blob: d4e4439931ce4d3dfcb1d4dcc7828aea68e6aab4 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../utils/defaults.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00002import Discord, {
3 CommandInteraction,
4 Message,
5 ActionRowBuilder,
6 StringSelectMenuBuilder,
7 ButtonBuilder,
8 ButtonStyle,
9 StringSelectMenuOptionBuilder,
10 APIMessageComponentEmoji,
11 TextInputBuilder,
12 StringSelectMenuInteraction,
13 ButtonInteraction,
14 MessageComponentInteraction,
15 ChannelSelectMenuBuilder,
16 ChannelSelectMenuInteraction,
17 ModalBuilder
18} from "discord.js";
pineafan0bc04162022-07-25 17:22:26 +010019import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
TheCodedProff86ba092023-01-27 17:10:07 -050020import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan0bc04162022-07-25 17:22:26 +010021import client from "../../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +010022import convertCurlyBracketString from "../../utils/convertCurlyBracketString.js";
pineafan63fc5e22022-08-04 22:04:10 +010023import singleNotify from "../../utils/singleNotify.js";
TheCodedProf4a6d5712023-01-19 15:54:40 -050024import getEmojiByName from "../../utils/getEmojiByName.js";
25import createPageIndicator from "../../utils/createPageIndicator.js";
26import { modalInteractionCollector } from "../../utils/dualCollector.js";
TheCodedProfc2acbcc2023-01-20 17:23:51 -050027
pineafan708692b2022-07-24 22:16:22 +010028const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Greyda16adf2023-03-05 10:22:12 +000029 builder.setName("stats").setDescription("Controls channels which update when someone joins or leaves the server");
pineafan708692b2022-07-24 22:16:22 +010030
Skyler Greyda16adf2023-03-05 10:22:12 +000031const showModal = async (interaction: MessageComponentInteraction, current: { enabled: boolean; name: string }) => {
TheCodedProfc2acbcc2023-01-20 17:23:51 -050032 await interaction.showModal(
TheCodedProff4facde2023-01-28 13:42:48 -050033 new ModalBuilder()
TheCodedProfc2acbcc2023-01-20 17:23:51 -050034 .setCustomId("modal")
35 .setTitle(`Stats channel name`)
36 .addComponents(
37 new ActionRowBuilder<TextInputBuilder>().addComponents(
38 new TextInputBuilder()
39 .setCustomId("ex1")
40 .setLabel("Server Info (1/3)")
41 .setPlaceholder(
42 `{serverName} - This server's name\n\n` +
Skyler Greyda16adf2023-03-05 10:22:12 +000043 `These placeholders will be replaced with the server's name, etc..`
TheCodedProfc2acbcc2023-01-20 17:23:51 -050044 )
45 .setMaxLength(1)
46 .setRequired(false)
47 .setStyle(Discord.TextInputStyle.Paragraph)
48 ),
49 new ActionRowBuilder<TextInputBuilder>().addComponents(
50 new TextInputBuilder()
51 .setCustomId("ex2")
52 .setLabel("Member Counts (2/3) - {MemberCount:...}")
53 .setPlaceholder(
54 `{:all} - Total member count\n` +
Skyler Greyda16adf2023-03-05 10:22:12 +000055 `{:humans} - Total non-bot users\n` +
56 `{:bots} - Number of bots\n`
TheCodedProfc2acbcc2023-01-20 17:23:51 -050057 )
58 .setMaxLength(1)
59 .setRequired(false)
60 .setStyle(Discord.TextInputStyle.Paragraph)
61 ),
62 new ActionRowBuilder<TextInputBuilder>().addComponents(
63 new TextInputBuilder()
64 .setCustomId("ex3")
65 .setLabel("Latest Member (3/3) - {member:...}")
Skyler Greyda16adf2023-03-05 10:22:12 +000066 .setPlaceholder(`{:name} - The members name\n`)
TheCodedProfc2acbcc2023-01-20 17:23:51 -050067 .setMaxLength(1)
68 .setRequired(false)
69 .setStyle(Discord.TextInputStyle.Paragraph)
70 ),
71 new ActionRowBuilder<TextInputBuilder>().addComponents(
72 new TextInputBuilder()
73 .setCustomId("text")
74 .setLabel("Channel name input")
75 .setMaxLength(1000)
76 .setRequired(true)
77 .setStyle(Discord.TextInputStyle.Short)
78 .setValue(current.name)
79 )
80 )
81 );
Skyler Greyda16adf2023-03-05 10:22:12 +000082};
TheCodedProf4a6d5712023-01-19 15:54:40 -050083
Skyler Greyda16adf2023-03-05 10:22:12 +000084type ObjectSchema = Record<string, { name: string; enabled: boolean }>;
TheCodedProf9bc84752023-01-21 05:19:57 -050085
Skyler Greyda16adf2023-03-05 10:22:12 +000086const addStatsChannel = async (
87 interaction: CommandInteraction,
88 m: Message,
89 currentObject: ObjectSchema
90): Promise<ObjectSchema> => {
TheCodedProf9bc84752023-01-21 05:19:57 -050091 let closed = false;
92 let cancelled = false;
Skyler Greyda16adf2023-03-05 10:22:12 +000093 const originalObject = Object.fromEntries(Object.entries(currentObject).map(([k, v]) => [k, { ...v }]));
TheCodedProf9bc84752023-01-21 05:19:57 -050094 let newChannel: string | undefined;
95 let newChannelName: string = "{memberCount:all}-members";
96 let newChannelEnabled: boolean = true;
97 do {
TheCodedProf267563a2023-01-21 17:00:57 -050098 m = await interaction.editReply({
Skyler Greyda16adf2023-03-05 10:22:12 +000099 embeds: [
100 new EmojiEmbed()
101 .setTitle("Stats Channel")
102 .setDescription(
103 `New stats channel` +
104 (newChannel ? ` in <#${newChannel}>` : "") +
105 "\n\n" +
106 `**Name:** \`${newChannelName}\`\n` +
107 `**Preview:** ${await convertCurlyBracketString(
108 newChannelName,
109 interaction.user!.id,
110 interaction.user.username,
111 interaction.guild!.name,
112 interaction.guild!.members
113 )}\n` +
114 `**Enabled:** ${newChannelEnabled ? "Yes" : "No"}\n\n`
115 )
116 .setEmoji("SETTINGS.STATS.GREEN")
117 .setStatus("Success")
118 ],
119 components: [
TheCodedProf9bc84752023-01-21 05:19:57 -0500120 new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(
Skyler Greyda16adf2023-03-05 10:22:12 +0000121 new ChannelSelectMenuBuilder().setCustomId("channel").setPlaceholder("Select a channel to use")
TheCodedProf9bc84752023-01-21 05:19:57 -0500122 ),
123 new ActionRowBuilder<ButtonBuilder>().addComponents(
124 new ButtonBuilder()
125 .setLabel("Cancel")
126 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
127 .setStyle(ButtonStyle.Danger)
128 .setCustomId("back"),
129 new ButtonBuilder()
130 .setLabel("Save")
131 .setEmoji(getEmojiByName("ICONS.SAVE", "id"))
132 .setStyle(ButtonStyle.Success)
133 .setCustomId("save"),
134 new ButtonBuilder()
135 .setLabel("Edit name")
136 .setEmoji(getEmojiByName("ICONS.EDIT", "id"))
137 .setStyle(ButtonStyle.Primary)
138 .setCustomId("editName"),
139 new ButtonBuilder()
140 .setLabel(newChannelEnabled ? "Enabled" : "Disabled")
141 .setEmoji(getEmojiByName(newChannelEnabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id"))
142 .setStyle(ButtonStyle.Secondary)
143 .setCustomId("toggleEnabled")
144 )
145 ]
146 });
147 let i: ButtonInteraction | ChannelSelectMenuInteraction;
148 try {
Skyler Greyda16adf2023-03-05 10:22:12 +0000149 i = (await m.awaitMessageComponent({
150 time: 300000,
151 filter: (i) => {
152 return (
153 i.user.id === interaction.user.id &&
154 i.channel!.id === interaction.channel!.id &&
155 i.message.id === m.id
156 );
157 }
158 })) as ButtonInteraction | ChannelSelectMenuInteraction;
TheCodedProf9bc84752023-01-21 05:19:57 -0500159 } catch (e) {
160 closed = true;
161 cancelled = true;
162 break;
163 }
164 if (i.isButton()) {
165 switch (i.customId) {
PineaFanb0d0c242023-02-05 10:59:45 +0000166 case "back": {
TheCodedProf267563a2023-01-21 17:00:57 -0500167 await i.deferUpdate();
TheCodedProf9bc84752023-01-21 05:19:57 -0500168 closed = true;
169 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000170 }
171 case "save": {
TheCodedProf267563a2023-01-21 17:00:57 -0500172 await i.deferUpdate();
TheCodedProf9bc84752023-01-21 05:19:57 -0500173 if (newChannel) {
174 currentObject[newChannel] = {
175 name: newChannelName,
176 enabled: newChannelEnabled
Skyler Greyda16adf2023-03-05 10:22:12 +0000177 };
TheCodedProf9bc84752023-01-21 05:19:57 -0500178 }
179 closed = true;
180 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000181 }
182 case "editName": {
TheCodedProf9bc84752023-01-21 05:19:57 -0500183 await interaction.editReply({
Skyler Greyda16adf2023-03-05 10:22:12 +0000184 embeds: [
185 new EmojiEmbed()
186 .setTitle("Stats Channel")
187 .setDescription("Modal opened. If you can't see it, click back and try again.")
188 .setStatus("Success")
189 .setEmoji("SETTINGS.STATS.GREEN")
TheCodedProf9bc84752023-01-21 05:19:57 -0500190 ],
191 components: [
192 new ActionRowBuilder<ButtonBuilder>().addComponents(
193 new ButtonBuilder()
194 .setLabel("Back")
195 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
196 .setStyle(ButtonStyle.Primary)
197 .setCustomId("back")
198 )
199 ]
200 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000201 showModal(i, { name: newChannelName, enabled: newChannelEnabled });
TheCodedProf9bc84752023-01-21 05:19:57 -0500202
Skyler Greyda16adf2023-03-05 10:22:12 +0000203 const out: Discord.ModalSubmitInteraction | ButtonInteraction | null =
204 await modalInteractionCollector(m, interaction.user);
TheCodedProf9bc84752023-01-21 05:19:57 -0500205 if (!out) continue;
TheCodedProf9bc84752023-01-21 05:19:57 -0500206 if (out.isButton()) continue;
207 newChannelName = out.fields.getTextInputValue("text");
208 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000209 }
210 case "toggleEnabled": {
TheCodedProf267563a2023-01-21 17:00:57 -0500211 await i.deferUpdate();
TheCodedProf9bc84752023-01-21 05:19:57 -0500212 newChannelEnabled = !newChannelEnabled;
213 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000214 }
TheCodedProf9bc84752023-01-21 05:19:57 -0500215 }
216 } else {
TheCodedProf267563a2023-01-21 17:00:57 -0500217 await i.deferUpdate();
TheCodedProf9bc84752023-01-21 05:19:57 -0500218 if (i.customId === "channel") {
219 newChannel = i.values[0];
220 }
221 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000222 } while (!closed);
TheCodedProf9bc84752023-01-21 05:19:57 -0500223 if (cancelled) return originalObject;
224 if (!(newChannel && newChannelName && newChannelEnabled)) return originalObject;
TheCodedProf267563a2023-01-21 17:00:57 -0500225 return currentObject;
Skyler Greyda16adf2023-03-05 10:22:12 +0000226};
PineaFan5d98a4b2023-01-19 16:15:47 +0000227const callback = async (interaction: CommandInteraction) => {
228 if (!interaction.guild) return;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500229 const { renderChannel } = client.logger;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500230 const m: Message = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500231 let page = 0;
232 let closed = false;
233 const config = await client.database.guilds.read(interaction.guild.id);
TheCodedProf9bc84752023-01-21 05:19:57 -0500234 let currentObject: ObjectSchema = config.stats;
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500235 let modified = false;
PineaFan5d98a4b2023-01-19 16:15:47 +0000236 do {
Skyler Greyda16adf2023-03-05 10:22:12 +0000237 const embed = new EmojiEmbed().setTitle("Stats Settings").setEmoji("SETTINGS.STATS.GREEN").setStatus("Success");
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500238 const noStatsChannels = Object.keys(currentObject).length === 0;
Skyler Greyda16adf2023-03-05 10:22:12 +0000239 let current: { enabled: boolean; name: string };
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500240
241 const pageSelect = new StringSelectMenuBuilder()
PineaFan5d98a4b2023-01-19 16:15:47 +0000242 .setCustomId("page")
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500243 .setPlaceholder("Select a stats channel to manage");
244 const actionSelect = new StringSelectMenuBuilder()
TheCodedProf4a6d5712023-01-19 15:54:40 -0500245 .setCustomId("action")
246 .setPlaceholder("Perform an action")
TheCodedProf4a6d5712023-01-19 15:54:40 -0500247 .addOptions(
248 new StringSelectMenuOptionBuilder()
249 .setLabel("Edit")
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500250 .setDescription("Edit the stats channel")
TheCodedProf4a6d5712023-01-19 15:54:40 -0500251 .setValue("edit")
TheCodedProf4a6d5712023-01-19 15:54:40 -0500252 .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
253 new StringSelectMenuOptionBuilder()
254 .setLabel("Delete")
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500255 .setDescription("Delete the stats channel")
TheCodedProf4a6d5712023-01-19 15:54:40 -0500256 .setValue("delete")
TheCodedProf4a6d5712023-01-19 15:54:40 -0500257 .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji)
258 );
Skyler Greyda16adf2023-03-05 10:22:12 +0000259 const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
260 new ButtonBuilder()
261 .setCustomId("back")
262 .setStyle(ButtonStyle.Primary)
263 .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
264 .setDisabled(page === 0),
265 new ButtonBuilder()
266 .setCustomId("next")
267 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji)
268 .setStyle(ButtonStyle.Primary)
269 .setDisabled(page === Object.keys(currentObject).length - 1),
270 new ButtonBuilder()
271 .setCustomId("add")
272 .setLabel("Create new")
273 .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji)
274 .setStyle(ButtonStyle.Secondary)
275 .setDisabled(Object.keys(currentObject).length >= 24),
276 new ButtonBuilder()
277 .setCustomId("save")
278 .setLabel("Save")
279 .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji)
280 .setStyle(ButtonStyle.Success)
281 .setDisabled(modified)
282 );
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500283 if (noStatsChannels) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000284 embed.setDescription(
285 "No stats channels have been set up yet. Use the button below to add one.\n\n" +
286 createPageIndicator(1, 1, undefined, true)
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500287 );
288 pageSelect.setDisabled(true);
289 actionSelect.setDisabled(true);
Skyler Greyda16adf2023-03-05 10:22:12 +0000290 pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No stats channels").setValue("none"));
TheCodedProf4a6d5712023-01-19 15:54:40 -0500291 } else {
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500292 page = Math.min(page, Object.keys(currentObject).length - 1);
Skyler Greyda16adf2023-03-05 10:22:12 +0000293 current = currentObject[Object.keys(config.stats)[page]!]!;
294 actionSelect.addOptions(
295 new StringSelectMenuOptionBuilder()
296 .setLabel(current.enabled ? "Disable" : "Enable")
297 .setValue("toggleEnabled")
298 .setDescription(
299 `Currently ${current.enabled ? "Enabled" : "Disabled"}, click to ${
300 current.enabled ? "disable" : "enable"
301 } this channel`
302 )
303 .setEmoji(
304 getEmojiByName(
305 current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS",
306 "id"
307 ) as APIMessageComponentEmoji
308 )
TheCodedProf4a6d5712023-01-19 15:54:40 -0500309 );
Skyler Greyda16adf2023-03-05 10:22:12 +0000310 embed.setDescription(
311 `**Currently Editing:** ${renderChannel(Object.keys(currentObject)[page]!)}\n\n` +
312 `${getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS")} Currently ${
313 current.enabled ? "Enabled" : "Disabled"
314 }\n` +
315 `**Name:** \`${current.name}\`\n` +
316 `**Preview:** ${await convertCurlyBracketString(
317 current.name,
318 interaction.user.id,
319 interaction.user.username,
320 interaction.guild.name,
321 interaction.guild.members
322 )}` +
323 "\n\n" +
324 createPageIndicator(Object.keys(config.stats).length, page)
TheCodedProf4a6d5712023-01-19 15:54:40 -0500325 );
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500326 for (const [id, { name, enabled }] of Object.entries(currentObject)) {
Skyler Greyda16adf2023-03-05 10:22:12 +0000327 pageSelect.addOptions(
328 new StringSelectMenuOptionBuilder()
329 .setLabel(`${name} (${renderChannel(id)})`)
330 .setEmoji(
331 getEmojiByName(enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji
332 )
333 .setDescription(`${enabled ? "Enabled" : "Disabled"}`)
334 .setValue(id)
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500335 );
336 }
337 }
TheCodedProf4a6d5712023-01-19 15:54:40 -0500338
Skyler Greyda16adf2023-03-05 10:22:12 +0000339 interaction.editReply({
340 embeds: [embed],
341 components: [
342 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect),
343 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect),
344 buttonRow
345 ]
346 });
TheCodedProf4a6d5712023-01-19 15:54:40 -0500347
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500348 let i: StringSelectMenuInteraction | ButtonInteraction;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500349 try {
Skyler Greyda16adf2023-03-05 10:22:12 +0000350 i = (await m.awaitMessageComponent({
351 filter: (interaction) => interaction.user.id === interaction.user.id,
352 time: 60000
353 })) as StringSelectMenuInteraction | ButtonInteraction;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500354 } catch (e) {
355 closed = true;
356 continue;
357 }
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500358
Skyler Greyda16adf2023-03-05 10:22:12 +0000359 if (i.isStringSelectMenu()) {
360 switch (i.customId) {
PineaFanb0d0c242023-02-05 10:59:45 +0000361 case "page": {
TheCodedProf267563a2023-01-21 17:00:57 -0500362 await i.deferUpdate();
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500363 page = Object.keys(currentObject).indexOf(i.values[0]!);
TheCodedProf4a6d5712023-01-19 15:54:40 -0500364 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000365 }
366 case "action": {
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500367 modified = true;
Skyler Greyda16adf2023-03-05 10:22:12 +0000368 switch (i.values[0]!) {
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500369 case "edit": {
Skyler Greyda16adf2023-03-05 10:22:12 +0000370 showModal(i, current!);
TheCodedProf4a6d5712023-01-19 15:54:40 -0500371 await interaction.editReply({
372 embeds: [
373 new EmojiEmbed()
374 .setTitle("Stats Channel")
375 .setDescription("Modal opened. If you can't see it, click back and try again.")
376 .setStatus("Success")
377 .setEmoji("SETTINGS.STATS.GREEN")
378 ],
379 components: [
380 new ActionRowBuilder<ButtonBuilder>().addComponents(
381 new ButtonBuilder()
382 .setLabel("Back")
383 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
384 .setStyle(ButtonStyle.Primary)
385 .setCustomId("back")
386 )
387 ]
388 });
TheCodedProf9bc84752023-01-21 05:19:57 -0500389 let out: Discord.ModalSubmitInteraction | null;
390 try {
Skyler Greyda16adf2023-03-05 10:22:12 +0000391 out = (await modalInteractionCollector(
392 m,
393 interaction.user
394 )) as Discord.ModalSubmitInteraction | null;
TheCodedProf9bc84752023-01-21 05:19:57 -0500395 } catch (e) {
396 continue;
397 }
Skyler Greyda16adf2023-03-05 10:22:12 +0000398 if (!out) continue;
TheCodedProf9bc84752023-01-21 05:19:57 -0500399 if (out.isButton()) continue;
Skyler Greyda16adf2023-03-05 10:22:12 +0000400 currentObject[Object.keys(currentObject)[page]!]!.name =
401 out.fields.getTextInputValue("text");
TheCodedProf4a6d5712023-01-19 15:54:40 -0500402 break;
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500403 }
404 case "toggleEnabled": {
TheCodedProf267563a2023-01-21 17:00:57 -0500405 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +0000406 currentObject[Object.keys(currentObject)[page]!]!.enabled =
407 !currentObject[Object.keys(currentObject)[page]!]!.enabled;
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500408 modified = true;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500409 break;
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500410 }
411 case "delete": {
TheCodedProf267563a2023-01-21 17:00:57 -0500412 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +0000413 currentObject = Object.fromEntries(
414 Object.entries(currentObject).filter(([k]) => k !== Object.keys(currentObject)[page]!)
415 );
TheCodedProf267563a2023-01-21 17:00:57 -0500416 page = Math.min(page, Object.keys(currentObject).length - 1);
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500417 modified = true;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500418 break;
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500419 }
TheCodedProf4a6d5712023-01-19 15:54:40 -0500420 }
421 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000422 }
TheCodedProf4a6d5712023-01-19 15:54:40 -0500423 }
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500424 } else {
TheCodedProf267563a2023-01-21 17:00:57 -0500425 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +0000426 switch (i.customId) {
PineaFanb0d0c242023-02-05 10:59:45 +0000427 case "back": {
TheCodedProf4a6d5712023-01-19 15:54:40 -0500428 page--;
429 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000430 }
431 case "next": {
TheCodedProf4a6d5712023-01-19 15:54:40 -0500432 page++;
433 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000434 }
435 case "add": {
TheCodedProf9bc84752023-01-21 05:19:57 -0500436 currentObject = await addStatsChannel(interaction, m, currentObject);
TheCodedProf267563a2023-01-21 17:00:57 -0500437 page = Object.keys(currentObject).length - 1;
TheCodedProf4a6d5712023-01-19 15:54:40 -0500438 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000439 }
440 case "save": {
Skyler Greyda16adf2023-03-05 10:22:12 +0000441 await client.database.guilds.write(interaction.guild.id, { stats: currentObject });
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500442 singleNotify("statsChannelDeleted", interaction.guild.id, true);
443 modified = false;
Skyler Grey16ecb172023-03-05 07:30:32 +0000444 await client.memory.forceUpdate(interaction.guild.id);
TheCodedProfc2acbcc2023-01-20 17:23:51 -0500445 break;
PineaFanb0d0c242023-02-05 10:59:45 +0000446 }
TheCodedProf4a6d5712023-01-19 15:54:40 -0500447 }
448 }
PineaFan5d98a4b2023-01-19 16:15:47 +0000449 } while (!closed);
Skyler Greyda16adf2023-03-05 10:22:12 +0000450 await interaction.deleteReply();
pineafan63fc5e22022-08-04 22:04:10 +0100451};
pineafan708692b2022-07-24 22:16:22 +0100452
TheCodedProff86ba092023-01-27 17:10:07 -0500453const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100454 const member = interaction.member as Discord.GuildMember;
TheCodedProfafca98b2023-01-17 22:25:43 -0500455 if (!member.permissions.has("ManageChannels"))
PineaFan0d06edc2023-01-17 22:10:31 +0000456 return "You must have the *Manage Channels* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100457 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100458};
pineafan708692b2022-07-24 22:16:22 +0100459
460export { command };
461export { callback };
Skyler Grey16ecb172023-03-05 07:30:32 +0000462export { check };