PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../../utils/defaults.js"; |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 2 | import { ChannelType } from "discord-api-types/v9"; |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 3 | import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonComponent } from "discord.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
| 5 | import confirmationMessage from "../../../utils/confirmationMessage.js"; |
| 6 | import getEmojiByName from "../../../utils/getEmojiByName.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 8 | import client from "../../../utils/client.js"; |
| 9 | |
| 10 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 11 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | .setName("staff") |
| 13 | .setDescription("Settings for the staff notifications channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 14 | .addChannelOption((option) => |
| 15 | option |
| 16 | .setName("channel") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 17 | .setDescription("The channel to set the staff notifications channel to") |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 18 | .addChannelTypes(ChannelType.GuildText) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 19 | .setRequired(false) |
| 20 | ); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 21 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 22 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 23 | if (!interaction.guild) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 24 | const m = (await interaction.reply({ |
| 25 | embeds: LoadingEmbed, |
| 26 | ephemeral: true, |
| 27 | fetchReply: true |
| 28 | })) as Discord.Message; |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 29 | if (interaction.options.get("channel")?.channel) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | let channel; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 31 | try { |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 32 | channel = interaction.options.get("channel")?.channel; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 33 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | return await interaction.editReply({ |
| 35 | embeds: [ |
| 36 | new EmojiEmbed() |
| 37 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 38 | .setTitle("Staff Notifications Channel") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 39 | .setDescription("The channel you provided is not a valid channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 40 | .setStatus("Danger") |
| 41 | ] |
| 42 | }); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 43 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | channel = channel as Discord.TextChannel; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 45 | if (channel.guild.id !== interaction.guild.id) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 46 | return interaction.editReply({ |
| 47 | embeds: [ |
| 48 | new EmojiEmbed() |
| 49 | .setTitle("Staff Notifications Channel") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 50 | .setDescription("You must choose a channel in this server") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 51 | .setStatus("Danger") |
| 52 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 53 | ] |
| 54 | }); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 55 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 56 | const confirmation = await new confirmationMessage(interaction) |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 57 | .setEmoji("CHANNEL.TEXT.EDIT") |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 58 | .setTitle("Staff Notifications Channel") |
| 59 | .setDescription( |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 60 | "This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 61 | `Are you sure you want to set the staff notifications channel to <#${channel.id}>?` |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 62 | ) |
| 63 | .setColor("Warning") |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame] | 64 | .setFailedMessage("No changes were made", "Success", "CHANNEL.TEXT.CREATE") |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 65 | .setInverted(true) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 66 | .send(true); |
| 67 | if (confirmation.cancelled) return; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 68 | if (confirmation.success) { |
| 69 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 70 | await client.database.guilds.write(interaction.guild.id, { |
| 71 | "logging.staff.channel": channel.id |
| 72 | }); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 73 | const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 74 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 75 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 76 | type: "staffChannelUpdate", |
| 77 | displayName: "Staff Notifications Channel Updated", |
| 78 | calculateType: "nucleusSettingsUpdated", |
| 79 | color: NucleusColors.yellow, |
| 80 | emoji: "CHANNEL.TEXT.EDIT", |
| 81 | timestamp: new Date().getTime() |
| 82 | }, |
| 83 | list: { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 84 | memberId: entry(interaction.user.id, `\`${interaction.user.id}\``), |
| 85 | changedBy: entry(interaction.user.id, renderUser(interaction.user)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 86 | channel: entry(channel.id, renderChannel(channel)) |
| 87 | }, |
| 88 | hidden: { |
| 89 | guild: interaction.guild.id |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 90 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 91 | }; |
| 92 | log(data); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 93 | } catch (e) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 94 | return interaction.editReply({ |
| 95 | embeds: [ |
| 96 | new EmojiEmbed() |
| 97 | .setTitle("Staff Notifications Channel") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 98 | .setDescription("Something went wrong and the staff notifications channel could not be set") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 99 | .setStatus("Danger") |
| 100 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 101 | ], |
| 102 | components: [] |
| 103 | }); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 104 | } |
| 105 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 106 | return interaction.editReply({ |
| 107 | embeds: [ |
| 108 | new EmojiEmbed() |
| 109 | .setTitle("Staff Notifications Channel") |
| 110 | .setDescription("No changes were made") |
| 111 | .setStatus("Success") |
| 112 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 113 | ], |
| 114 | components: [] |
| 115 | }); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | let clicks = 0; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 119 | const data = await client.database.guilds.read(interaction.guild.id); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 120 | let channel = data.logging.staff.channel; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 121 | let timedOut = false; |
| 122 | while (!timedOut) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | await interaction.editReply({ |
| 124 | embeds: [ |
| 125 | new EmojiEmbed() |
| 126 | .setTitle("Staff Notifications channel") |
| 127 | .setDescription( |
| 128 | channel |
| 129 | ? `Your staff notifications channel is currently set to <#${channel}>` |
| 130 | : "This server does not have a staff notifications channel" |
| 131 | ) |
| 132 | .setStatus("Success") |
| 133 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 134 | ], |
| 135 | components: [ |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 136 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 137 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 138 | .setCustomId("clear") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 139 | .setLabel(clicks ? "Click again to confirm" : "Reset channel") |
| 140 | .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 141 | .setStyle(ButtonStyle.Danger) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 142 | .setDisabled(!channel) |
| 143 | ]) |
| 144 | ] |
| 145 | }); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 146 | let i; |
| 147 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 148 | i = await m.awaitMessageComponent({ |
| 149 | time: 300000, |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame^] | 150 | filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id } |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 151 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 152 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 153 | timedOut = true; |
| 154 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 155 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame^] | 156 | await i.deferUpdate(); |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 157 | if ((i.component as ButtonComponent).customId === "clear") { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 158 | clicks ++; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 159 | if (clicks === 2) { |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 160 | clicks = 0; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 161 | await client.database.guilds.write(interaction.guild.id, null, ["logging.staff.channel"]); |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 162 | channel = null; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 163 | } |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 166 | await interaction.editReply({ |
| 167 | embeds: [ |
| 168 | new EmojiEmbed() |
| 169 | .setTitle("Staff Notifications channel") |
| 170 | .setDescription( |
| 171 | channel |
| 172 | ? `Your staff notifications channel is currently set to <#${channel}>` |
| 173 | : "This server does not have a staff notifications channel" |
| 174 | ) |
| 175 | .setStatus("Success") |
| 176 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 177 | .setFooter({ text: "Message closed" }) |
| 178 | ], |
| 179 | components: [ |
TheCodedProf | 327016b | 2023-01-18 21:48:00 -0500 | [diff] [blame] | 180 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 181 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 182 | .setCustomId("clear") |
| 183 | .setLabel("Clear") |
| 184 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 185 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 186 | .setDisabled(true) |
| 187 | ]) |
| 188 | ] |
| 189 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 190 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 191 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 192 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 193 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 194 | if (!member.permissions.has("ManageGuild")) |
| 195 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 196 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 197 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 198 | |
| 199 | export { command }; |
| 200 | export { callback }; |
| 201 | export { check }; |