5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-10 03:10:26 +00:00

Strip custom emoji metadata (discord). Closes #148

This commit is contained in:
Wim 2017-04-15 16:23:34 +02:00
parent 6ea8be5749
commit 035c2b906a

View File

@ -4,6 +4,7 @@ import (
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"regexp"
"strings" "strings"
"sync" "sync"
) )
@ -125,6 +126,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
if len(m.MentionRoles) > 0 { if len(m.MentionRoles) > 0 {
m.Message.Content = b.replaceRoleMentions(m.Message.Content) m.Message.Content = b.replaceRoleMentions(m.Message.Content)
} }
m.Message.Content = b.stripCustomoji(m.Message.Content)
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName, 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"} Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
} }
@ -195,3 +197,9 @@ func (b *bdiscord) replaceRoleMentions(text string) string {
} }
return text return text
} }
func (b *bdiscord) stripCustomoji(text string) string {
// <:doge:302803592035958784>
re := regexp.MustCompile("<(:.*?:)[0-9]+>")
return re.ReplaceAllString(text, `$1`)
}