(interaction, config, client)
| 67 | category: 'Leveling', |
| 68 | |
| 69 | async execute(interaction, config, client) { |
| 70 | try { |
| 71 | const deferred = await InteractionHelper.safeDefer(interaction, { |
| 72 | flags: MessageFlags.Ephemeral, |
| 73 | }); |
| 74 | if (!deferred) return; |
| 75 | |
| 76 | if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)) { |
| 77 | return await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need the **Manage Server** permission to use this command.' }); |
| 78 | } |
| 79 | |
| 80 | const subcommand = interaction.options.getSubcommand(); |
| 81 | |
| 82 | if (subcommand === 'dashboard') { |
| 83 | return levelDashboard.execute(interaction, config, client); |
| 84 | } |
| 85 | |
| 86 | if (subcommand === 'setup') { |
| 87 | const channel = interaction.options.getChannel('channel'); |
| 88 | const xpMin = interaction.options.getInteger('xp_min') ?? 15; |
| 89 | const xpMax = interaction.options.getInteger('xp_max') ?? 25; |
| 90 | const message = |
| 91 | interaction.options.getString('message') ?? |
| 92 | '{user} has leveled up to level {level}!'; |
| 93 | const xpCooldown = interaction.options.getInteger('xp_cooldown') ?? 60; |
| 94 | |
| 95 | if (xpMin > xpMax) { |
| 96 | return await replyUserError(interaction, { type: ErrorTypes.VALIDATION, message: 'Minimum XP (**${xpMin}**) cannot be greater than maximum XP (**${xpMax}**).' }); |
| 97 | } |
| 98 | |
| 99 | if (!botHasPermission(channel, ['SendMessages', 'EmbedLinks'])) { |
| 100 | throw new TitanBotError( |
| 101 | 'Bot missing permissions in the specified channel', |
| 102 | ErrorTypes.PERMISSION, |
| 103 | `I need **SendMessages** and **EmbedLinks** permissions in ${channel} to send level-up notifications.`, |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | const existingConfig = await getLevelingConfig(client, interaction.guildId); |
| 108 | |
| 109 | if (existingConfig.configured) { |
| 110 | return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'The leveling system is already set up on this server (level-up notifications go to <#${existingConfig.levelUpChannel}>).\n\nUse \\`/level dashboard\\` to adjust any settings.' }); |
| 111 | } |
| 112 | |
| 113 | const newConfig = { |
| 114 | ...existingConfig, |
| 115 | configured: true, |
| 116 | enabled: true, |
| 117 | levelUpChannel: channel.id, |
| 118 | xpRange: { min: xpMin, max: xpMax }, |
| 119 | xpCooldown: xpCooldown, |
| 120 | levelUpMessage: message, |
| 121 | announceLevelUp: true, |
| 122 | }; |
| 123 | |
| 124 | await saveLevelingConfig(client, interaction.guildId, newConfig); |
| 125 | |
| 126 | logger.info(`Leveling system set up in guild ${interaction.guildId}`, { |
nothing calls this directly
no test coverage detected