blob: 793d1fac5a8cf6085b9bacd36124023d92277661 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../../../utils/defaultEmbeds.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";
4import { WrappedCheck } from "jshaiku";
pineafan41d93562022-07-30 22:10:15 +01005import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +01006import client from "../../../utils/client.js";
pineafan41d93562022-07-30 22:10:15 +01007import { toHexArray, toHexInteger } from "../../../utils/calculate.js";
8
pineafan41d93562022-07-30 22:10:15 +01009const logs = {
Skyler Grey75ea9172022-08-06 10:22:23 +010010 channelUpdate: "Channels created, deleted or modified",
11 emojiUpdate: "Server emojis modified",
12 stickerUpdate: "Server stickers modified",
13 guildUpdate: "Server settings updated",
14 guildMemberUpdate: "Member updated (i.e. nickname)",
15 guildMemberPunish: "Members punished (i.e. muted, banned, kicked)",
16 guildRoleUpdate: "Role settings changed",
17 guildInviteUpdate: "Server invite created or deleted",
18 messageUpdate: "Message edited",
19 messageDelete: "Message deleted",
20 messageDeleteBulk: "Messages purged",
21 messageReactionUpdate: "Message reactions cleared",
22 messageMassPing: "Message pings multiple members at once",
23 messageAnnounce: "Message published in announcement channel",
24 threadUpdate: "Thread created or deleted",
25 webhookUpdate: "Webhooks created or deleted",
26 guildMemberVerify: "Member runs verify",
27 autoModeratorDeleted: "Messages auto deleted by Nucleus",
28 nucleusSettingsUpdated: "Nucleus' settings updated by a moderator",
29 ticketUpdate: "Tickets created or deleted"
pineafan63fc5e22022-08-04 22:04:10 +010030};
pineafan4f164f32022-02-26 22:07:12 +000031
32const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010033 builder.setName("events").setDescription("Sets what events should be logged");
pineafan4f164f32022-02-26 22:07:12 +000034
pineafanbd02b4a2022-08-05 22:01:38 +010035const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Grey75ea9172022-08-06 10:22:23 +010036 await interaction.reply({
37 embeds: LoadingEmbed,
38 fetchReply: true,
39 ephemeral: true
40 });
Skyler Greyad002172022-08-16 18:48:26 +010041 let m: Message;
42 let timedOut = false;
43 do {
pineafan63fc5e22022-08-04 22:04:10 +010044 const config = await client.database.guilds.read(interaction.guild.id);
45 const converted = toHexArray(config.logging.logs.toLog);
Skyler Greyad002172022-08-16 18:48:26 +010046 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010047 embeds: [
48 new EmojiEmbed()
49 .setTitle("Logging Events")
50 .setDescription(
51 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
52 )
53 .setStatus("Success")
54 .setEmoji("CHANNEL.TEXT.CREATE")
55 ],
56 components: [
TheCodedProf21c08592022-09-13 14:14:43 -040057 new ActionRowBuilder().addComponents([
58 new SelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010059 .setPlaceholder("Set events to log")
60 .setMaxValues(Object.keys(logs).length)
61 .setCustomId("logs")
62 .setMinValues(0)
63 .setOptions(
64 Object.keys(logs).map((e, i) => ({
65 label: logs[e],
66 value: i.toString(),
67 default: converted.includes(e)
68 }))
69 )
70 ]),
TheCodedProf21c08592022-09-13 14:14:43 -040071 new ActionRowBuilder().addComponents([
72 new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"),
73 new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none")
Skyler Grey75ea9172022-08-06 10:22:23 +010074 ])
75 ]
Skyler Greyad002172022-08-16 18:48:26 +010076 })) as Message;
pineafan41d93562022-07-30 22:10:15 +010077 let i;
78 try {
79 i = await m.awaitMessageComponent({ time: 300000 });
80 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +010081 timedOut = true;
82 continue;
pineafan41d93562022-07-30 22:10:15 +010083 }
pineafan63fc5e22022-08-04 22:04:10 +010084 i.deferUpdate();
pineafan41d93562022-07-30 22:10:15 +010085 if (i.customId === "logs") {
pineafan63fc5e22022-08-04 22:04:10 +010086 const selected = i.values;
Skyler Grey11236ba2022-08-08 21:13:33 +010087 const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)]));
Skyler Grey75ea9172022-08-06 10:22:23 +010088 await client.database.guilds.write(interaction.guild.id, {
89 "logging.logs.toLog": newLogs
90 });
pineafan41d93562022-07-30 22:10:15 +010091 } else if (i.customId === "all") {
Skyler Grey75ea9172022-08-06 10:22:23 +010092 const newLogs = toHexInteger(Object.keys(logs).map((e) => e));
93 await client.database.guilds.write(interaction.guild.id, {
94 "logging.logs.toLog": newLogs
95 });
pineafan41d93562022-07-30 22:10:15 +010096 } else if (i.customId === "none") {
Skyler Grey75ea9172022-08-06 10:22:23 +010097 await client.database.guilds.write(interaction.guild.id, {
98 "logging.logs.toLog": 0
99 });
pineafan41d93562022-07-30 22:10:15 +0100100 }
Skyler Greyad002172022-08-16 18:48:26 +0100101 } while (!timedOut);
102
103 await interaction.editReply({ embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })] });
pineafanbd02b4a2022-08-05 22:01:38 +0100104 return;
pineafan63fc5e22022-08-04 22:04:10 +0100105};
pineafan4f164f32022-02-26 22:07:12 +0000106
Skyler Grey11236ba2022-08-08 21:13:33 +0100107const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100108 const member = interaction.member as Discord.GuildMember;
109 if (!member.permissions.has("MANAGE_GUILD"))
pineafan3a02ea32022-08-11 21:35:04 +0100110 throw new Error("You must have the *Manage Server* permission to use this command");
pineafan4f164f32022-02-26 22:07:12 +0000111 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100112};
pineafan4f164f32022-02-26 22:07:12 +0000113
114export { command };
115export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100116export { check };