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 | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 22 | 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 | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame^] | 69 | i = (await interaction.channel!.awaitMessageComponent<ComponentType.Button | ComponentType.ChannelSelect>({ |
pineafan | 96228bd | 2023-02-21 14:22:55 +0000 | [diff] [blame] | 70 | filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 71 | time: 300000 |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame^] | 72 | })) |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 73 | } catch (e) { |
| 74 | closed = true; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 75 | continue; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 76 | } |
| 77 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 78 | if (i.isButton()) { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 79 | switch (i.customId) { |
| 80 | case "clear": { |
| 81 | channel = null; |
| 82 | break; |
| 83 | } |
| 84 | case "save": { |
| 85 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame^] | 86 | "logging.staff.channel": channel |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 87 | }); |
| 88 | data = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 89 | await client.memory.forceUpdate(interaction.guild!.id); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } else { |
| 94 | channel = i.values[0]!; |
| 95 | } |
| 96 | } while (!closed); |
| 97 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 98 | await interaction.deleteReply(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 99 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 100 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 101 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 102 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 103 | if (!member.permissions.has("ManageGuild")) |
| 104 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 105 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 106 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 107 | |
| 108 | export { command }; |
| 109 | export { callback }; |
| 110 | export { check }; |