Thumbnail

rani/matterbridge.git

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

commit b84bfb90b5e983f31dab2611da7a3f5bdb233a54 Author: Qais Patankar <qaisjp@gmail.com> Date: Sat Dec 05 15:56:43 2020 +0000 Extract maybeGetLocalAvatar into its own function (discord) diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 78c579a..70fdaf9 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -38217 +3829 @@ func (b *Bdiscord) webhookSend(msg *config.Message, channelID string) (*discordg   err error   )   - // If avatar is unset, check if UseLocalAvatar contains the message's - // account or protocol, and if so, try to find a local avatar + // If avatar is unset, mutate the message to include the local avatar (but only if settings say we should do this)   if msg.Avatar == "" { - for _, val := range b.GetStringSlice("UseLocalAvatar") { - if msg.Protocol == val || msg.Account == val { - if avatar := b.findAvatar(msg); avatar != "" { - msg.Avatar = avatar - } - break - } - } + msg.Avatar = b.maybeGetLocalAvatar(msg)   }     // WebhookParams can have either `Content` or `File`. @@ -44110 +43320 @@ func (b *Bdiscord) webhookSend(msg *config.Message, channelID string) (*discordg   return res, err  }   -func (b *Bdiscord) findAvatar(m *config.Message) string { - member, err := b.getGuildMemberByNick(m.Username) - if err != nil { - return "" +// maybeGetLocalAvatar checks if UseLocalAvatar contains the message's +// account or protocol, and if so, returns the Discord avatar (if exists) +func (b *Bdiscord) maybeGetLocalAvatar(msg *config.Message) string { + for _, val := range b.GetStringSlice("UseLocalAvatar") { + if msg.Protocol != val && msg.Account != val { + continue + } + + member, err := b.getGuildMemberByNick(msg.Username) + if err != nil { + return "" + } + + return member.User.AvatarURL("")   } - return member.User.AvatarURL("") + return ""  }