pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +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 | |
| 9 | |
| 10 | const logs = { |
| 11 | "channelUpdate": "Channels created, deleted or modified", |
| 12 | "emojiUpdate": "Server emojis modified", |
| 13 | "stickerUpdate": "Server stickers modified", |
| 14 | "guildUpdate": "Server settings updated", |
| 15 | "guildMemberUpdate": "Member updated (i.e. nickname)", |
| 16 | "guildMemberPunish": "Members punished (i.e. muted, banned, kicked)", |
| 17 | "guildRoleUpdate": "Role settings changed", |
| 18 | "guildInviteUpdate": "Server invite created or deleted", |
| 19 | "messageUpdate": "Message edited", |
| 20 | "messageDelete": "Message deleted", |
| 21 | "messageDeleteBulk": "Messages purged", |
| 22 | "messageReactionUpdate": "Message reactions cleared", |
| 23 | "messageMassPing": "Message pings multiple members at once", |
| 24 | "messageAnnounce": "Message published in announcement channel", |
| 25 | "threadUpdate": "Thread created or deleted", |
| 26 | "webhookUpdate": "Webhooks created or deleted", |
| 27 | "guildMemberVerify": "Member runs verify", |
| 28 | "autoModeratorDeleted": "Messages auto deleted by Nucleus", |
| 29 | "nucleusSettingsUpdated": "Nucleus' settings updated by a moderator", |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | "ticketUpdate": "Tickets created or deleted" |
| 31 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 32 | |
| 33 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 34 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | .setName("events") |
| 36 | .setDescription("Sets what events should be logged"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 37 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 38 | const callback = async (interaction: CommandInteraction): Promise<any> => { |
| 39 | await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true}); |
| 40 | let m; |
| 41 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 42 | const config = await client.database.guilds.read(interaction.guild.id); |
| 43 | const converted = toHexArray(config.logging.logs.toLog); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 44 | m = await interaction.editReply({embeds: [new EmojiEmbed() |
| 45 | .setTitle("Logging Events") |
| 46 | .setDescription("Below are the events being logged in the server. You can toggle them on and off in the dropdown") |
| 47 | .setStatus("Success") |
| 48 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 49 | ], components: [ |
| 50 | new MessageActionRow().addComponents([new MessageSelectMenu() |
| 51 | .setPlaceholder("Set events to log") |
| 52 | .setMaxValues(Object.keys(logs).length) |
| 53 | .setCustomId("logs") |
| 54 | .setMinValues(0) |
| 55 | .setOptions(Object.keys(logs).map((e, i) => ({ |
| 56 | label: logs[e], |
| 57 | value: i.toString(), |
| 58 | default: converted.includes(e) |
| 59 | }))) |
| 60 | ]), |
| 61 | new MessageActionRow().addComponents([ |
| 62 | new MessageButton() |
| 63 | .setLabel("Select all") |
| 64 | .setStyle("PRIMARY") |
| 65 | .setCustomId("all"), |
| 66 | new MessageButton() |
| 67 | .setLabel("Select none") |
| 68 | .setStyle("DANGER") |
| 69 | .setCustomId("none") |
| 70 | ]) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 71 | ]}); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 72 | let i; |
| 73 | try { |
| 74 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 75 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 76 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 77 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 78 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 79 | if (i.customId === "logs") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 80 | const selected = i.values; |
| 81 | const newLogs = toHexInteger(selected.map(e => Object.keys(logs)[parseInt(e)])); |
| 82 | await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs}); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 83 | } else if (i.customId === "all") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 84 | const newLogs = toHexInteger(Object.keys(logs).map(e => e)); |
| 85 | await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": newLogs}); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 86 | } else if (i.customId === "none") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 87 | await client.database.guilds.write(interaction.guild.id, {"logging.logs.toLog": 0}); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 88 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 89 | break; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | m = await interaction.editReply({embeds: [new EmojiEmbed() |
| 93 | .setTitle("Logging Events") |
| 94 | .setDescription("Below are the events being logged in the server. You can toggle them on and off in the dropdown") |
| 95 | .setFooter({text: "Message timed out"}) |
| 96 | .setStatus("Success") |
| 97 | .setEmoji("CHANNEL.TEXT.CREATE") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 98 | ]}); |
| 99 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 100 | |
| 101 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 102 | const member = (interaction.member as Discord.GuildMember); |
| 103 | if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 104 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 105 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 106 | |
| 107 | export { command }; |
| 108 | export { callback }; |
| 109 | export { check }; |