blob: f2ec13ac30f36f097938ed173d5f3a4eceaafaf9 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf267563a2023-01-21 17:00:57 -05002import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, EmbedBuilder } from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -05003import { SlashCommandSubcommandBuilder, StringSelectMenuOptionBuilder } from "discord.js";
pineafan41d93562022-07-30 22:10:15 +01004import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +01005import client from "../../../utils/client.js";
pineafan41d93562022-07-30 22:10:15 +01006import { toHexArray, toHexInteger } from "../../../utils/calculate.js";
7
PineaFan638eb132023-01-19 10:41:22 +00008const logs: Record<string, string> = {
Skyler Grey75ea9172022-08-06 10:22:23 +01009 channelUpdate: "Channels created, deleted or modified",
10 emojiUpdate: "Server emojis modified",
11 stickerUpdate: "Server stickers modified",
12 guildUpdate: "Server settings updated",
13 guildMemberUpdate: "Member updated (i.e. nickname)",
14 guildMemberPunish: "Members punished (i.e. muted, banned, kicked)",
15 guildRoleUpdate: "Role settings changed",
16 guildInviteUpdate: "Server invite created or deleted",
17 messageUpdate: "Message edited",
18 messageDelete: "Message deleted",
19 messageDeleteBulk: "Messages purged",
20 messageReactionUpdate: "Message reactions cleared",
21 messageMassPing: "Message pings multiple members at once",
22 messageAnnounce: "Message published in announcement channel",
23 threadUpdate: "Thread created or deleted",
24 webhookUpdate: "Webhooks created or deleted",
25 guildMemberVerify: "Member runs verify",
26 autoModeratorDeleted: "Messages auto deleted by Nucleus",
27 nucleusSettingsUpdated: "Nucleus' settings updated by a moderator",
28 ticketUpdate: "Tickets created or deleted"
pineafan63fc5e22022-08-04 22:04:10 +010029};
pineafan4f164f32022-02-26 22:07:12 +000030
31const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010032 builder.setName("events").setDescription("Sets what events should be logged");
pineafan4f164f32022-02-26 22:07:12 +000033
TheCodedProf1f675042023-02-16 17:01:29 -050034const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Grey75ea9172022-08-06 10:22:23 +010035 await interaction.reply({
36 embeds: LoadingEmbed,
37 fetchReply: true,
38 ephemeral: true
39 });
Skyler Greyad002172022-08-16 18:48:26 +010040 let m: Message;
41 let timedOut = false;
42 do {
TheCodedProf327016b2023-01-18 21:48:00 -050043 const config = await client.database.guilds.read(interaction.guild!.id);
pineafan63fc5e22022-08-04 22:04:10 +010044 const converted = toHexArray(config.logging.logs.toLog);
PineaFan638eb132023-01-19 10:41:22 +000045 const selectPane = new StringSelectMenuBuilder()
46 .setPlaceholder("Set events to log")
47 .setMaxValues(Object.keys(logs).length)
48 .setCustomId("logs")
49 .setMinValues(0)
50 Object.keys(logs).map((e, i) => {
51 selectPane.addOptions(new StringSelectMenuOptionBuilder()
52 .setLabel(logs[e]!)
53 .setValue(i.toString())
54 .setDefault(converted.includes(e))
55 )
56 });
Skyler Greyad002172022-08-16 18:48:26 +010057 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010058 embeds: [
59 new EmojiEmbed()
60 .setTitle("Logging Events")
61 .setDescription(
62 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
63 )
64 .setStatus("Success")
65 .setEmoji("CHANNEL.TEXT.CREATE")
66 ],
67 components: [
PineaFan638eb132023-01-19 10:41:22 +000068 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectPane),
TheCodedProf327016b2023-01-18 21:48:00 -050069 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040070 new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"),
71 new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none")
Skyler Grey75ea9172022-08-06 10:22:23 +010072 ])
73 ]
Skyler Greyad002172022-08-16 18:48:26 +010074 })) as Message;
pineafan41d93562022-07-30 22:10:15 +010075 let i;
76 try {
PineaFan0d06edc2023-01-17 22:10:31 +000077 i = await m.awaitMessageComponent({
78 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -050079 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id }
PineaFan0d06edc2023-01-17 22:10:31 +000080 });
pineafan41d93562022-07-30 22:10:15 +010081 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +010082 timedOut = true;
83 continue;
pineafan41d93562022-07-30 22:10:15 +010084 }
TheCodedProf267563a2023-01-21 17:00:57 -050085 await i.deferUpdate();
TheCodedProf4a6d5712023-01-19 15:54:40 -050086 if (i.isStringSelectMenu() && i.customId === "logs") {
87 const selected = i.values;
TheCodedProf327016b2023-01-18 21:48:00 -050088 const newLogs = toHexInteger(selected.map((e: string) => Object.keys(logs)[parseInt(e)]!));
89 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey75ea9172022-08-06 10:22:23 +010090 "logging.logs.toLog": newLogs
91 });
pineafan41d93562022-07-30 22:10:15 +010092 } else if (i.customId === "all") {
Skyler Grey75ea9172022-08-06 10:22:23 +010093 const newLogs = toHexInteger(Object.keys(logs).map((e) => e));
TheCodedProf327016b2023-01-18 21:48:00 -050094 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey75ea9172022-08-06 10:22:23 +010095 "logging.logs.toLog": newLogs
96 });
pineafan41d93562022-07-30 22:10:15 +010097 } else if (i.customId === "none") {
TheCodedProf327016b2023-01-18 21:48:00 -050098 await client.database.guilds.write(interaction.guild!.id, {
Skyler Grey75ea9172022-08-06 10:22:23 +010099 "logging.logs.toLog": 0
100 });
pineafan41d93562022-07-30 22:10:15 +0100101 }
Skyler Greyad002172022-08-16 18:48:26 +0100102 } while (!timedOut);
103
TheCodedProf327016b2023-01-18 21:48:00 -0500104 await interaction.editReply({ embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message timed out" })] });
pineafanbd02b4a2022-08-05 22:01:38 +0100105 return;
pineafan63fc5e22022-08-04 22:04:10 +0100106};
pineafan4f164f32022-02-26 22:07:12 +0000107
TheCodedProff86ba092023-01-27 17:10:07 -0500108const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000110 if (!member.permissions.has("ManageGuild"))
111 return "You must have the *Manage Server* permission to use this command";
pineafan4f164f32022-02-26 22:07:12 +0000112 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100113};
pineafan4f164f32022-02-26 22:07:12 +0000114
115export { command };
116export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100117export { check };