discord: resolve guild nicks

This commit is contained in:
Chris Sexton 2021-08-20 13:47:33 -04:00 committed by Chris Sexton
parent 8b84d6b840
commit edc56dedc7
1 changed files with 23 additions and 5 deletions

View File

@ -128,10 +128,12 @@ func (d *Discord) GetEmojiList() map[string]string {
if d.emojiCache != nil { if d.emojiCache != nil {
return d.emojiCache return d.emojiCache
} }
guidID := d.config.Get("discord.guildid", "") guildID := d.config.Get("discord.guildid", "")
if guidID == "" { if guildID == "" {
log.Error().Msg("no guild ID set")
return map[string]string{}
} }
e, err := d.client.GuildEmojis(guidID) e, err := d.client.GuildEmojis(guildID)
if err != nil { if err != nil {
log.Error().Err(err).Msg("could not retrieve emojis") log.Error().Err(err).Msg("could not retrieve emojis")
return map[string]string{} return map[string]string{}
@ -170,9 +172,23 @@ func (d *Discord) convertUser(u *discordgo.User) *user.User {
if err != nil { if err != nil {
log.Error().Err(err).Msg("error getting avatar") log.Error().Err(err).Msg("error getting avatar")
} }
nick := u.Username
guildID := d.config.Get("discord.guildid", "")
if guildID == "" {
log.Error().Msg("no guild ID set")
} else {
mem, err := d.client.GuildMember(guildID, u.ID)
if err != nil {
log.Error().Err(err).Msg("could not get guild member")
} else if mem.Nick != "" {
nick = mem.Nick
}
}
return &user.User{ return &user.User{
ID: u.ID, ID: u.ID,
Name: u.Username, Name: nick,
Admin: false, Admin: false,
Icon: d.client.State.User.AvatarURL("64"), Icon: d.client.State.User.AvatarURL("64"),
IconImg: img, IconImg: img,
@ -212,9 +228,11 @@ func (d *Discord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate
tStamp, _ := m.Timestamp.Parse() tStamp, _ := m.Timestamp.Parse()
author := d.convertUser(m.Author)
msg := msg.Message{ msg := msg.Message{
ID: m.ID, ID: m.ID,
User: d.convertUser(m.Author), User: author,
Channel: m.ChannelID, Channel: m.ChannelID,
ChannelName: ch.Name, ChannelName: ch.Name,
Body: text, Body: text,