mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 07:00:27 +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:
parent
49110a5872
commit
c91bfd08d8
@ -138,6 +138,7 @@ type Protocol struct {
|
|||||||
Topic string // zulip
|
Topic string // zulip
|
||||||
URL string // mattermost, slack // DEPRECATED
|
URL string // mattermost, slack // DEPRECATED
|
||||||
UseAPI bool // mattermost, slack
|
UseAPI bool // mattermost, slack
|
||||||
|
UseLocalAvatar []string // discord
|
||||||
UseSASL bool // IRC
|
UseSASL bool // IRC
|
||||||
UseTLS bool // IRC
|
UseTLS bool // IRC
|
||||||
UseDiscriminator bool // discord
|
UseDiscriminator bool // discord
|
||||||
|
@ -381,6 +381,19 @@ func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*d
|
|||||||
err error
|
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`.
|
// WebhookParams can have either `Content` or `File`.
|
||||||
|
|
||||||
// We can't send empty messages.
|
// We can't send empty messages.
|
||||||
@ -430,3 +443,11 @@ func (b *Bdiscord) webhookSend(msg *config.Message, webhookID, token string) (*d
|
|||||||
}
|
}
|
||||||
return res, err
|
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("")
|
||||||
|
}
|
||||||
|
@ -306,8 +306,6 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) string {
|
func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) string {
|
||||||
br := gw.Bridges[msg.Account]
|
|
||||||
msg.Protocol = br.Protocol
|
|
||||||
if dest.GetBool("StripNick") {
|
if dest.GetBool("StripNick") {
|
||||||
re := regexp.MustCompile("[^a-zA-Z0-9]+")
|
re := regexp.MustCompile("[^a-zA-Z0-9]+")
|
||||||
msg.Username = re.ReplaceAllString(msg.Username, "")
|
msg.Username = re.ReplaceAllString(msg.Username, "")
|
||||||
@ -315,6 +313,7 @@ func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) stri
|
|||||||
nick := dest.GetString("RemoteNickFormat")
|
nick := dest.GetString("RemoteNickFormat")
|
||||||
|
|
||||||
// loop to replace nicks
|
// loop to replace nicks
|
||||||
|
br := gw.Bridges[msg.Account]
|
||||||
for _, outer := range br.GetStringSlice2D("ReplaceNicks") {
|
for _, outer := range br.GetStringSlice2D("ReplaceNicks") {
|
||||||
search := outer[0]
|
search := outer[0]
|
||||||
replace := outer[1]
|
replace := outer[1]
|
||||||
|
@ -132,6 +132,9 @@ func (r *Router) handleReceive() {
|
|||||||
r.handleEventFailure(&msg)
|
r.handleEventFailure(&msg)
|
||||||
r.handleEventRejoinChannels(&msg)
|
r.handleEventRejoinChannels(&msg)
|
||||||
|
|
||||||
|
// Set message protocol based on the account it came from
|
||||||
|
msg.Protocol = r.getBridge(msg.Account).Protocol
|
||||||
|
|
||||||
filesHandled := false
|
filesHandled := false
|
||||||
for _, gw := range r.Gateways {
|
for _, gw := range r.Gateways {
|
||||||
// record all the message ID's of the different bridges
|
// record all the message ID's of the different bridges
|
||||||
|
@ -724,6 +724,12 @@ Server="yourservername"
|
|||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
ShowEmbeds=false
|
ShowEmbeds=false
|
||||||
|
|
||||||
|
#Show Discord avatars of remote users with matching names
|
||||||
|
#This only works for webhooks & if the source message has no avatar
|
||||||
|
#
|
||||||
|
#OPTIONAL (default empty)
|
||||||
|
UseLocalAvatar=["irc"]
|
||||||
|
|
||||||
#Shows the username instead of the server nickname
|
#Shows the username instead of the server nickname
|
||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
UseUserName=false
|
UseUserName=false
|
||||||
|
Loading…
Reference in New Issue
Block a user