feat(command): top
This commit is contained in:
parent
7d4e050c3f
commit
75df974f6f
2 changed files with 47 additions and 1 deletions
41
commands/top.go
Normal file
41
commands/top.go
Normal file
|
@ -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())
|
||||
}
|
||||
}()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue