pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js"; |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 2 | import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 3 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | import client from "../../../utils/client.js"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 6 | import { toHexArray, toHexInteger } from "../../../utils/calculate.js"; |
| 7 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 8 | const logs = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 9 | channelUpdate: "Channels created, deleted or modified", |
| 10 | emojiUpdate: "Server emojis modified", |
| 11 | stickerUpdate: "Server stickers modified", |
| 12 | guildUpdate: "Server settings updated", |
| 13 | guildMemberUpdate: "Member updated (i.e. nickname)", |
| 14 | guildMemberPunish: "Members punished (i.e. muted, banned, kicked)", |
| 15 | guildRoleUpdate: "Role settings changed", |
| 16 | guildInviteUpdate: "Server invite created or deleted", |
| 17 | messageUpdate: "Message edited", |
| 18 | messageDelete: "Message deleted", |
| 19 | messageDeleteBulk: "Messages purged", |
| 20 | messageReactionUpdate: "Message reactions cleared", |
| 21 | messageMassPing: "Message pings multiple members at once", |
| 22 | messageAnnounce: "Message published in announcement channel", |
| 23 | threadUpdate: "Thread created or deleted", |
| 24 | webhookUpdate: "Webhooks created or deleted", |
| 25 | guildMemberVerify: "Member runs verify", |
| 26 | autoModeratorDeleted: "Messages auto deleted by Nucleus", |
| 27 | nucleusSettingsUpdated: "Nucleus' settings updated by a moderator", |
| 28 | ticketUpdate: "Tickets created or deleted" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 30 | |
| 31 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 32 | builder.setName("events").setDescription("Sets what events should be logged"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 33 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 34 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | await interaction.reply({ |
| 36 | embeds: LoadingEmbed, |
| 37 | fetchReply: true, |
| 38 | ephemeral: true |
| 39 | }); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 40 | let m: Message; |
| 41 | let timedOut = false; |
| 42 | do { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | const config = await client.database.guilds.read(interaction.guild.id); |
| 44 | const converted = toHexArray(config.logging.logs.toLog); |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 45 | m = (await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 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: [ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 56 | new ActionRowBuilder().addComponents([ |
| 57 | new SelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 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 | ]), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 70 | new ActionRowBuilder().addComponents([ |
| 71 | new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"), |
| 72 | new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 73 | ]) |
| 74 | ] |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 75 | })) as Message; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 76 | let i; |
| 77 | try { |
| 78 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 79 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 80 | timedOut = true; |
| 81 | continue; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 82 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 83 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 84 | if (i.customId === "logs") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | const selected = i.values; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 86 | const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)])); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 87 | await client.database.guilds.write(interaction.guild.id, { |
| 88 | "logging.logs.toLog": newLogs |
| 89 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 90 | } else if (i.customId === "all") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 91 | const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); |
| 92 | await client.database.guilds.write(interaction.guild.id, { |
| 93 | "logging.logs.toLog": newLogs |
| 94 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 95 | } else if (i.customId === "none") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 96 | await client.database.guilds.write(interaction.guild.id, { |
| 97 | "logging.logs.toLog": 0 |
| 98 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 99 | } |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 100 | } while (!timedOut); |
| 101 | |
| 102 | await interaction.editReply({ embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })] }); |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 103 | return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 104 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 105 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 106 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 107 | const member = interaction.member as Discord.GuildMember; |
| 108 | if (!member.permissions.has("MANAGE_GUILD")) |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 109 | 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] | 110 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 111 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 112 | |
| 113 | export { command }; |
| 114 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 115 | export { check }; |