blob: c3fbe410f5caba43d56aca3d840ad4011227a380 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
Skyler Grey11236ba2022-08-08 21:13:33 +01002import Discord, { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } 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 });
pineafan41d93562022-07-30 22:10:15 +010041 let m;
42 while (true) {
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 Grey75ea9172022-08-06 10:22:23 +010045 m = await interaction.editReply({
46 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: [
56 new MessageActionRow().addComponents([
57 new MessageSelectMenu()
58 .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 ]),
70 new MessageActionRow().addComponents([
Skyler Grey11236ba2022-08-08 21:13:33 +010071 new MessageButton().setLabel("Select all").setStyle("PRIMARY").setCustomId("all"),
72 new MessageButton().setLabel("Select none").setStyle("DANGER").setCustomId("none")
Skyler Grey75ea9172022-08-06 10:22:23 +010073 ])
74 ]
75 });
pineafan41d93562022-07-30 22:10:15 +010076 let i;
77 try {
78 i = await m.awaitMessageComponent({ time: 300000 });
79 } catch (e) {
pineafan63fc5e22022-08-04 22:04:10 +010080 break;
pineafan41d93562022-07-30 22:10:15 +010081 }
pineafan63fc5e22022-08-04 22:04:10 +010082 i.deferUpdate();
pineafan41d93562022-07-30 22:10:15 +010083 if (i.customId === "logs") {
pineafan63fc5e22022-08-04 22:04:10 +010084 const selected = i.values;
Skyler Grey11236ba2022-08-08 21:13:33 +010085 const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)]));
Skyler Grey75ea9172022-08-06 10:22:23 +010086 await client.database.guilds.write(interaction.guild.id, {
87 "logging.logs.toLog": newLogs
88 });
pineafan41d93562022-07-30 22:10:15 +010089 } else if (i.customId === "all") {
Skyler Grey75ea9172022-08-06 10:22:23 +010090 const newLogs = toHexInteger(Object.keys(logs).map((e) => e));
91 await client.database.guilds.write(interaction.guild.id, {
92 "logging.logs.toLog": newLogs
93 });
pineafan41d93562022-07-30 22:10:15 +010094 } else if (i.customId === "none") {
Skyler Grey75ea9172022-08-06 10:22:23 +010095 await client.database.guilds.write(interaction.guild.id, {
96 "logging.logs.toLog": 0
97 });
pineafan41d93562022-07-30 22:10:15 +010098 } else {
pineafan63fc5e22022-08-04 22:04:10 +010099 break;
pineafan41d93562022-07-30 22:10:15 +0100100 }
101 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 m = await interaction.editReply({
103 embeds: [
104 new EmojiEmbed()
105 .setTitle("Logging Events")
106 .setDescription(
107 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
108 )
109 .setFooter({ text: "Message timed out" })
110 .setStatus("Success")
111 .setEmoji("CHANNEL.TEXT.CREATE")
112 ]
113 });
pineafanbd02b4a2022-08-05 22:01:38 +0100114 return;
pineafan63fc5e22022-08-04 22:04:10 +0100115};
pineafan4f164f32022-02-26 22:07:12 +0000116
Skyler Grey11236ba2022-08-08 21:13:33 +0100117const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100118 const member = interaction.member as Discord.GuildMember;
119 if (!member.permissions.has("MANAGE_GUILD"))
pineafan3a02ea32022-08-11 21:35:04 +0100120 throw new Error("You must have the *Manage Server* permission to use this command");
pineafan4f164f32022-02-26 22:07:12 +0000121 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100122};
pineafan4f164f32022-02-26 22:07:12 +0000123
124export { command };
125export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100126export { check };