blob: 110c70e26927b7f349e5659cfd8b7220ad2dd032 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
pineafan41d93562022-07-30 22:10:15 +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
9
10const logs = {
11 "channelUpdate": "Channels created, deleted or modified",
12 "emojiUpdate": "Server emojis modified",
13 "stickerUpdate": "Server stickers modified",
14 "guildUpdate": "Server settings updated",
15 "guildMemberUpdate": "Member updated (i.e. nickname)",
16 "guildMemberPunish": "Members punished (i.e. muted, banned, kicked)",
17 "guildRoleUpdate": "Role settings changed",
18 "guildInviteUpdate": "Server invite created or deleted",
19 "messageUpdate": "Message edited",
20 "messageDelete": "Message deleted",
21 "messageDeleteBulk": "Messages purged",
22 "messageReactionUpdate": "Message reactions cleared",
23 "messageMassPing": "Message pings multiple members at once",
24 "messageAnnounce": "Message published in announcement channel",
25 "threadUpdate": "Thread created or deleted",
26 "webhookUpdate": "Webhooks created or deleted",
27 "guildMemberVerify": "Member runs verify",
28 "autoModeratorDeleted": "Messages auto deleted by Nucleus",
29 "nucleusSettingsUpdated": "Nucleus' settings updated by a moderator",
pineafan63fc5e22022-08-04 22:04:10 +010030 "ticketUpdate": "Tickets created or deleted"
31};
pineafan4f164f32022-02-26 22:07:12 +000032
33const command = (builder: SlashCommandSubcommandBuilder) =>
34 builder
pineafan63fc5e22022-08-04 22:04:10 +010035 .setName("events")
36 .setDescription("Sets what events should be logged");
pineafan4f164f32022-02-26 22:07:12 +000037
pineafanbd02b4a2022-08-05 22:01:38 +010038const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan41d93562022-07-30 22:10:15 +010039 await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true});
40 let m;
41 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +010042 const config = await client.database.guilds.read(interaction.guild.id);
43 const converted = toHexArray(config.logging.logs.toLog);
pineafan41d93562022-07-30 22:10:15 +010044 m = await interaction.editReply({embeds: [new EmojiEmbed()
45 .setTitle("Logging Events")
46 .setDescription("Below are the events being logged in the server. You can toggle them on and off in the dropdown")
47 .setStatus("Success")
48 .setEmoji("CHANNEL.TEXT.CREATE")
49 ], components: [
50 new MessageActionRow().addComponents([new MessageSelectMenu()
51 .setPlaceholder("Set events to log")
52 .setMaxValues(Object.keys(logs).length)
53 .setCustomId("logs")
54 .setMinValues(0)
55 .setOptions(Object.keys(logs).map((e, i) => ({
56 label: logs[e],
57 value: i.toString(),
58 default: converted.includes(e)
59 })))
60 ]),
61 new MessageActionRow().addComponents([
62 new MessageButton()
63 .setLabel("Select all")
64 .setStyle("PRIMARY")
65 .setCustomId("all"),
66 new MessageButton()
67 .setLabel("Select none")
68 .setStyle("DANGER")
69 .setCustomId("none")
70 ])
pineafan63fc5e22022-08-04 22:04:10 +010071 ]});
pineafan41d93562022-07-30 22:10:15 +010072 let i;
73 try {
74 i = await m.awaitMessageComponent({ time: 300000 });
75 } catch (e) {
pineafan63fc5e22022-08-04 22:04:10 +010076 break;
pineafan41d93562022-07-30 22:10:15 +010077 }
pineafan63fc5e22022-08-04 22:04:10 +010078 i.deferUpdate();
pineafan41d93562022-07-30 22:10:15 +010079 if (i.customId === "logs") {
pineafan63fc5e22022-08-04 22:04:10 +010080 const selected = i.values;
81 const newLogs = toHexInteger(selected.map(e => Object.keys(logs)[parseInt(e)]));
82 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs});
pineafan41d93562022-07-30 22:10:15 +010083 } else if (i.customId === "all") {
pineafan63fc5e22022-08-04 22:04:10 +010084 const newLogs = toHexInteger(Object.keys(logs).map(e => e));
85 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs});
pineafan41d93562022-07-30 22:10:15 +010086 } else if (i.customId === "none") {
pineafan63fc5e22022-08-04 22:04:10 +010087 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": 0});
pineafan41d93562022-07-30 22:10:15 +010088 } else {
pineafan63fc5e22022-08-04 22:04:10 +010089 break;
pineafan41d93562022-07-30 22:10:15 +010090 }
91 }
92 m = await interaction.editReply({embeds: [new EmojiEmbed()
93 .setTitle("Logging Events")
94 .setDescription("Below are the events being logged in the server. You can toggle them on and off in the dropdown")
95 .setFooter({text: "Message timed out"})
96 .setStatus("Success")
97 .setEmoji("CHANNEL.TEXT.CREATE")
pineafan63fc5e22022-08-04 22:04:10 +010098 ]});
pineafanbd02b4a2022-08-05 22:01:38 +010099 return;
pineafan63fc5e22022-08-04 22:04:10 +0100100};
pineafan4f164f32022-02-26 22:07:12 +0000101
pineafanbd02b4a2022-08-05 22:01:38 +0100102const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
pineafan63fc5e22022-08-04 22:04:10 +0100103 const member = (interaction.member as Discord.GuildMember);
104 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command";
pineafan4f164f32022-02-26 22:07:12 +0000105 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100106};
pineafan4f164f32022-02-26 22:07:12 +0000107
108export { command };
109export { callback };
110export { check };