diff options
author | NikkyAI <NikkyAI@users.noreply.github.com> | 2018-09-17 21:25:06 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2018-09-17 21:25:06 +0200 |
commit | 296428d53e4febb5a82082d3c61628fbd396fd13 (patch) | |
tree | d3338185ab9023d734178debb59ae33dcacc7db0 /bridge | |
parent | e0ca876de2dd8a8f0226848ef4ef10ef27400291 (diff) | |
download | matterbridge-msglm-296428d53e4febb5a82082d3c61628fbd396fd13.tar.gz matterbridge-msglm-296428d53e4febb5a82082d3c61628fbd396fd13.tar.bz2 matterbridge-msglm-296428d53e4febb5a82082d3c61628fbd396fd13.zip |
Fix Discord mentions by populating the nickMemberMap at connect (#498)
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/discord/discord.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 25a6a7a6..0265f843 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -89,6 +89,21 @@ func (b *Bdiscord) Connect() error { for _, channel := range b.Channels { b.Log.Debugf("found channel %#v", channel) } + // obtaining guild members and initializing nickname mapping + b.Lock() + members, err := b.c.GuildMembers(b.guildID, "", 1000) + if err != nil { + b.Log.Error("Error obtaining guild members", err) + return err + } + for _, member := range members { + b.userMemberMap[member.User.ID] = member + b.nickMemberMap[member.User.Username] = member + if member.Nick != "" { + b.nickMemberMap[member.Nick] = member + } + } + b.Unlock() return nil } @@ -298,7 +313,10 @@ func (b *Bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUp b.Log.Debugf("%s: memberupdate: user %s (nick %s) changes nick to %s", b.Account, m.Member.User.Username, b.userMemberMap[m.Member.User.ID].Nick, m.Member.Nick) } b.userMemberMap[m.Member.User.ID] = m.Member - b.nickMemberMap[m.Member.Nick] = m.Member + b.nickMemberMap[m.Member.User.Username] = m.Member + if m.Member.Nick != "" { + b.nickMemberMap[m.Member.Nick] = m.Member + } b.Unlock() } |