Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 3a582d16291244761c13e3f74bf731931f0737be Author: Qais Patankar <qaisjp@gmail.com> Date: Sun Mar 22 13:16:31 2020 +0000 Strip extra info from emotes (discord) (#1052) diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go index 1ce402c..2bae366 100644 --- a/bridge/discord/handlers.go +++ b/bridge/discord/handlers.go @@ -1196 +1199 @@ 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 8bc4f33..9ef234c 100644 --- a/bridge/discord/helpers.go +++ b/bridge/discord/helpers.go @@ -1376 +1377 @@ var (   // See https://discordapp.com/developers/docs/reference#message-formatting.   channelMentionRE = regexp.MustCompile("<#[0-9]+>")   userMentionRE = regexp.MustCompile("@[^@\n]{1,32}") + emoteRE = regexp.MustCompile(`<a?(:\w+:)\d+>`)  )    func (b *Bdiscord) replaceChannelMentions(text string) string { @@ -1826 +18310 @@ 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