blob: 38b645a2b98d7982ed03fcc018f3fdcb6ad59042 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00002import Discord, {
3 CommandInteraction,
4 ActionRowBuilder,
5 ButtonBuilder,
6 ButtonStyle,
7 ChannelSelectMenuBuilder,
8 ChannelType
9} from "discord.js";
pineafan708692b2022-07-24 22:16:22 +010010import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan708692b2022-07-24 22:16:22 +010011import getEmojiByName from "../../../utils/getEmojiByName.js";
TheCodedProff86ba092023-01-27 17:10:07 -050012import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +010013import client from "../../../utils/client.js";
14
15const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Greyda16adf2023-03-05 10:22:12 +000016 builder.setName("warnings").setDescription("Settings for the staff notifications channel");
pineafan708692b2022-07-24 22:16:22 +010017
pineafan3a02ea32022-08-11 21:35:04 +010018const callback = async (interaction: CommandInteraction): Promise<unknown> => {
pineafan63fc5e22022-08-04 22:04:10 +010019 if (!interaction.guild) return;
TheCodedProf01cba762023-02-18 15:55:05 -050020 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010021 embeds: LoadingEmbed,
22 ephemeral: true,
23 fetchReply: true
Skyler Greyda16adf2023-03-05 10:22:12 +000024 });
TheCodedProf01cba762023-02-18 15:55:05 -050025
26 let data = await client.database.guilds.read(interaction.guild.id);
pineafan708692b2022-07-24 22:16:22 +010027 let channel = data.logging.staff.channel;
TheCodedProf01cba762023-02-18 15:55:05 -050028 let closed = false;
29 do {
Skyler Greyda16adf2023-03-05 10:22:12 +000030 const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(
TheCodedProf01cba762023-02-18 15:55:05 -050031 new ChannelSelectMenuBuilder()
32 .setCustomId("channel")
33 .setPlaceholder("Select a channel")
TheCodedProf94ff6de2023-02-22 17:47:26 -050034 .setChannelTypes(ChannelType.GuildText)
TheCodedProf01cba762023-02-18 15:55:05 -050035 );
Skyler Greyda16adf2023-03-05 10:22:12 +000036 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 );
TheCodedProf01cba762023-02-18 15:55:05 -050050
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 Greyda16adf2023-03-05 10:22:12 +000057 `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n`
58 );
TheCodedProf01cba762023-02-18 15:55:05 -050059
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({
pineafan96228bd2023-02-21 14:22:55 +000068 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050069 time: 300000
70 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
71 } catch (e) {
72 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050073 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050074 }
75 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +000076 if (i.isButton()) {
TheCodedProf01cba762023-02-18 15:55:05 -050077 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 Grey16ecb172023-03-05 07:30:32 +000087 await client.memory.forceUpdate(interaction.guild!.id);
TheCodedProf01cba762023-02-18 15:55:05 -050088 break;
89 }
90 }
91 } else {
92 channel = i.values[0]!;
93 }
94 } while (!closed);
95
Skyler Greyda16adf2023-03-05 10:22:12 +000096 await interaction.deleteReply();
pineafan63fc5e22022-08-04 22:04:10 +010097};
pineafan708692b2022-07-24 22:16:22 +010098
TheCodedProff86ba092023-01-27 17:10:07 -050099const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000101 if (!member.permissions.has("ManageGuild"))
102 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100103 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100104};
pineafan708692b2022-07-24 22:16:22 +0100105
106export { command };
107export { callback };
108export { check };