blob: 4d9a3fafbc51aead27e19d1c62bf3026f86f92a9 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf94ff6de2023-02-22 17:47:26 -05002import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelSelectMenuBuilder, ChannelType } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +01003import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan708692b2022-07-24 22:16:22 +01004import getEmojiByName from "../../../utils/getEmojiByName.js";
TheCodedProff86ba092023-01-27 17:10:07 -05005import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +01006import client from "../../../utils/client.js";
7
8const command = (builder: SlashCommandSubcommandBuilder) =>
9 builder
PineaFand471ccd2023-01-26 20:48:40 +000010 .setName("warnings")
pineafan63fc5e22022-08-04 22:04:10 +010011 .setDescription("Settings for the staff notifications channel")
pineafan708692b2022-07-24 22:16:22 +010012
pineafan3a02ea32022-08-11 21:35:04 +010013const callback = async (interaction: CommandInteraction): Promise<unknown> => {
pineafan63fc5e22022-08-04 22:04:10 +010014 if (!interaction.guild) return;
TheCodedProf01cba762023-02-18 15:55:05 -050015 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010016 embeds: LoadingEmbed,
17 ephemeral: true,
18 fetchReply: true
TheCodedProf01cba762023-02-18 15:55:05 -050019 })
20
21 let data = await client.database.guilds.read(interaction.guild.id);
pineafan708692b2022-07-24 22:16:22 +010022 let channel = data.logging.staff.channel;
TheCodedProf01cba762023-02-18 15:55:05 -050023 let closed = false;
24 do {
25 const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>()
26 .addComponents(
27 new ChannelSelectMenuBuilder()
28 .setCustomId("channel")
29 .setPlaceholder("Select a channel")
TheCodedProf94ff6de2023-02-22 17:47:26 -050030 .setChannelTypes(ChannelType.GuildText)
TheCodedProf01cba762023-02-18 15:55:05 -050031 );
32 const buttons = new ActionRowBuilder<ButtonBuilder>()
33 .addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -040034 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010035 .setCustomId("clear")
36 .setLabel("Clear")
TheCodedProf01cba762023-02-18 15:55:05 -050037 .setStyle(ButtonStyle.Danger)
38 .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji)
39 .setDisabled(!channel),
40 new ButtonBuilder()
41 .setCustomId("save")
42 .setLabel("Save")
43 .setStyle(ButtonStyle.Success)
44 .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji)
45 .setDisabled(channel === data.logging.staff.channel)
46 );
47
48 const embed = new EmojiEmbed()
49 .setTitle("Staff Notifications Channel")
50 .setStatus("Success")
51 .setEmoji("CHANNEL.TEXT.CREATE")
52 .setDescription(
53 `Logs which require an action from a moderator or administrator will be sent to this channel.\n` +
54 `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n`
55 )
56
57 await interaction.editReply({
58 embeds: [embed],
59 components: [channelMenu, buttons]
60 });
61
62 let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction;
63 try {
64 i = (await interaction.channel!.awaitMessageComponent({
pineafan96228bd2023-02-21 14:22:55 +000065 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050066 time: 300000
67 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
68 } catch (e) {
69 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050070 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050071 }
72 await i.deferUpdate();
73 if(i.isButton()) {
74 switch (i.customId) {
75 case "clear": {
76 channel = null;
77 break;
78 }
79 case "save": {
80 await client.database.guilds.write(interaction.guild!.id, {
81 "logging.warnings.channel": channel
82 });
83 data = await client.database.guilds.read(interaction.guild!.id);
Skyler Grey16ecb172023-03-05 07:30:32 +000084 await client.memory.forceUpdate(interaction.guild!.id);
TheCodedProf01cba762023-02-18 15:55:05 -050085 break;
86 }
87 }
88 } else {
89 channel = i.values[0]!;
90 }
91 } while (!closed);
92
93 await interaction.deleteReply()
pineafan63fc5e22022-08-04 22:04:10 +010094};
pineafan708692b2022-07-24 22:16:22 +010095
TheCodedProff86ba092023-01-27 17:10:07 -050096const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +010097 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +000098 if (!member.permissions.has("ManageGuild"))
99 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100100 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100101};
pineafan708692b2022-07-24 22:16:22 +0100102
103export { command };
104export { callback };
105export { check };