blob: ef303cb60df59270e92d86da706143097088fbad [file] [log] [blame]
pineafan41d93562022-07-30 22:10:15 +01001import { LoadingEmbed } from './../../../utils/defaultEmbeds.js';
2import 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";
6import client from '../../../utils/client.js';
7import { 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",
30 "ticketUpdate": "Tickets created or deleted",
31}
pineafan4f164f32022-02-26 22:07:12 +000032
33const command = (builder: SlashCommandSubcommandBuilder) =>
34 builder
35 .setName("events")
36 .setDescription("Sets what events should be logged")
37
pineafan41d93562022-07-30 22:10:15 +010038const callback = async (interaction: CommandInteraction): Promise<any> => {
39 await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true});
40 let m;
41 while (true) {
42 let config = await client.database.guilds.read(interaction.guild.id)
43 let converted = toHexArray(config.logging.logs.toLog)
44 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 ])
71 ]})
72 let i;
73 try {
74 i = await m.awaitMessageComponent({ time: 300000 });
75 } catch (e) {
76 break
77 }
78 i.deferUpdate()
79 if (i.customId === "logs") {
80 let selected = i.values;
81 let newLogs = toHexInteger(selected.map(e => Object.keys(logs)[parseInt(e)]))
82 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs})
83 } else if (i.customId === "all") {
84 let newLogs = toHexInteger(Object.keys(logs).map(e => e))
85 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs})
86 } else if (i.customId === "none") {
87 await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": 0})
88 } else {
89 break
90 }
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")
98 ]})
pineafan4f164f32022-02-26 22:07:12 +000099}
100
101const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
pineafan41d93562022-07-30 22:10:15 +0100102 let member = (interaction.member as Discord.GuildMember)
103 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command"
pineafan4f164f32022-02-26 22:07:12 +0000104 return true;
105}
106
107export { command };
108export { callback };
109export { check };