diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-22 20:10:21 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-22 20:10:21 +0100 |
| commit | 8255a2e51454049f3ac1532f6e1125f528691c37 (patch) | |
| tree | 064b7dbdd07efd85162c954d20c1dcd831ea84f6 /commands/top.go | |
| parent | eee2a3873e11bef6bee2f71cf429c8a870c5383c (diff) | |
refactor(commands): use new handlers
Diffstat (limited to 'commands/top.go')
| -rw-r--r-- | commands/top.go | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/commands/top.go b/commands/top.go index a6ed992..867cf26 100644 --- a/commands/top.go +++ b/commands/top.go @@ -8,53 +8,51 @@ import ( "git.anhgelus.world/anhgelus/les-copaings-bot/config" "git.anhgelus.world/anhgelus/les-copaings-bot/exp" "git.anhgelus.world/anhgelus/les-copaings-bot/user" - "github.com/anhgelus/gokord/cmd" "github.com/nyttikord/gokord/bot" "github.com/nyttikord/gokord/channel" - "github.com/nyttikord/gokord/event" + "github.com/nyttikord/gokord/interaction" ) -func Top(ctx context.Context) func(s bot.Session, i *event.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) { - return func(s bot.Session, i *event.InteractionCreate, _ cmd.OptionMap, resp *cmd.ResponseBuilder) { - embeds := make([]*channel.MessageEmbed, 3) - var wg sync.WaitGroup +func Top(ctx context.Context, dg bot.Session, i *interaction.ApplicationCommand) { + embeds := make([]*channel.MessageEmbed, 3) + var wg sync.WaitGroup - fn := func(str string, n uint, d int, id int) { - tops := user.GetBestXP(ctx, i.GuildID, n, d) - embeds[id] = &channel.MessageEmbed{ - Title: str, - Description: genTopsMessage(tops), - Color: 0x10E6AD, - } - } - - cfg := config.GetGuildConfig(i.GuildID) - if cfg.DaysXPRemains > 30 { - wg.Go(func() { - fn(fmt.Sprintf("Top %d jours", cfg.DaysXPRemains), 10, -1, 0) - }) + fn := func(str string, n uint, d int, id int) { + tops := user.GetBestXP(ctx, i.GuildID, n, d) + embeds[id] = &channel.MessageEmbed{ + Title: str, + Description: genTopsMessage(tops), + Color: 0x10E6AD, } + } + cfg := config.GetGuildConfig(i.GuildID) + if cfg.DaysXPRemains > 30 { wg.Go(func() { - fn("Top 30 jours", 5, 30, 1) - }) - wg.Go(func() { - fn("Top 7 jours", 5, 7, 2) + fn(fmt.Sprintf("Top %d jours", cfg.DaysXPRemains), 10, -1, 0) }) + } - wg.Wait() - if cfg.DaysXPRemains > 30 { - resp.AddEmbed(embeds[0]). - AddEmbed(embeds[1]). - AddEmbed(embeds[2]) - } else { - resp.AddEmbed(embeds[1]). - AddEmbed(embeds[2]) - } - err := resp.Send() - if err != nil { - s.Logger().Error("sending response top", "error", err) - } + wg.Go(func() { + fn("Top 30 jours", 5, 30, 1) + }) + wg.Go(func() { + fn("Top 7 jours", 5, 7, 2) + }) + + wg.Wait() + resp := interaction.NewMessageResponse() + if cfg.DaysXPRemains > 30 { + resp.AddEmbed(embeds[0]). + AddEmbed(embeds[1]). + AddEmbed(embeds[2]) + } else { + resp.AddEmbed(embeds[1]). + AddEmbed(embeds[2]) + } + err := dg.InteractionAPI().Respond(i.Interaction, resp.Response()).Do(ctx) + if err != nil { + bot.Logger(ctx).Error("sending response top", "error", err) } } |
