mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 14:19:24 +00:00
Add ability to procure avatars from the destination bridge (#1000)
* remote_avatar: add UseLocalAvatar * remote_avatar: make sure msg.Protocol is always set correctly * remote_avatars: support msg.Account * remote_avatar: add to matterbridge.toml.sample * remote_avatar: clarify something
This commit is contained in:
@ -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
|
||||
|
@ -381,6 +381,19 @@ func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*d
|
||||
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 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
member, err := b.getGuildMemberByNick(m.Username)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return member.User.AvatarURL("")
|
||||
}
|
||||
|
Reference in New Issue
Block a user