From efaa24393a3e7c999f6706d88a9cba74bfa62980 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 23 Jan 2026 19:09:20 +0100 Subject: refactor(commands): deploy when flag is given --- commands/deploy.go | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ commands/reset.go | 2 +- commands/stats.go | 4 +-- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 commands/deploy.go (limited to 'commands') diff --git a/commands/deploy.go b/commands/deploy.go new file mode 100644 index 0000000..4974d50 --- /dev/null +++ b/commands/deploy.go @@ -0,0 +1,77 @@ +package commands + +import ( + "context" + + "git.anhgelus.world/anhgelus/les-copaings-bot/common" + "github.com/nyttikord/gokord/bot" + "github.com/nyttikord/gokord/discord" + "github.com/nyttikord/gokord/discord/types" + "github.com/nyttikord/gokord/interaction" +) + +var commands []*interaction.Command + +func newCmd(name, description string) *interaction.Command { + return &interaction.Command{ + Type: types.CommandChat, + Name: name, + Description: description, + Contexts: &[]types.InteractionContext{types.InteractionContextGuild}, + IntegrationTypes: &[]types.IntegrationInstall{types.IntegrationInstallGuild}, + } +} + +func newOption(tp types.CommandOption, name, description string) *interaction.CommandOption { + return &interaction.CommandOption{ + Type: tp, + Name: name, + Description: description, + } +} + +func init() { + adm := int64(discord.PermissionManageGuild) + + rank := newCmd("rank", "Affiche le niveau d'un copaing") + rank.Options = append(rank.Options, newOption(types.CommandOptionUser, "copaing", "Le niveau du Copaing que vous souhaitez obtenir")) + + cfg := newCmd("config", "Modifie la config") + cfg.DefaultMemberPermissions = &adm + + top := newCmd("top", "Copaings les plus actifs") + + reset := newCmd("reset", "Reset l'xp") + reset.DefaultMemberPermissions = &adm + + resetUser := newCmd("reset-user", "Reset l'xp d'un utilisation") + resetUser.DefaultMemberPermissions = &adm + resetUser.Options = append(resetUser.Options, newOption(types.CommandOptionUser, "copaing", "Copaing à reset")) + + credits := newCmd("credits", "Affiche les crédits du bot") + + stats := newCmd("stats", "Affiche des stats :D") + stats.Options = append(stats.Options, + newOption(types.CommandOptionInteger, "jours", "Nombre de jours à afficher dans le graphique"), + newOption(types.CommandOptionUser, "copaing", "Copaing à inspecter"), + ) + + rolereact := newCmd("rolereact", "Envoie un message permettant de récupérer des rôles grâce à des réactions") + rolereact.DefaultMemberPermissions = &adm + rolereact.Options = append(rolereact.Options, newOption(types.CommandOptionChannel, "salon", "Salon de destination du message")) + + modify := newCmd("Modifier", "") + modify.DefaultMemberPermissions = &adm + modify.Type = types.CommandMessage + + commands = []*interaction.Command{rank, cfg, top, reset, resetUser, credits, stats, rolereact, modify} +} + +func Deploy(ctx context.Context, dg bot.Session) error { + guildID := "" + if common.IsDebug(ctx) { + guildID = dg.GuildAPI().State.Guilds()[0] + } + _, err := dg.InteractionAPI().CommandBulkOverwrite(dg.SessionState().Application().ID, guildID, commands).Do(ctx) + return err +} diff --git a/commands/reset.go b/commands/reset.go index d1e04ea..85f8f0d 100644 --- a/commands/reset.go +++ b/commands/reset.go @@ -29,7 +29,7 @@ func ResetUser(ctx context.Context, dg bot.Session, i *interaction.ApplicationCo } }() opts := i.OptionMap() - v, ok := opts["user"] + v, ok := opts["copaing"] if !ok { resp.Message("Le copaing n'a pas été renseigné.") return diff --git a/commands/stats.go b/commands/stats.go index e74f3e1..017cfc6 100644 --- a/commands/stats.go +++ b/commands/stats.go @@ -62,7 +62,7 @@ func Stats(ctx context.Context, dg bot.Session, i *interaction.ApplicationComman }() opts := i.OptionMap() - if v, ok := opts["days"]; ok { + if v, ok := opts["jours"]; ok { in := v.IntValue() if in < 1 || uint(in) > cfg.DaysXPRemains { msg := fmt.Sprintf("Nombre de jours invalide. Il doit être strictement positif et inférieur à %d", cfg.DaysXPRemains) @@ -76,7 +76,7 @@ func Stats(ctx context.Context, dg bot.Session, i *interaction.ApplicationComman bot.Logger(ctx).Error("sending deferred", "error", err) } var w io.WriterTo - if v, ok := opts["user"]; ok { + if v, ok := opts["copaing"]; ok { w, err = statsMember(ctx, dg, i, days, v.UserValue(ctx).ID) } else { w, err = statsAll(ctx, dg, i, days) -- cgit v1.2.3