pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js"; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 2 | import Discord, { CommandInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 3 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
| 4 | import { WrappedCheck } from "jshaiku"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 5 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | import client from "../../../utils/client.js"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 7 | import { toHexArray, toHexInteger } from "../../../utils/calculate.js"; |
| 8 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 9 | const logs = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 10 | 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" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 31 | |
| 32 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 33 | builder.setName("events").setDescription("Sets what events should be logged"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 34 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 35 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 36 | await interaction.reply({ |
| 37 | embeds: LoadingEmbed, |
| 38 | fetchReply: true, |
| 39 | ephemeral: true |
| 40 | }); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 41 | let m: Message; |
| 42 | let timedOut = false; |
| 43 | do { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | const config = await client.database.guilds.read(interaction.guild.id); |
| 45 | const converted = toHexArray(config.logging.logs.toLog); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 46 | m = (await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 47 | 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: [ |
| 57 | new MessageActionRow().addComponents([ |
| 58 | new MessageSelectMenu() |
| 59 | .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 | ]), |
| 71 | new MessageActionRow().addComponents([ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 72 | new MessageButton().setLabel("Select all").setStyle("PRIMARY").setCustomId("all"), |
| 73 | new MessageButton().setLabel("Select none").setStyle("DANGER").setCustomId("none") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | ]) |
| 75 | ] |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 76 | })) as Message; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 77 | let i; |
| 78 | try { |
| 79 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 80 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 81 | timedOut = true; |
| 82 | continue; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 83 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 84 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 85 | if (i.customId === "logs") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 86 | const selected = i.values; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 87 | const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)])); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | await client.database.guilds.write(interaction.guild.id, { |
| 89 | "logging.logs.toLog": newLogs |
| 90 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 91 | } else if (i.customId === "all") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 92 | const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); |
| 93 | await client.database.guilds.write(interaction.guild.id, { |
| 94 | "logging.logs.toLog": newLogs |
| 95 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 96 | } else if (i.customId === "none") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | await client.database.guilds.write(interaction.guild.id, { |
| 98 | "logging.logs.toLog": 0 |
| 99 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 100 | } |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 101 | } while (!timedOut); |
| 102 | |
| 103 | await interaction.editReply({ embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })] }); |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 104 | return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 105 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 106 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 107 | const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 108 | const member = interaction.member as Discord.GuildMember; |
| 109 | if (!member.permissions.has("MANAGE_GUILD")) |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 110 | throw new Error("You must have the *Manage Server* permission to use this command"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 111 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 112 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 113 | |
| 114 | export { command }; |
| 115 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 116 | export { check }; |