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())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
7
main.go
7
main.go
|
@ -92,7 +92,11 @@ func main() {
|
||||||
"Salon textuel par défaut",
|
"Salon textuel par défaut",
|
||||||
).IsRequired()).
|
).IsRequired()).
|
||||||
SetHandler(commands.ConfigFallbackChannel),
|
SetHandler(commands.ConfigFallbackChannel),
|
||||||
)
|
).SetPermission(gokord.AdminPermission)
|
||||||
|
|
||||||
|
topCmd := gokord.NewCommand("top", "Copaings les plus actifs").
|
||||||
|
HasOption().
|
||||||
|
SetHandler(commands.Top)
|
||||||
|
|
||||||
bot := gokord.Bot{
|
bot := gokord.Bot{
|
||||||
Token: token,
|
Token: token,
|
||||||
|
@ -106,6 +110,7 @@ func main() {
|
||||||
Commands: []*gokord.GeneralCommand{
|
Commands: []*gokord.GeneralCommand{
|
||||||
rankCmd,
|
rankCmd,
|
||||||
configCmd,
|
configCmd,
|
||||||
|
topCmd,
|
||||||
},
|
},
|
||||||
AfterInit: afterInit,
|
AfterInit: afterInit,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue