aboutsummaryrefslogtreecommitdiff
path: root/commands/top.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 18:30:58 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 18:30:58 +0200
commit75df974f6fa47291eedadbea8bffbce7b90acfac (patch)
tree4f6f1c15b324baf7f639e287fd451f901fabab95 /commands/top.go
parent7d4e050c3f709dc192c1aef66b26221436a0e7f5 (diff)
feat(command): top
Diffstat (limited to 'commands/top.go')
-rw-r--r--commands/top.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/commands/top.go b/commands/top.go
new file mode 100644
index 0000000..bc444a3
--- /dev/null
+++ b/commands/top.go
@@ -0,0 +1,41 @@
+package commands
+
+import (
+ "fmt"
+ "github.com/anhgelus/gokord"
+ "github.com/anhgelus/gokord/utils"
+ "github.com/anhgelus/les-copaings-bot/xp"
+ "github.com/bwmarrin/discordgo"
+)
+
+func Top(s *discordgo.Session, i *discordgo.InteractionCreate) {
+ resp := utils.ResponseBuilder{C: s, I: i}
+ err := resp.IsDeferred().Send()
+ if err != nil {
+ utils.SendAlert("commands/top.go - Sending deferred", err.Error())
+ return
+ }
+ resp.NotDeferred().IsEdit()
+ go func() {
+ var tops []xp.Copaing
+ gokord.DB.Where("guild_id = ?", i.GuildID).Limit(10).Order("xp desc").Find(&tops)
+ msg := ""
+ for i, c := range tops {
+ if i == 9 {
+ msg += fmt.Sprintf("%d. **<@%s>** - niveau %d", i+1, c.DiscordID, xp.Level(c.XP))
+ } else {
+ msg += fmt.Sprintf("%d. **<@%s>** - niveau %d\n", i+1, c.DiscordID, xp.Level(c.XP))
+ }
+ }
+ err = resp.Embeds([]*discordgo.MessageEmbed{
+ {
+ Title: "Top",
+ Description: msg,
+ Color: utils.Success,
+ },
+ }).Send()
+ if err != nil {
+ utils.SendAlert("commands/top.go - Sending response top", err.Error())
+ }
+ }()
+}