blob: 1093bd2344370ea5d02662797bb8816d3738a5b2 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../utils/defaults.js";
PineaFan5d98a4b2023-01-19 16:15:47 +00002import Discord, { CommandInteraction, Message, ActionRowBuilder, GuildMember, StringSelectMenuBuilder, StringSelectMenuInteraction, SelectMenuOptionBuilder } from "discord.js";
pineafan0bc04162022-07-25 17:22:26 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
4import confirmationMessage from "../../utils/confirmationMessage.js";
TheCodedProfafca98b2023-01-17 22:25:43 -05005import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan0bc04162022-07-25 17:22:26 +01006import client from "../../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +01007import convertCurlyBracketString from "../../utils/convertCurlyBracketString.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01008import { callback as statsChannelAddCallback } from "../../reflex/statsChannelUpdate.js";
pineafan63fc5e22022-08-04 22:04:10 +01009import singleNotify from "../../utils/singleNotify.js";
pineafan708692b2022-07-24 22:16:22 +010010
11const command = (builder: SlashCommandSubcommandBuilder) =>
12 builder
pineafan63fc5e22022-08-04 22:04:10 +010013 .setName("stats")
Skyler Grey11236ba2022-08-08 21:13:33 +010014 .setDescription("Controls channels which update when someone joins or leaves the server")
pineafan708692b2022-07-24 22:16:22 +010015
PineaFan5d98a4b2023-01-19 16:15:47 +000016const callback = async (interaction: CommandInteraction) => {
17 if (!interaction.guild) return;
18 let closed = false;
19 let page = 0;
20 do {
21 const config = await client.database.guilds.read(interaction.guild.id);
22 const stats = config.stats; // stats: Record<string, { name: string; enabled: boolean }>
23 if (!stats) {
24 await interaction.editReply({embeds: [new EmojiEmbed()
25 .setTitle("Stats channels")
26 .setDescription("You don't have ant stats channels yet")
27 .setStatus("Success")
28 .setEmoji("")
29 ]})
pineafane23c4ec2022-07-27 21:56:27 +010030 }
PineaFan5d98a4b2023-01-19 16:15:47 +000031 let pageSelect = new StringSelectMenuBuilder()
32 .setCustomId("page")
33 .setPlaceholder("Select a stats channel to manage")
pineafan0bc04162022-07-25 17:22:26 +010034 .setMinValues(1)
PineaFan5d98a4b2023-01-19 16:15:47 +000035 .setMaxValues(1);
36 for (const [id, { name, enabled }] of Object.entries(stats)) {
37 pageSelect.addOption()
Skyler Grey75ea9172022-08-06 10:22:23 +010038 }
PineaFan5d98a4b2023-01-19 16:15:47 +000039 // [ Action... ] -> Edit, delete, reorder
40 // [Back][Next][Add]
41 } while (!closed);
42 closed = true;
pineafan63fc5e22022-08-04 22:04:10 +010043};
pineafan708692b2022-07-24 22:16:22 +010044
PineaFan64486c42022-12-28 09:21:04 +000045const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +010046 const member = interaction.member as Discord.GuildMember;
TheCodedProfafca98b2023-01-17 22:25:43 -050047 if (!member.permissions.has("ManageChannels"))
PineaFan0d06edc2023-01-17 22:10:31 +000048 return "You must have the *Manage Channels* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +010049 return true;
pineafan63fc5e22022-08-04 22:04:10 +010050};
pineafan708692b2022-07-24 22:16:22 +010051
PineaFan538d3752023-01-12 21:48:23 +000052
pineafan708692b2022-07-24 22:16:22 +010053export { command };
54export { callback };
PineaFan5d98a4b2023-01-19 16:15:47 +000055export { check };