pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 2 | import Discord, { CommandInteraction, 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 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 41 | let m; |
| 42 | while (true) { |
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 | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | m = await interaction.editReply({ |
| 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: [ |
| 56 | new MessageActionRow().addComponents([ |
| 57 | new MessageSelectMenu() |
| 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 | ]), |
| 70 | new MessageActionRow().addComponents([ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 71 | new MessageButton().setLabel("Select all").setStyle("PRIMARY").setCustomId("all"), |
| 72 | new MessageButton().setLabel("Select none").setStyle("DANGER").setCustomId("none") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 73 | ]) |
| 74 | ] |
| 75 | }); |
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) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 80 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 81 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 83 | if (i.customId === "logs") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 84 | const selected = i.values; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 85 | const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)])); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 86 | await client.database.guilds.write(interaction.guild.id, { |
| 87 | "logging.logs.toLog": newLogs |
| 88 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 89 | } else if (i.customId === "all") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 90 | const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); |
| 91 | await client.database.guilds.write(interaction.guild.id, { |
| 92 | "logging.logs.toLog": newLogs |
| 93 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 94 | } else if (i.customId === "none") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 95 | await client.database.guilds.write(interaction.guild.id, { |
| 96 | "logging.logs.toLog": 0 |
| 97 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 98 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 99 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 102 | m = await interaction.editReply({ |
| 103 | embeds: [ |
| 104 | new EmojiEmbed() |
| 105 | .setTitle("Logging Events") |
| 106 | .setDescription( |
| 107 | "Below are the events being logged in the server. You can toggle them on and off in the dropdown" |
| 108 | ) |
| 109 | .setFooter({ text: "Message timed out" }) |
| 110 | .setStatus("Success") |
| 111 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 112 | ] |
| 113 | }); |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 114 | return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 115 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 116 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 117 | const check = (interaction: CommandInteraction, _defaultCheck: WrappedCheck) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 118 | const member = interaction.member as Discord.GuildMember; |
| 119 | if (!member.permissions.has("MANAGE_GUILD")) |
| 120 | throw "You must have the *Manage Server* permission to use this command"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 121 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 122 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 123 | |
| 124 | export { command }; |
| 125 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 126 | export { check }; |