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