PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | Message, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 5 | ActionRowBuilder, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 6 | ButtonBuilder, |
TheCodedProf | 59772f8 | 2023-01-18 22:17:16 -0500 | [diff] [blame] | 7 | ButtonStyle, |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 8 | RoleSelectMenuBuilder, |
| 9 | APIMessageComponentEmoji |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 10 | } from "discord.js"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 11 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 12 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 13 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 14 | import client from "../../utils/client.js"; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 15 | import { getCommandMentionByName } from "../../utils/getCommandDataByName.js"; |
| 16 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 17 | |
| 18 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 19 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | .setName("verify") |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 21 | .setDescription("Manage the role given after a user runs /verify") |
| 22 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 23 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 24 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 25 | if (!interaction.guild) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 26 | const m = (await interaction.reply({ |
| 27 | embeds: LoadingEmbed, |
| 28 | ephemeral: true, |
| 29 | fetchReply: true |
| 30 | })) as Message; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 31 | |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 32 | let closed = false; |
| 33 | let config = await client.database.guilds.read(interaction.guild.id); |
| 34 | let data = Object.assign({}, config.verify); |
| 35 | do { |
| 36 | console.log(config.verify, data) |
| 37 | const selectMenu = new ActionRowBuilder<RoleSelectMenuBuilder>() |
| 38 | .addComponents( |
| 39 | new RoleSelectMenuBuilder() |
| 40 | .setCustomId("role") |
| 41 | .setPlaceholder("Select a role") |
| 42 | ); |
| 43 | |
| 44 | const buttons = new ActionRowBuilder<ButtonBuilder>() |
| 45 | .addComponents( |
| 46 | new ButtonBuilder() |
| 47 | .setCustomId("switch") |
| 48 | .setLabel(data.enabled ? "Disabled" : "Enabled") |
| 49 | .setStyle(data.enabled ? ButtonStyle.Danger : ButtonStyle.Success) |
| 50 | .setEmoji(getEmojiByName(data.enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji), |
| 51 | new ButtonBuilder() |
| 52 | .setCustomId("save") |
| 53 | .setLabel("Save") |
| 54 | .setStyle(ButtonStyle.Success) |
| 55 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji) |
| 56 | .setDisabled(data.role === config.verify.role && data.enabled === config.verify.enabled) |
| 57 | ); |
| 58 | |
| 59 | const embed = new EmojiEmbed() |
| 60 | .setTitle("Verify Role") |
| 61 | .setDescription( |
| 62 | `Select a role to be given to users after they run ${getCommandMentionByName("verify")}` + |
| 63 | `\n\nCurrent role: ${config.verify.role ? `<@&${config.verify.role}>` : "None"}` |
| 64 | ) |
| 65 | .setStatus("Success") |
| 66 | .setEmoji("CHANNEL.TEXT.CREATE"); |
| 67 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 68 | await interaction.editReply({ |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 69 | embeds: [embed], |
| 70 | components: [selectMenu, buttons] |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 71 | }); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 72 | |
| 73 | let i; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 74 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 75 | i = await m.awaitMessageComponent({ |
| 76 | time: 300000, |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 77 | filter: (i) => { return i.user.id === interaction.user.id } |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 78 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 79 | } catch (e) { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 80 | closed = true; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 81 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | } |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 83 | |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 84 | await i.deferUpdate(); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 85 | |
| 86 | if(i.isButton()) { |
| 87 | switch (i.customId) { |
| 88 | case "save": { |
| 89 | client.database.guilds.write(interaction.guild.id, {"verify": data} ) |
| 90 | config = await client.database.guilds.read(interaction.guild.id); |
| 91 | break |
| 92 | } |
| 93 | case "switch": { |
| 94 | data.enabled = !data.enabled; |
| 95 | break |
| 96 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 97 | } |
| 98 | } else { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 99 | data.role = i.values[0]!; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 100 | } |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 101 | |
| 102 | } while (!closed); |
| 103 | await interaction.deleteReply() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 104 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 105 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 106 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 107 | const member = interaction.member as Discord.GuildMember; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 108 | if (!member.permissions.has("ManageGuild")) |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 109 | return "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 }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 115 | export { check }; |