PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 2 | import Discord, { CommandInteraction, Message, ActionRowBuilder, GuildMember, StringSelectMenuBuilder, StringSelectMenuInteraction, SelectMenuOptionBuilder } from "discord.js"; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 4 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 5 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 6 | import client from "../../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | import convertCurlyBracketString from "../../utils/convertCurlyBracketString.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 8 | import { callback as statsChannelAddCallback } from "../../reflex/statsChannelUpdate.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | import singleNotify from "../../utils/singleNotify.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 10 | |
| 11 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 12 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | .setName("stats") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 14 | .setDescription("Controls channels which update when someone joins or leaves the server") |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 15 | |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 16 | const 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 | ]}) |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 30 | } |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 31 | let pageSelect = new StringSelectMenuBuilder() |
| 32 | .setCustomId("page") |
| 33 | .setPlaceholder("Select a stats channel to manage") |
pineafan | 0bc0416 | 2022-07-25 17:22:26 +0100 | [diff] [blame] | 34 | .setMinValues(1) |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 35 | .setMaxValues(1); |
| 36 | for (const [id, { name, enabled }] of Object.entries(stats)) { |
| 37 | pageSelect.addOption() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 38 | } |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 39 | // [ Action... ] -> Edit, delete, reorder |
| 40 | // [Back][Next][Add] |
| 41 | } while (!closed); |
| 42 | closed = true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 44 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 45 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 46 | const member = interaction.member as Discord.GuildMember; |
TheCodedProf | afca98b | 2023-01-17 22:25:43 -0500 | [diff] [blame] | 47 | if (!member.permissions.has("ManageChannels")) |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 48 | return "You must have the *Manage Channels* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 49 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 51 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 52 | |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 53 | export { command }; |
| 54 | export { callback }; |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 55 | export { check }; |