package commands import ( "github.com/bwmarrin/discordgo" "gitea.teamortix.com/chanbakjsd/Milen/db" "gitea.teamortix.com/chanbakjsd/Milen/level" "gitea.teamortix.com/chanbakjsd/Milen/util" ) var leaderboardEmoji = []string{"🏆", "🥈", "🥉", "⬛", "◼️"} func handleLeaderboard(dg *discordgo.Session, m *discordgo.MessageCreate, arguments []string) { topFive := db.GetTopFive() fields := make([]*discordgo.MessageEmbedField, 0, len(topFive)) for k, v := range topFive { member, err := util.GetMember(dg, m.GuildID, v.UserID) var displayName string if err == nil { if member.Nick != "" { displayName = member.Nick + " (" + member.User.Username + "#" + member.User.Discriminator + ")" } else { displayName = member.User.Username + "#" + member.User.Discriminator } } else { displayName = "??? (" + v.UserID + ")" } rank, level := level.GetLevelFromXP(v.XP) fields = append(fields, &discordgo.MessageEmbedField{ Name: leaderboardEmoji[k] + " " + displayName, Value: rank.String() + " " + util.FormatRomanNumeral(level) + " (" + util.FormatPlural(v.XP, "second", "seconds") + ")", }) } util.SendEmbed(dg, m.ChannelID, &discordgo.MessageEmbed{ Title: "Leaderboard", Fields: fields, }) }