mirror of https://github.com/velour/catbase.git
Add regexp to clean ugly Slack URLs
This commit is contained in:
parent
b048890b05
commit
f665b166ad
|
@ -11,6 +11,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -158,11 +159,16 @@ func (s *Slack) Serve() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var urlDetector = regexp.MustCompile(`<(.+)://([^|^>]+).*>`)
|
||||||
|
|
||||||
// Convert a slackMessage to a msg.Message
|
// Convert a slackMessage to a msg.Message
|
||||||
func (s *Slack) buildMessage(m slackMessage) msg.Message {
|
func (s *Slack) buildMessage(m slackMessage) msg.Message {
|
||||||
log.Printf("DEBUG: msg: %#v", m)
|
log.Printf("DEBUG: msg: %#v", m)
|
||||||
text := html.UnescapeString(m.Text)
|
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)
|
isCmd, text := bot.IsCmd(s.config, text)
|
||||||
|
|
||||||
isAction := strings.HasPrefix(text, "/me ")
|
isAction := strings.HasPrefix(text, "/me ")
|
||||||
|
|
Loading…
Reference in New Issue