diff options
author | Patrick Connolly <patrick.c.connolly@gmail.com> | 2017-11-02 16:21:46 -0400 |
---|---|---|
committer | Wim <wim@42.be> | 2017-11-02 21:21:46 +0100 |
commit | 4f8ae761a27302c7575ac0ef7ca1c45fe329e9a7 (patch) | |
tree | 59b384c3a45f3ba03f80cf429b79c464de11896f /bridge | |
parent | b530e92834885748597f244f5df047dc30d5b9e3 (diff) | |
download | matterbridge-msglm-4f8ae761a27302c7575ac0ef7ca1c45fe329e9a7.tar.gz matterbridge-msglm-4f8ae761a27302c7575ac0ef7ca1c45fe329e9a7.tar.bz2 matterbridge-msglm-4f8ae761a27302c7575ac0ef7ca1c45fe329e9a7.zip |
Resolve slack channel to human-readable name. (slack) (#282)
Diffstat (limited to 'bridge')
-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 b0b11562..c09d6f90 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -340,6 +340,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) { } m.Raw = ev m.Text = b.replaceMention(m.Text) + m.Text = b.replaceChannel(m.Text) // when using webhookURL we can't check if it's our webhook or not for now if ev.BotID != "" && b.Config.WebhookURL == "" { bot, err := b.rtm.GetBotInfo(ev.BotID) @@ -386,6 +387,7 @@ func (b *Bslack) handleMatterHook(mchan chan *MMMessage) { m.Username = message.UserName m.Text = message.Text m.Text = b.replaceMention(m.Text) + m.Text = b.replaceChannel(m.Text) m.Channel = message.ChannelName if m.Username == "slackbot" { continue @@ -410,7 +412,14 @@ func (b *Bslack) replaceMention(text string) string { results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(text, -1) for _, r := range results { text = strings.Replace(text, "<@"+r[1]+">", "@"+b.userName(r[1]), -1) + } + return text +} +func (b *Bslack) replaceChannel(text string) string { + results := regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`).FindAllStringSubmatch(text, -1) + for _, r := range results { + text = strings.Replace(text, r[0], "#"+r[1], -1) } return text } |