pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | MessageActionRow, |
| 5 | MessageButton, |
| 6 | MessageSelectMenu |
| 7 | } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 8 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
| 9 | import { WrappedCheck } from "jshaiku"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 10 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | import client from "../../../utils/client.js"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 12 | import { toHexArray, toHexInteger } from "../../../utils/calculate.js"; |
| 13 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 14 | const logs = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 15 | 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" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 36 | |
| 37 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 38 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | .setName("events") |
| 40 | .setDescription("Sets what events should be logged"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 41 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 42 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 43 | await interaction.reply({ |
| 44 | embeds: LoadingEmbed, |
| 45 | fetchReply: true, |
| 46 | ephemeral: true |
| 47 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 48 | let m; |
| 49 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | const config = await client.database.guilds.read(interaction.guild.id); |
| 51 | const converted = toHexArray(config.logging.logs.toLog); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 52 | 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 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 89 | let i; |
| 90 | try { |
| 91 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 92 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 93 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 94 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 95 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 96 | if (i.customId === "logs") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 97 | const selected = i.values; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 98 | 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 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 104 | } else if (i.customId === "all") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 105 | const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); |
| 106 | await client.database.guilds.write(interaction.guild.id, { |
| 107 | "logging.logs.toLog": newLogs |
| 108 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 109 | } else if (i.customId === "none") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 110 | await client.database.guilds.write(interaction.guild.id, { |
| 111 | "logging.logs.toLog": 0 |
| 112 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 113 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 114 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 115 | } |
| 116 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 117 | 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 | }); |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 129 | return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 130 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 131 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 132 | const 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"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 139 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 140 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 141 | |
| 142 | export { command }; |
| 143 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 144 | export { check }; |