Пример #1
0
func nickChangeUpdateCallback(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
	nicknames := nickCollection{ramendb.GetCollection(m.GuildID, nickCollName)}

	guild, _ := s.State.Guild(m.GuildID)
	if guild == nil {
		log.WithFields(log.Fields{
			"guild": m.GuildID,
		}).Warning("Failed to grab guild")
		return
	}

	member := m.Member
	user := member.User
	if member == nil {
		log.WithFields(log.Fields{
			"member": member,
		}).Warning("Failed to grab member")
		return
	}

	if member.User.Bot {
		return
	}

	data := nicknameConfig{}
	nicknames.Find(nicknameConfig{UserID: user.ID}).One(&data)
	trueNick := data.Nickname
	if trueNick == "" {
		log.Debug("No Nickname DB Info")
		return
	}
	if member.Nick != trueNick {
		err := s.GuildMemberNickname(guild.ID, user.ID, trueNick)
		if err != nil {
			log.Errorf("Failed to correct user's nickname: %v", err)
			return
		}
		return
	}
}