diff options
author | Wim <wim@42.be> | 2017-06-26 22:16:19 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-26 22:16:19 +0200 |
commit | c268e90f492527a6d5bf9cefc9a67c67b3d8c41c (patch) | |
tree | 6749f5d812cd56be8ee33669dba891e6b78e7724 /bridge/slack/slack.go | |
parent | c17512b7ab759ab0fba0ecc8be20ff829946bb24 (diff) | |
download | matterbridge-msglm-c268e90f492527a6d5bf9cefc9a67c67b3d8c41c.tar.gz matterbridge-msglm-c268e90f492527a6d5bf9cefc9a67c67b3d8c41c.tar.bz2 matterbridge-msglm-c268e90f492527a6d5bf9cefc9a67c67b3d8c41c.zip |
Remove label from URLs (slack). Closes #205
If slack detects a text contains an url it changes it to <http://url|url>.
Strip the |url so that http://url remains.
Diffstat (limited to 'bridge/slack/slack.go')
-rw-r--r-- | bridge/slack/slack.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index fd4b9e1a..ad6a2b60 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -185,6 +185,7 @@ func (b *Bslack) handleSlack() { } texts := strings.Split(message.Text, "\n") for _, text := range texts { + text = b.replaceURL(text) flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID} } @@ -279,3 +280,11 @@ func (b *Bslack) replaceMention(text string) string { } return text } + +func (b *Bslack) replaceURL(text string) string { + results := regexp.MustCompile(`<(.*?)\|.*?>`).FindAllStringSubmatch(text, -1) + for _, r := range results { + text = strings.Replace(text, r[0], r[1], -1) + } + return text +} |