blob: ae04e891d937c0b4a4019e1185cfd6ab7373b63a [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf21c08592022-09-13 14:14:43 -04002import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00003import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
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
pineafan41d93562022-07-30 22:10:15 +01008const logs = {
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
pineafanbd02b4a2022-08-05 22:01:38 +010034const 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 {
pineafan63fc5e22022-08-04 22:04:10 +010043 const config = await client.database.guilds.read(interaction.guild.id);
44 const converted = toHexArray(config.logging.logs.toLog);
Skyler Greyad002172022-08-16 18:48:26 +010045 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010046 embeds: [
47 new EmojiEmbed()
48 .setTitle("Logging Events")
49 .setDescription(
50 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
51 )
52 .setStatus("Success")
53 .setEmoji("CHANNEL.TEXT.CREATE")
54 ],
55 components: [
TheCodedProf21c08592022-09-13 14:14:43 -040056 new ActionRowBuilder().addComponents([
57 new SelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010058 .setPlaceholder("Set events to log")
59 .setMaxValues(Object.keys(logs).length)
60 .setCustomId("logs")
61 .setMinValues(0)
62 .setOptions(
63 Object.keys(logs).map((e, i) => ({
64 label: logs[e],
65 value: i.toString(),
66 default: converted.includes(e)
67 }))
68 )
69 ]),
TheCodedProf21c08592022-09-13 14:14:43 -040070 new ActionRowBuilder().addComponents([
71 new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"),
72 new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none")
Skyler Grey75ea9172022-08-06 10:22:23 +010073 ])
74 ]
Skyler Greyad002172022-08-16 18:48:26 +010075 })) as Message;
pineafan41d93562022-07-30 22:10:15 +010076 let i;
77 try {
PineaFan0d06edc2023-01-17 22:10:31 +000078 i = await m.awaitMessageComponent({
79 time: 300000,
80 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
81 });
pineafan41d93562022-07-30 22:10:15 +010082 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +010083 timedOut = true;
84 continue;
pineafan41d93562022-07-30 22:10:15 +010085 }
pineafan63fc5e22022-08-04 22:04:10 +010086 i.deferUpdate();
pineafan41d93562022-07-30 22:10:15 +010087 if (i.customId === "logs") {
pineafan63fc5e22022-08-04 22:04:10 +010088 const selected = i.values;
Skyler Grey11236ba2022-08-08 21:13:33 +010089 const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)]));
Skyler Grey75ea9172022-08-06 10:22:23 +010090 await client.database.guilds.write(interaction.guild.id, {
91 "logging.logs.toLog": newLogs
92 });
pineafan41d93562022-07-30 22:10:15 +010093 } else if (i.customId === "all") {
Skyler Grey75ea9172022-08-06 10:22:23 +010094 const newLogs = toHexInteger(Object.keys(logs).map((e) => e));
95 await client.database.guilds.write(interaction.guild.id, {
96 "logging.logs.toLog": newLogs
97 });
pineafan41d93562022-07-30 22:10:15 +010098 } else if (i.customId === "none") {
Skyler Grey75ea9172022-08-06 10:22:23 +010099 await client.database.guilds.write(interaction.guild.id, {
100 "logging.logs.toLog": 0
101 });
pineafan41d93562022-07-30 22:10:15 +0100102 }
Skyler Greyad002172022-08-16 18:48:26 +0100103 } while (!timedOut);
104
105 await interaction.editReply({ embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })] });
pineafanbd02b4a2022-08-05 22:01:38 +0100106 return;
pineafan63fc5e22022-08-04 22:04:10 +0100107};
pineafan4f164f32022-02-26 22:07:12 +0000108
PineaFan64486c42022-12-28 09:21:04 +0000109const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100110 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000111 if (!member.permissions.has("ManageGuild"))
112 return "You must have the *Manage Server* permission to use this command";
pineafan4f164f32022-02-26 22:07:12 +0000113 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100114};
pineafan4f164f32022-02-26 22:07:12 +0000115
116export { command };
117export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100118export { check };