summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-05-23 22:26:37 +0200
committerWim <wim@42.be>2017-05-23 22:26:37 +0200
commit381269311172c9586589b6438f960b173578ca25 (patch)
treef8a395362ff3e5a2077c18e67f651d4621679dcc
parentdd3c572256db1f6bce8cc604babace6865a331c4 (diff)
downloadmatterbridge-msglm-381269311172c9586589b6438f960b173578ca25.tar.gz
matterbridge-msglm-381269311172c9586589b6438f960b173578ca25.tar.bz2
matterbridge-msglm-381269311172c9586589b6438f960b173578ca25.zip
Replace long ids in channel metions (discord). Fixes #174
-rw-r--r--bridge/discord/discord.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index f6f3077f..f379ede6 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -140,6 +140,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
m.Message.Content = b.replaceRoleMentions(m.Message.Content)
}
m.Message.Content = b.stripCustomoji(m.Message.Content)
+ m.Message.Content = b.replaceChannelMentions(m.Message.Content)
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
}
@@ -213,6 +214,25 @@ func (b *bdiscord) replaceRoleMentions(text string) string {
return text
}
+func (b *bdiscord) replaceChannelMentions(text string) string {
+ var err error
+ re := regexp.MustCompile("<#[0-9]+>")
+ text = re.ReplaceAllStringFunc(text, func(m string) string {
+ channel := b.getChannelName(m[2 : len(m)-1])
+ // if at first don't succeed, try again
+ if channel == "" {
+ b.Channels, err = b.c.GuildChannels(b.guildID)
+ if err != nil {
+ return "#unknownchannel"
+ }
+ channel = b.getChannelName(m[2 : len(m)-1])
+ return channel
+ }
+ return channel
+ })
+ return text
+}
+
func (b *bdiscord) stripCustomoji(text string) string {
// <:doge:302803592035958784>
re := regexp.MustCompile("<(:.*?:)[0-9]+>")