remote_avatar: add UseLocalAvatar

This commit is contained in:
Qais Patankar
2020-02-08 19:21:54 +00:00
parent c01c8edeb8
commit ee63663e49
2 changed files with 22 additions and 0 deletions

View File

@@ -138,6 +138,7 @@ type Protocol struct {
Topic string // zulip
URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
UseLocalAvatar []string // discord
UseSASL bool // IRC
UseTLS bool // IRC
UseDiscriminator bool // discord

View File

@@ -381,6 +381,19 @@ func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*d
err error
)
// If avatar is unset, maybe we need to set the local avatar
if msg.Avatar == "" {
for _, val := range b.GetStringSlice("UseLocalAvatar") {
if msg.Protocol != val {
continue
}
if avatar, ok := b.findAvatar(msg); ok {
msg.Avatar = avatar
}
break
}
}
// WebhookParams can have either `Content` or `File`.
// We can't send empty messages.
@@ -430,3 +443,11 @@ func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*d
}
return res, err
}
func (b *Bdiscord) findAvatar(m *config.Message) (string, bool) {
member, err := b.getGuildMemberByNick(m.Username)
if err != nil {
return "", false
}
return member.User.AvatarURL(""), true
}