PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../../utils/defaults.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | ActionRowBuilder, |
| 5 | ButtonBuilder, |
| 6 | ButtonStyle, |
| 7 | ChannelSelectMenuBuilder, |
| 8 | ChannelType |
| 9 | } from "discord.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 10 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 11 | import getEmojiByName from "../../../utils/getEmojiByName.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 12 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 13 | import client from "../../../utils/client.js"; |
| 14 | |
| 15 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 16 | builder.setName("warnings").setDescription("Settings for the staff notifications channel"); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 17 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 18 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 19 | if (!interaction.guild) return; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 20 | await interaction.reply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | embeds: LoadingEmbed, |
| 22 | ephemeral: true, |
| 23 | fetchReply: true |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 24 | }); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 25 | |
| 26 | let data = await client.database.guilds.read(interaction.guild.id); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 27 | let channel = data.logging.staff.channel; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 28 | let closed = false; |
| 29 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 30 | const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 31 | new ChannelSelectMenuBuilder() |
| 32 | .setCustomId("channel") |
| 33 | .setPlaceholder("Select a channel") |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 34 | .setChannelTypes(ChannelType.GuildText) |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 35 | ); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 36 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 37 | new ButtonBuilder() |
| 38 | .setCustomId("clear") |
| 39 | .setLabel("Clear") |
| 40 | .setStyle(ButtonStyle.Danger) |
| 41 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji) |
| 42 | .setDisabled(!channel), |
| 43 | new ButtonBuilder() |
| 44 | .setCustomId("save") |
| 45 | .setLabel("Save") |
| 46 | .setStyle(ButtonStyle.Success) |
| 47 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji) |
| 48 | .setDisabled(channel === data.logging.staff.channel) |
| 49 | ); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 50 | |
| 51 | const embed = new EmojiEmbed() |
| 52 | .setTitle("Staff Notifications Channel") |
| 53 | .setStatus("Success") |
| 54 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 55 | .setDescription( |
| 56 | `Logs which require an action from a moderator or administrator will be sent to this channel.\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 57 | `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n` |
| 58 | ); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 59 | |
| 60 | await interaction.editReply({ |
| 61 | embeds: [embed], |
| 62 | components: [channelMenu, buttons] |
| 63 | }); |
| 64 | |
| 65 | let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction; |
| 66 | try { |
| 67 | i = (await interaction.channel!.awaitMessageComponent({ |
pineafan | 96228bd | 2023-02-21 14:22:55 +0000 | [diff] [blame] | 68 | filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 69 | time: 300000 |
| 70 | })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction; |
| 71 | } catch (e) { |
| 72 | closed = true; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 73 | continue; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 74 | } |
| 75 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 76 | if (i.isButton()) { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 77 | switch (i.customId) { |
| 78 | case "clear": { |
| 79 | channel = null; |
| 80 | break; |
| 81 | } |
| 82 | case "save": { |
| 83 | await client.database.guilds.write(interaction.guild!.id, { |
| 84 | "logging.warnings.channel": channel |
| 85 | }); |
| 86 | data = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 87 | await client.memory.forceUpdate(interaction.guild!.id); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 88 | break; |
| 89 | } |
| 90 | } |
| 91 | } else { |
| 92 | channel = i.values[0]!; |
| 93 | } |
| 94 | } while (!closed); |
| 95 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 96 | await interaction.deleteReply(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 97 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 98 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 99 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 101 | if (!member.permissions.has("ManageGuild")) |
| 102 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 103 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 104 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 105 | |
| 106 | export { command }; |
| 107 | export { callback }; |
| 108 | export { check }; |