diff options
-rw-r--r-- | bridge/discord/discord.go | 20 |
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]+>") |