@@ -40,12 +40,13 @@ var (
40
40
rxSlackUser = regexp .MustCompile ("<@[UW][A-Z0-9]+>" )
41
41
)
42
42
43
- // ExpandURLs expands and unquotes URLs from Slack's messages. Slack quotes the
44
- // URLs and groups them between < and >. It also translates potential URLs into
45
- // actual URLs (e.g. when you type "example.com"), so you will get something
46
- // like <http://example.com|example.com>. This function tries to detect them and
47
- // unquote and expand them for a better visualization on IRC.
48
- func ExpandURLs (text string ) string {
43
+ // ExpandText expands and unquotes text and URLs from Slack's messages. Slack
44
+ // quotes the text and URLS, and the latter are enclosed in < and >. It also
45
+ // translates potential URLs into actual URLs (e.g. when you type "example.com"),
46
+ // so you will get something like <http://example.com|example.com>. This
47
+ // function tries to detect them and unquote and expand them for a better
48
+ // visualization on IRC.
49
+ func ExpandText (text string ) string {
49
50
text = rxSlackUrls .ReplaceAllStringFunc (text , func (subs string ) string {
50
51
if ! strings .HasPrefix (subs , "<" ) && ! strings .HasSuffix (subs , ">" ) {
51
52
return subs
@@ -68,12 +69,13 @@ func ExpandURLs(text string) string {
68
69
return subs
69
70
}
70
71
// Slack escapes the URLs passed by the users, let's undo that
71
- u .RawQuery = html .UnescapeString (u .RawQuery )
72
+ // u.RawQuery = html.UnescapeString(u.RawQuery)
72
73
if slackMsg == "" {
73
74
return u .String ()
74
75
}
75
76
return fmt .Sprintf ("%s (%s)" , slackMsg , u .String ())
76
77
})
78
+ text = html .UnescapeString (text )
77
79
return text
78
80
}
79
81
@@ -196,7 +198,7 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error {
196
198
return fmt .Sprintf ("@%s" , user .Name )
197
199
})
198
200
// replace some HTML entities
199
- text = ExpandURLs (text )
201
+ text = ExpandText (text )
200
202
201
203
// FIXME if two instances are connected to the Slack API at the
202
204
// same time, this will hide the other instance's message
0 commit comments