package config import ( "context" "fmt" "strconv" "strings" "velox-bot/internal/commands/level/shared" "velox-bot/internal/db/services" "github.com/bwmarrin/discordgo" ) // Looking at the leveling settings and removing a role reward, so nothing // about leveling needs a dashboard. func slvlRemoveRewardOption() *discordgo.ApplicationCommandOption { return &discordgo.ApplicationCommandOption{ Type: discordgo.ApplicationCommandOptionSubCommand, Name: "remove-reward", Description: "Remove the role reward of a level", Options: []*discordgo.ApplicationCommandOption{ {Type: discordgo.ApplicationCommandOptionInteger, Name: "level", Description: "The level", Required: true}, }, } } func slvlStatusOption() *discordgo.ApplicationCommandOption { return &discordgo.ApplicationCommandOption{ Type: discordgo.ApplicationCommandOptionSubCommand, Name: "status", Description: "Show the leveling settings", } } func slvlRemoveRewardHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { if !shared.RequireManageGuild(s, i) || !shared.RequireLevelSystemEnabled(s, i) || !shared.RequireLevelSettingsService(s, i) { return } guildID, ok := shared.ParseGuildID(s, i) if !ok { return } level := int(shared.SubcommandOptionMap(i)["level"].IntValue()) removed, err := services.Global.LevelSettings.DeleteRoleRewardForLevel(context.Background(), guildID, level) switch { case err != nil: shared.RespondEphemeral(s, i, "Failed to remove the reward.") case !removed: shared.RespondEphemeral(s, i, "Level "+strconv.Itoa(level)+" has no role reward.") default: shared.RespondEphemeral(s, i, "Removed the reward for level "+strconv.Itoa(level)+".") } } func slvlStatusHandler(s *discordgo.Session, i *discordgo.InteractionCreate) { if !shared.RequireManageGuild(s, i) || !shared.RequireLevelSettingsService(s, i) { return } guildID, ok := shared.ParseGuildID(s, i) if !ok { return } ctx := context.Background() ls := services.Global.LevelSettings enabled, err := ls.IsLevelSystemEnabled(ctx, guildID) if err != nil { shared.RespondEphemeral(s, i, "Failed to load the settings.") return } state := "off" if enabled { state = "on" } var b strings.Builder fmt.Fprintf(&b, "**Leveling:** %s\n", state) if ch, ok, _ := ls.GetLevelUpChannelID(ctx, guildID); ok && ch != 0 { fmt.Fprintf(&b, "**Level-up channel:** <#%d>\n", ch) } else { b.WriteString("**Level-up channel:** the channel of the message\n") } if msg, err := ls.GetLevelUpMessage(ctx, guildID); err == nil { fmt.Fprintf(&b, "**Level-up message:** %s\n", msg) } rewards, _ := ls.ListRoleRewards(ctx, guildID, 25) if len(rewards) == 0 { b.WriteString("**Role rewards:** none") } else { b.WriteString("**Role rewards:** ") for n, r := range rewards { if n > 0 { b.WriteString(", ") } fmt.Fprintf(&b, "level %d → <@&%d>", r.Level, r.RoleID) } } out := b.String() if r := []rune(out); len(r) > 1900 { out = string(r[:1899]) + "…" } shared.RespondEphemeral(s, i, out) }