blob: 24249a2e945224e2ca9bf083115d7de76d39bae6 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf01cba762023-02-18 15:55:05 -05002import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelSelectMenuBuilder } 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")
30 );
31 const buttons = new ActionRowBuilder<ButtonBuilder>()
32 .addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -040033 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010034 .setCustomId("clear")
35 .setLabel("Clear")
TheCodedProf01cba762023-02-18 15:55:05 -050036 .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({
pineafan96228bd2023-02-21 14:22:55 +000064 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050065 time: 300000
66 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
67 } catch (e) {
68 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050069 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050070 }
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()
pineafan63fc5e22022-08-04 22:04:10 +010092};
pineafan708692b2022-07-24 22:16:22 +010093
TheCodedProff86ba092023-01-27 17:10:07 -050094const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +010095 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +000096 if (!member.permissions.has("ManageGuild"))
97 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +010098 return true;
pineafan63fc5e22022-08-04 22:04:10 +010099};
pineafan708692b2022-07-24 22:16:22 +0100100
101export { command };
102export { callback };
103export { check };