From af0acf0daece8c4857513f3fea84a332709e8c55 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sun, 22 Mar 2020 13:16:31 +0000 Subject: Strip extra info from emotes (discord) (#1052) --- bridge/discord/handlers.go | 3 +++ bridge/discord/helpers.go | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'bridge') diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go index 1ce402c5..2bae3664 100644 --- a/bridge/discord/handlers.go +++ b/bridge/discord/handlers.go @@ -119,6 +119,9 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat rmsg.Event = config.EventUserAction } + // Replace emotes + rmsg.Text = replaceEmotes(rmsg.Text) + b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account) b.Log.Debugf("<= Message is %#v", rmsg) b.Remote <- rmsg diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go index 8bc4f336..9ef234c5 100644 --- a/bridge/discord/helpers.go +++ b/bridge/discord/helpers.go @@ -137,6 +137,7 @@ var ( // See https://discordapp.com/developers/docs/reference#message-formatting. channelMentionRE = regexp.MustCompile("<#[0-9]+>") userMentionRE = regexp.MustCompile("@[^@\n]{1,32}") + emoteRE = regexp.MustCompile(``) ) func (b *Bdiscord) replaceChannelMentions(text string) string { @@ -182,6 +183,10 @@ func (b *Bdiscord) replaceUserMentions(text string) string { return userMentionRE.ReplaceAllStringFunc(text, replaceUserMentionFunc) } +func replaceEmotes(text string) string { + return emoteRE.ReplaceAllString(text, "$1") +} + func (b *Bdiscord) replaceAction(text string) (string, bool) { if strings.HasPrefix(text, "_") && strings.HasSuffix(text, "_") { return text[1 : len(text)-1], true -- cgit v1.2.3