blob: a988faeec669072c93889fbe0d8c8449fb8b8120 [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,
Skyler Grey0d885222023-03-08 21:46:37 +00008 ChannelType,
9 ComponentType
Skyler Greyda16adf2023-03-05 10:22:12 +000010} from "discord.js";
pineafan708692b2022-07-24 22:16:22 +010011import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan708692b2022-07-24 22:16:22 +010012import getEmojiByName from "../../../utils/getEmojiByName.js";
TheCodedProff86ba092023-01-27 17:10:07 -050013import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +010014import client from "../../../utils/client.js";
Skyler Grey0d885222023-03-08 21:46:37 +000015import _ from "lodash";
pineafan708692b2022-07-24 22:16:22 +010016
17const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Greyda16adf2023-03-05 10:22:12 +000018 builder.setName("warnings").setDescription("Settings for the staff notifications channel");
pineafan708692b2022-07-24 22:16:22 +010019
pineafan3a02ea32022-08-11 21:35:04 +010020const callback = async (interaction: CommandInteraction): Promise<unknown> => {
pineafan63fc5e22022-08-04 22:04:10 +010021 if (!interaction.guild) return;
TheCodedProf01cba762023-02-18 15:55:05 -050022 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010023 embeds: LoadingEmbed,
24 ephemeral: true,
25 fetchReply: true
Skyler Greyda16adf2023-03-05 10:22:12 +000026 });
TheCodedProf01cba762023-02-18 15:55:05 -050027
28 let data = await client.database.guilds.read(interaction.guild.id);
Skyler Grey0d885222023-03-08 21:46:37 +000029 let channel = _.clone(data.logging.staff.channel);
TheCodedProf01cba762023-02-18 15:55:05 -050030 let closed = false;
31 do {
Skyler Greyda16adf2023-03-05 10:22:12 +000032 const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(
TheCodedProf01cba762023-02-18 15:55:05 -050033 new ChannelSelectMenuBuilder()
34 .setCustomId("channel")
35 .setPlaceholder("Select a channel")
TheCodedProf94ff6de2023-02-22 17:47:26 -050036 .setChannelTypes(ChannelType.GuildText)
TheCodedProf01cba762023-02-18 15:55:05 -050037 );
Skyler Greyda16adf2023-03-05 10:22:12 +000038 const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
39 new ButtonBuilder()
40 .setCustomId("clear")
41 .setLabel("Clear")
42 .setStyle(ButtonStyle.Danger)
43 .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji)
44 .setDisabled(!channel),
45 new ButtonBuilder()
46 .setCustomId("save")
47 .setLabel("Save")
48 .setStyle(ButtonStyle.Success)
49 .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji)
Skyler Grey0d885222023-03-08 21:46:37 +000050 .setDisabled(_.isEqual(channel, data.logging.staff.channel))
Skyler Greyda16adf2023-03-05 10:22:12 +000051 );
TheCodedProf01cba762023-02-18 15:55:05 -050052
53 const embed = new EmojiEmbed()
54 .setTitle("Staff Notifications Channel")
55 .setStatus("Success")
56 .setEmoji("CHANNEL.TEXT.CREATE")
57 .setDescription(
58 `Logs which require an action from a moderator or administrator will be sent to this channel.\n` +
Skyler Greyda16adf2023-03-05 10:22:12 +000059 `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n`
60 );
TheCodedProf01cba762023-02-18 15:55:05 -050061
62 await interaction.editReply({
63 embeds: [embed],
64 components: [channelMenu, buttons]
65 });
66
Skyler Grey0d885222023-03-08 21:46:37 +000067 let i: Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction;
TheCodedProf01cba762023-02-18 15:55:05 -050068 try {
Skyler Grey0d885222023-03-08 21:46:37 +000069 i = (await interaction.channel!.awaitMessageComponent<ComponentType.Button | ComponentType.ChannelSelect>({
pineafan96228bd2023-02-21 14:22:55 +000070 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050071 time: 300000
Skyler Grey0d885222023-03-08 21:46:37 +000072 }))
TheCodedProf01cba762023-02-18 15:55:05 -050073 } catch (e) {
74 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050075 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050076 }
77 await i.deferUpdate();
Skyler Greyda16adf2023-03-05 10:22:12 +000078 if (i.isButton()) {
TheCodedProf01cba762023-02-18 15:55:05 -050079 switch (i.customId) {
80 case "clear": {
81 channel = null;
82 break;
83 }
84 case "save": {
85 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey0d885222023-03-08 21:46:37 +000086 "logging.staff.channel": channel
TheCodedProf01cba762023-02-18 15:55:05 -050087 });
88 data = await client.database.guilds.read(interaction.guild!.id);
Skyler Grey16ecb172023-03-05 07:30:32 +000089 await client.memory.forceUpdate(interaction.guild!.id);
TheCodedProf01cba762023-02-18 15:55:05 -050090 break;
91 }
92 }
93 } else {
94 channel = i.values[0]!;
95 }
96 } while (!closed);
97
Skyler Greyda16adf2023-03-05 10:22:12 +000098 await interaction.deleteReply();
pineafan63fc5e22022-08-04 22:04:10 +010099};
pineafan708692b2022-07-24 22:16:22 +0100100
TheCodedProff86ba092023-01-27 17:10:07 -0500101const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000103 if (!member.permissions.has("ManageGuild"))
104 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100105 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100106};
pineafan708692b2022-07-24 22:16:22 +0100107
108export { command };
109export { callback };
110export { check };