PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 2 | import Discord, { CommandInteraction, Message, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuOptionBuilder, APIMessageComponentEmoji, TextInputBuilder, StringSelectMenuInteraction, ButtonInteraction, MessageComponentInteraction, ChannelSelectMenuBuilder, ChannelSelectMenuInteraction } from "discord.js"; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 4 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 5 | import client from "../../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | import convertCurlyBracketString from "../../utils/convertCurlyBracketString.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | import singleNotify from "../../utils/singleNotify.js"; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 8 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 9 | import createPageIndicator from "../../utils/createPageIndicator.js"; |
| 10 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 11 | |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 12 | |
| 13 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 14 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | .setName("stats") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 16 | .setDescription("Controls channels which update when someone joins or leaves the server") |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 17 | |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 18 | |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 19 | const showModal = async (interaction: MessageComponentInteraction, current: { enabled: boolean; name: string; }) => { |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 20 | await interaction.showModal( |
| 21 | new Discord.ModalBuilder() |
| 22 | .setCustomId("modal") |
| 23 | .setTitle(`Stats channel name`) |
| 24 | .addComponents( |
| 25 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 26 | new TextInputBuilder() |
| 27 | .setCustomId("ex1") |
| 28 | .setLabel("Server Info (1/3)") |
| 29 | .setPlaceholder( |
| 30 | `{serverName} - This server's name\n\n` + |
| 31 | `These placeholders will be replaced with the server's name, etc..` |
| 32 | ) |
| 33 | .setMaxLength(1) |
| 34 | .setRequired(false) |
| 35 | .setStyle(Discord.TextInputStyle.Paragraph) |
| 36 | ), |
| 37 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 38 | new TextInputBuilder() |
| 39 | .setCustomId("ex2") |
| 40 | .setLabel("Member Counts (2/3) - {MemberCount:...}") |
| 41 | .setPlaceholder( |
| 42 | `{:all} - Total member count\n` + |
| 43 | `{:humans} - Total non-bot users\n` + |
| 44 | `{:bots} - Number of bots\n` |
| 45 | ) |
| 46 | .setMaxLength(1) |
| 47 | .setRequired(false) |
| 48 | .setStyle(Discord.TextInputStyle.Paragraph) |
| 49 | ), |
| 50 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 51 | new TextInputBuilder() |
| 52 | .setCustomId("ex3") |
| 53 | .setLabel("Latest Member (3/3) - {member:...}") |
| 54 | .setPlaceholder( |
| 55 | `{:name} - The members name\n` |
| 56 | ) |
| 57 | .setMaxLength(1) |
| 58 | .setRequired(false) |
| 59 | .setStyle(Discord.TextInputStyle.Paragraph) |
| 60 | ), |
| 61 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 62 | new TextInputBuilder() |
| 63 | .setCustomId("text") |
| 64 | .setLabel("Channel name input") |
| 65 | .setMaxLength(1000) |
| 66 | .setRequired(true) |
| 67 | .setStyle(Discord.TextInputStyle.Short) |
| 68 | .setValue(current.name) |
| 69 | ) |
| 70 | ) |
| 71 | ); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 72 | } |
| 73 | |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 74 | type ObjectSchema = Record<string, {name: string, enabled: boolean}> |
| 75 | |
| 76 | /* |
| 77 | let out: Discord.ModalSubmitInteraction | null = null; |
| 78 | try { |
| 79 | out = await modalInteractionCollector( |
| 80 | m, |
| 81 | (m) => m.channel!.id === interaction.channel!.id, |
| 82 | (_) => true |
| 83 | ) as Discord.ModalSubmitInteraction | null; |
| 84 | } catch (e) { |
| 85 | continue; |
| 86 | } |
| 87 | if (!out) continue |
| 88 | out = out!; |
| 89 | if (!out.fields) continue; |
| 90 | if (out.isButton()) continue; |
| 91 | const name = out.fields.getTextInputValue("text") |
| 92 | */ |
| 93 | |
| 94 | const addStatsChannel = async (interaction: CommandInteraction, m: Message, currentObject: ObjectSchema): Promise<ObjectSchema> => { |
| 95 | let closed = false; |
| 96 | let cancelled = false; |
| 97 | const originalObject = Object.fromEntries(Object.entries(currentObject).map(([k, v]) => [k, {...v}])); |
| 98 | let newChannel: string | undefined; |
| 99 | let newChannelName: string = "{memberCount:all}-members"; |
| 100 | let newChannelEnabled: boolean = true; |
| 101 | do { |
| 102 | await interaction.editReply({ |
| 103 | embeds: [new EmojiEmbed() |
| 104 | .setTitle("Stats Channel") |
| 105 | .setDescription( |
| 106 | `New stats channel` + (newChannel ? ` in <#${newChannel}>` : "") + "\n\n" + |
| 107 | `**Name:** \`${newChannelName}\`\n` + |
| 108 | `**Preview:** ${await convertCurlyBracketString(newChannelName, interaction.user!.id, interaction.user.username, interaction.guild!.name, interaction.guild!.members)}\n` + |
| 109 | `**Enabled:** ${newChannelEnabled ? "Yes" : "No"}\n\n` |
| 110 | ) |
| 111 | .setEmoji("SETTINGS.STATS.GREEN") |
| 112 | .setStatus("Success") |
| 113 | ], components: [ |
| 114 | new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
| 115 | new ChannelSelectMenuBuilder() |
| 116 | .setCustomId("channel") |
| 117 | ), |
| 118 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 119 | new ButtonBuilder() |
| 120 | .setLabel("Cancel") |
| 121 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 122 | .setStyle(ButtonStyle.Danger) |
| 123 | .setCustomId("back"), |
| 124 | new ButtonBuilder() |
| 125 | .setLabel("Save") |
| 126 | .setEmoji(getEmojiByName("ICONS.SAVE", "id")) |
| 127 | .setStyle(ButtonStyle.Success) |
| 128 | .setCustomId("save"), |
| 129 | new ButtonBuilder() |
| 130 | .setLabel("Edit name") |
| 131 | .setEmoji(getEmojiByName("ICONS.EDIT", "id")) |
| 132 | .setStyle(ButtonStyle.Primary) |
| 133 | .setCustomId("editName"), |
| 134 | new ButtonBuilder() |
| 135 | .setLabel(newChannelEnabled ? "Enabled" : "Disabled") |
| 136 | .setEmoji(getEmojiByName(newChannelEnabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id")) |
| 137 | .setStyle(ButtonStyle.Secondary) |
| 138 | .setCustomId("toggleEnabled") |
| 139 | ) |
| 140 | ] |
| 141 | }); |
| 142 | let i: ButtonInteraction | ChannelSelectMenuInteraction; |
| 143 | try { |
| 144 | i = await m.awaitMessageComponent({ time: 300000, filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }}) as ButtonInteraction | ChannelSelectMenuInteraction; |
| 145 | } catch (e) { |
| 146 | closed = true; |
| 147 | cancelled = true; |
| 148 | break; |
| 149 | } |
| 150 | if (i.isButton()) { |
| 151 | switch (i.customId) { |
| 152 | case "back": |
| 153 | if(!i.deferred) await i.deferUpdate(); |
| 154 | closed = true; |
| 155 | break; |
| 156 | case "save": |
| 157 | if(!i.deferred) await i.deferUpdate(); //I'm lost... |
| 158 | if (newChannel) { |
| 159 | currentObject[newChannel] = { |
| 160 | name: newChannelName, |
| 161 | enabled: newChannelEnabled |
| 162 | } |
| 163 | } |
| 164 | closed = true; |
| 165 | break; |
| 166 | case "editName": |
| 167 | await interaction.editReply({ |
| 168 | embeds: [new EmojiEmbed() |
| 169 | .setTitle("Stats Channel") |
| 170 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 171 | .setStatus("Success") |
| 172 | .setEmoji("SETTINGS.STATS.GREEN") |
| 173 | ], |
| 174 | components: [ |
| 175 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 176 | new ButtonBuilder() |
| 177 | .setLabel("Back") |
| 178 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 179 | .setStyle(ButtonStyle.Primary) |
| 180 | .setCustomId("back") |
| 181 | ) |
| 182 | ] |
| 183 | }); |
| 184 | showModal(i, {name: newChannelName, enabled: newChannelEnabled}) |
| 185 | |
| 186 | const out = await modalInteractionCollector( |
| 187 | m, |
| 188 | (m) => m.channel!.id === interaction.channel!.id, |
| 189 | (_) => true |
| 190 | ) as Discord.ModalSubmitInteraction | null; |
| 191 | if (!out) continue; |
| 192 | if (!out.fields) continue; |
| 193 | if (out.isButton()) continue; |
| 194 | newChannelName = out.fields.getTextInputValue("text"); |
| 195 | break; |
| 196 | case "toggleEnabled": |
| 197 | if(!i.deferred) await i.deferUpdate(); |
| 198 | newChannelEnabled = !newChannelEnabled; |
| 199 | break; |
| 200 | } |
| 201 | } else { |
| 202 | if(!i.deferred) await i.deferUpdate(); |
| 203 | if (i.customId === "channel") { |
| 204 | newChannel = i.values[0]; |
| 205 | } |
| 206 | } |
| 207 | } while (!closed) |
| 208 | if (cancelled) return originalObject; |
| 209 | if (!(newChannel && newChannelName && newChannelEnabled)) return originalObject; |
| 210 | return currentObject; // check 157 |
| 211 | } |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 212 | const callback = async (interaction: CommandInteraction) => { |
| 213 | if (!interaction.guild) return; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 214 | const { renderChannel } = client.logger; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 215 | const m: Message = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true }); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 216 | let page = 0; |
| 217 | let closed = false; |
| 218 | const config = await client.database.guilds.read(interaction.guild.id); |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 219 | let currentObject: ObjectSchema = config.stats; |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 220 | let modified = false; |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 221 | do { |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 222 | let embed = new EmojiEmbed() |
| 223 | .setTitle("Stats Settings") |
| 224 | .setEmoji("SETTINGS.STATS.GREEN") |
| 225 | .setStatus("Success"); |
| 226 | const noStatsChannels = Object.keys(currentObject).length === 0; |
| 227 | let current: { enabled: boolean; name: string; }; |
| 228 | |
| 229 | const pageSelect = new StringSelectMenuBuilder() |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 230 | .setCustomId("page") |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 231 | .setPlaceholder("Select a stats channel to manage"); |
| 232 | const actionSelect = new StringSelectMenuBuilder() |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 233 | .setCustomId("action") |
| 234 | .setPlaceholder("Perform an action") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 235 | .addOptions( |
| 236 | new StringSelectMenuOptionBuilder() |
| 237 | .setLabel("Edit") |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 238 | .setDescription("Edit the stats channel") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 239 | .setValue("edit") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 240 | .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji), |
| 241 | new StringSelectMenuOptionBuilder() |
| 242 | .setLabel("Delete") |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 243 | .setDescription("Delete the stats channel") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 244 | .setValue("delete") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 245 | .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji) |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 246 | ); |
| 247 | const buttonRow = new ActionRowBuilder<ButtonBuilder>() |
| 248 | .addComponents( |
| 249 | new ButtonBuilder() |
| 250 | .setCustomId("back") |
| 251 | .setStyle(ButtonStyle.Primary) |
| 252 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 253 | .setDisabled(page === 0), |
| 254 | new ButtonBuilder() |
| 255 | .setCustomId("next") |
| 256 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji) |
| 257 | .setStyle(ButtonStyle.Primary) |
| 258 | .setDisabled(page === Object.keys(currentObject).length - 1), |
| 259 | new ButtonBuilder() |
| 260 | .setCustomId("add") |
| 261 | .setLabel("Create new") |
| 262 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji) |
| 263 | .setStyle(ButtonStyle.Secondary) |
| 264 | .setDisabled(Object.keys(currentObject).length >= 24), |
| 265 | new ButtonBuilder() |
| 266 | .setCustomId("save") |
| 267 | .setLabel("Save") |
| 268 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji) |
| 269 | .setStyle(ButtonStyle.Success) |
| 270 | .setDisabled(modified), |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 271 | ); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 272 | if (noStatsChannels) { |
| 273 | embed.setDescription("No stats channels have been set up yet. Use the button below to add one.\n\n" + |
| 274 | createPageIndicator(1, 1, undefined, true) |
| 275 | ); |
| 276 | pageSelect.setDisabled(true); |
| 277 | actionSelect.setDisabled(true); |
| 278 | pageSelect.addOptions(new StringSelectMenuOptionBuilder() |
| 279 | .setLabel("No stats channels") |
| 280 | .setValue("none") |
| 281 | ); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 282 | } else { |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 283 | page = Math.min(page, Object.keys(currentObject).length - 1); |
| 284 | current = currentObject[Object.keys(config.stats)[page]!]! |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 285 | actionSelect.addOptions(new StringSelectMenuOptionBuilder() |
| 286 | .setLabel(current.enabled ? "Disable" : "Enable") |
| 287 | .setValue("toggleEnabled") |
| 288 | .setDescription(`Currently ${current.enabled ? "Enabled" : "Disabled"}, click to ${current.enabled ? "disable" : "enable"} this channel`) |
| 289 | .setEmoji(getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji) |
| 290 | ); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 291 | |
| 292 | embed.setDescription(`**Currently Editing:** ${renderChannel(Object.keys(currentObject)[page]!)}\n\n` + |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 293 | `${getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS")} Currently ${current.enabled ? "Enabled" : "Disabled"}\n` + |
| 294 | `**Name:** \`${current.name}\`\n` + |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 295 | `**Preview:** ${await convertCurlyBracketString(current.name, interaction.user.id, interaction.user.username, interaction.guild.name, interaction.guild.members)}` + '\n\n' + |
| 296 | createPageIndicator(Object.keys(config.stats).length, page) |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 297 | ); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 298 | for (const [id, { name, enabled }] of Object.entries(currentObject)) { |
| 299 | pageSelect.addOptions(new StringSelectMenuOptionBuilder() |
| 300 | .setLabel(`${name} (${renderChannel(id)})`) |
| 301 | .setEmoji(getEmojiByName(enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji) |
| 302 | .setDescription(`${enabled ? "Enabled" : "Disabled"}`) |
| 303 | .setValue(id) |
| 304 | ); |
| 305 | } |
| 306 | } |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 307 | |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 308 | interaction.editReply({embeds: [embed], components: [ |
| 309 | new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect), |
| 310 | new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect), |
| 311 | buttonRow |
| 312 | ]}); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 313 | |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 314 | let i: StringSelectMenuInteraction | ButtonInteraction; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 315 | try { |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 316 | i = await m.awaitMessageComponent({ filter: (interaction) => interaction.user.id === interaction.user.id, time: 60000 }) as StringSelectMenuInteraction | ButtonInteraction; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 317 | } catch (e) { |
| 318 | closed = true; |
| 319 | continue; |
| 320 | } |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 321 | |
| 322 | if(i.isStringSelectMenu()) { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 323 | switch(i.customId) { |
| 324 | case "page": |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 325 | page = Object.keys(currentObject).indexOf(i.values[0]!); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 326 | break; |
| 327 | case "action": |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 328 | modified = true; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 329 | switch(i.values[0]!) { |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 330 | case "edit": { |
| 331 | showModal(i, current!) |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 332 | await interaction.editReply({ |
| 333 | embeds: [ |
| 334 | new EmojiEmbed() |
| 335 | .setTitle("Stats Channel") |
| 336 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 337 | .setStatus("Success") |
| 338 | .setEmoji("SETTINGS.STATS.GREEN") |
| 339 | ], |
| 340 | components: [ |
| 341 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 342 | new ButtonBuilder() |
| 343 | .setLabel("Back") |
| 344 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 345 | .setStyle(ButtonStyle.Primary) |
| 346 | .setCustomId("back") |
| 347 | ) |
| 348 | ] |
| 349 | }); |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 350 | let out: Discord.ModalSubmitInteraction | null; |
| 351 | try { |
| 352 | out = await modalInteractionCollector( |
| 353 | m, |
| 354 | (m) => m.channel!.id === interaction.channel!.id, |
| 355 | (_) => true |
| 356 | ) as Discord.ModalSubmitInteraction | null; |
| 357 | } catch (e) { |
| 358 | continue; |
| 359 | } |
| 360 | if (!out) continue |
| 361 | if (!out.fields) continue |
| 362 | if (out.isButton()) continue; |
| 363 | currentObject[Object.keys(currentObject)[page]!]!.name = out.fields.getTextInputValue("text"); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 364 | break; |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 365 | } |
| 366 | case "toggleEnabled": { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 367 | i.deferUpdate(); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 368 | currentObject[Object.keys(currentObject)[page]!]!.enabled = !currentObject[Object.keys(currentObject)[page]!]!.enabled; |
| 369 | modified = true; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 370 | break; |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 371 | } |
| 372 | case "delete": { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 373 | i.deferUpdate(); |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 374 | delete currentObject[Object.keys(currentObject)[page]!]; |
| 375 | modified = true; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 376 | break; |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 377 | } |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 378 | } |
| 379 | break; |
| 380 | } |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 381 | } else { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 382 | i.deferUpdate(); |
| 383 | switch(i.customId) { |
| 384 | case "back": |
| 385 | page--; |
| 386 | break; |
| 387 | case "next": |
| 388 | page++; |
| 389 | break; |
| 390 | case "add": |
TheCodedProf | 9bc8475 | 2023-01-21 05:19:57 -0500 | [diff] [blame^] | 391 | currentObject = await addStatsChannel(interaction, m, currentObject); |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 392 | break; |
| 393 | case "save": |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 394 | client.database.guilds.write(interaction.guild.id, {stats: currentObject}); |
| 395 | singleNotify("statsChannelDeleted", interaction.guild.id, true); |
| 396 | modified = false; |
| 397 | break; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 398 | } |
| 399 | } |
TheCodedProf | c2acbcc | 2023-01-20 17:23:51 -0500 | [diff] [blame] | 400 | |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 401 | } while (!closed); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 402 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 403 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 404 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 405 | const member = interaction.member as Discord.GuildMember; |
TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 406 | if (!member.permissions.has("ManageChannels")) |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 407 | return "You must have the *Manage Channels* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 408 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 409 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 410 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 411 | |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 412 | export { command }; |
| 413 | export { callback }; |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 414 | export { check }; |