blob: a1edcaf284acfa657303f3dfc14639fdd951fc60 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01002import Discord, {
3 CommandInteraction,
4 MessageActionRow,
5 MessageButton,
6 MessageSelectMenu
7} from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00008import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
9import { WrappedCheck } from "jshaiku";
pineafan41d93562022-07-30 22:10:15 +010010import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +010011import client from "../../../utils/client.js";
pineafan41d93562022-07-30 22:10:15 +010012import { toHexArray, toHexInteger } from "../../../utils/calculate.js";
13
pineafan41d93562022-07-30 22:10:15 +010014const logs = {
Skyler Grey75ea9172022-08-06 10:22:23 +010015 channelUpdate: "Channels created, deleted or modified",
16 emojiUpdate: "Server emojis modified",
17 stickerUpdate: "Server stickers modified",
18 guildUpdate: "Server settings updated",
19 guildMemberUpdate: "Member updated (i.e. nickname)",
20 guildMemberPunish: "Members punished (i.e. muted, banned, kicked)",
21 guildRoleUpdate: "Role settings changed",
22 guildInviteUpdate: "Server invite created or deleted",
23 messageUpdate: "Message edited",
24 messageDelete: "Message deleted",
25 messageDeleteBulk: "Messages purged",
26 messageReactionUpdate: "Message reactions cleared",
27 messageMassPing: "Message pings multiple members at once",
28 messageAnnounce: "Message published in announcement channel",
29 threadUpdate: "Thread created or deleted",
30 webhookUpdate: "Webhooks created or deleted",
31 guildMemberVerify: "Member runs verify",
32 autoModeratorDeleted: "Messages auto deleted by Nucleus",
33 nucleusSettingsUpdated: "Nucleus' settings updated by a moderator",
34 ticketUpdate: "Tickets created or deleted"
pineafan63fc5e22022-08-04 22:04:10 +010035};
pineafan4f164f32022-02-26 22:07:12 +000036
37const command = (builder: SlashCommandSubcommandBuilder) =>
38 builder
pineafan63fc5e22022-08-04 22:04:10 +010039 .setName("events")
40 .setDescription("Sets what events should be logged");
pineafan4f164f32022-02-26 22:07:12 +000041
pineafanbd02b4a2022-08-05 22:01:38 +010042const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Grey75ea9172022-08-06 10:22:23 +010043 await interaction.reply({
44 embeds: LoadingEmbed,
45 fetchReply: true,
46 ephemeral: true
47 });
pineafan41d93562022-07-30 22:10:15 +010048 let m;
49 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +010050 const config = await client.database.guilds.read(interaction.guild.id);
51 const converted = toHexArray(config.logging.logs.toLog);
Skyler Grey75ea9172022-08-06 10:22:23 +010052 m = await interaction.editReply({
53 embeds: [
54 new EmojiEmbed()
55 .setTitle("Logging Events")
56 .setDescription(
57 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
58 )
59 .setStatus("Success")
60 .setEmoji("CHANNEL.TEXT.CREATE")
61 ],
62 components: [
63 new MessageActionRow().addComponents([
64 new MessageSelectMenu()
65 .setPlaceholder("Set events to log")
66 .setMaxValues(Object.keys(logs).length)
67 .setCustomId("logs")
68 .setMinValues(0)
69 .setOptions(
70 Object.keys(logs).map((e, i) => ({
71 label: logs[e],
72 value: i.toString(),
73 default: converted.includes(e)
74 }))
75 )
76 ]),
77 new MessageActionRow().addComponents([
78 new MessageButton()
79 .setLabel("Select all")
80 .setStyle("PRIMARY")
81 .setCustomId("all"),
82 new MessageButton()
83 .setLabel("Select none")
84 .setStyle("DANGER")
85 .setCustomId("none")
86 ])
87 ]
88 });
pineafan41d93562022-07-30 22:10:15 +010089 let i;
90 try {
91 i = await m.awaitMessageComponent({ time: 300000 });
92 } catch (e) {
pineafan63fc5e22022-08-04 22:04:10 +010093 break;
pineafan41d93562022-07-30 22:10:15 +010094 }
pineafan63fc5e22022-08-04 22:04:10 +010095 i.deferUpdate();
pineafan41d93562022-07-30 22:10:15 +010096 if (i.customId === "logs") {
pineafan63fc5e22022-08-04 22:04:10 +010097 const selected = i.values;
Skyler Grey75ea9172022-08-06 10:22:23 +010098 const newLogs = toHexInteger(
99 selected.map((e) => Object.keys(logs)[parseInt(e)])
100 );
101 await client.database.guilds.write(interaction.guild.id, {
102 "logging.logs.toLog": newLogs
103 });
pineafan41d93562022-07-30 22:10:15 +0100104 } else if (i.customId === "all") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 const newLogs = toHexInteger(Object.keys(logs).map((e) => e));
106 await client.database.guilds.write(interaction.guild.id, {
107 "logging.logs.toLog": newLogs
108 });
pineafan41d93562022-07-30 22:10:15 +0100109 } else if (i.customId === "none") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100110 await client.database.guilds.write(interaction.guild.id, {
111 "logging.logs.toLog": 0
112 });
pineafan41d93562022-07-30 22:10:15 +0100113 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100114 break;
pineafan41d93562022-07-30 22:10:15 +0100115 }
116 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100117 m = await interaction.editReply({
118 embeds: [
119 new EmojiEmbed()
120 .setTitle("Logging Events")
121 .setDescription(
122 "Below are the events being logged in the server. You can toggle them on and off in the dropdown"
123 )
124 .setFooter({ text: "Message timed out" })
125 .setStatus("Success")
126 .setEmoji("CHANNEL.TEXT.CREATE")
127 ]
128 });
pineafanbd02b4a2022-08-05 22:01:38 +0100129 return;
pineafan63fc5e22022-08-04 22:04:10 +0100130};
pineafan4f164f32022-02-26 22:07:12 +0000131
Skyler Grey75ea9172022-08-06 10:22:23 +0100132const check = (
133 interaction: CommandInteraction,
134 _defaultCheck: WrappedCheck
135) => {
136 const member = interaction.member as Discord.GuildMember;
137 if (!member.permissions.has("MANAGE_GUILD"))
138 throw "You must have the *Manage Server* permission to use this command";
pineafan4f164f32022-02-26 22:07:12 +0000139 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100140};
pineafan4f164f32022-02-26 22:07:12 +0000141
142export { command };
143export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100144export { check };