summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQais Patankar <qaisjp@gmail.com>2020-12-05 15:56:43 +0000
committerWim <wim@42.be>2020-12-13 23:19:48 +0100
commit0494119bf4e1fb53967aca9be3203d7cf2bbb9a5 (patch)
tree51016f2aa58ec06ef2c0390d5714c63942ef489d
parent0a17e2111921ad45251b72864cc713a120658849 (diff)
downloadmatterbridge-msglm-0494119bf4e1fb53967aca9be3203d7cf2bbb9a5.tar.gz
matterbridge-msglm-0494119bf4e1fb53967aca9be3203d7cf2bbb9a5.tar.bz2
matterbridge-msglm-0494119bf4e1fb53967aca9be3203d7cf2bbb9a5.zip
Extract maybeGetLocalAvatar into its own function (discord)
-rw-r--r--bridge/discord/discord.go32
1 files changed, 17 insertions, 15 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 78c579ae..70fdaf90 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -382,17 +382,9 @@ 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`.
@@ -441,10 +433,20 @@ 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 ""
}