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