Merge pull request #28 from velour/fixUrls

Fix urls
This commit is contained in:
Chris Sexton 2016-05-17 22:20:33 -04:00
commit d236d21500
3 changed files with 11 additions and 5 deletions

View File

@ -609,7 +609,7 @@ func (p *Factoid) randomFact() *factoid {
// factTimer spits out a fact at a given interval and with given probability
func (p *Factoid) factTimer(channel string) {
duration := time.Duration(p.Bot.Config().Factoid.QuoteTime) * time.Second
duration := time.Duration(p.Bot.Config().Factoid.QuoteTime) * time.Minute
myLastMsg := time.Now()
for {
time.Sleep(time.Duration(5) * time.Second) // why 5?

View File

@ -12,16 +12,16 @@ var factoidIndex string = `
<html>
<head>
<title>Factoids</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.1.0/pure-min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/base-min.css">
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
</head>
<div>

View File

@ -11,6 +11,7 @@ import (
"log"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"sync/atomic"
@ -158,11 +159,16 @@ func (s *Slack) Serve() {
}
}
var urlDetector = regexp.MustCompile(`<(.+)://([^|^>]+).*>`)
// Convert a slackMessage to a msg.Message
func (s *Slack) buildMessage(m slackMessage) msg.Message {
log.Printf("DEBUG: msg: %#v", m)
text := html.UnescapeString(m.Text)
// remove <> from URLs, URLs may also be <url|description>
text = urlDetector.ReplaceAllString(text, "${1}://${2}")
isCmd, text := bot.IsCmd(s.config, text)
isAction := strings.HasPrefix(text, "/me ")