blob: 14dfe8d53145cd4bd958167d3309a2f1d12a6af9 [file] [log] [blame]
pineafane23c4ec2022-07-27 21:56:27 +01001import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
pineafan6702cef2022-06-13 17:52:37 +01002import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafanda6e5342022-07-03 10:03:16 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
4import confirmationMessage from "../../utils/confirmationMessage.js";
5import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan4f164f32022-02-26 22:07:12 +00006import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
7import { WrappedCheck } from "jshaiku";
pineafanda6e5342022-07-03 10:03:16 +01008import client from "../../utils/client.js";
pineafan4f164f32022-02-26 22:07:12 +00009
10const command = (builder: SlashCommandSubcommandBuilder) =>
11 builder
pineafanda6e5342022-07-03 10:03:16 +010012 .setName("verify")
13 .setDescription("Manage the role given after typing /verify")
14 .addRoleOption(option => option.setName("role").setDescription("The role to give after verifying").setRequired(false))
pineafan4f164f32022-02-26 22:07:12 +000015
pineafan6702cef2022-06-13 17:52:37 +010016const callback = async (interaction: CommandInteraction): Promise<any> => {
17 let m;
pineafane23c4ec2022-07-27 21:56:27 +010018 m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true});
pineafan6702cef2022-06-13 17:52:37 +010019 if (interaction.options.getRole("role")) {
20 let role
21 try {
22 role = interaction.options.getRole("role")
23 } catch {
pineafan4edb7762022-06-26 19:21:04 +010024 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010025 .setEmoji("GUILD.ROLES.DELETE")
26 .setTitle("Verify Role")
27 .setDescription("The role you provided is not a valid role")
28 .setStatus("Danger")
29 ]})
30 }
31 role = role as Discord.Role
pineafane23c4ec2022-07-27 21:56:27 +010032 if (role.guild.id !== interaction.guild.id) {
pineafan4edb7762022-06-26 19:21:04 +010033 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010034 .setTitle("Verify Role")
35 .setDescription(`You must choose a role in this server`)
36 .setStatus("Danger")
37 .setEmoji("GUILD.ROLES.DELETE")
38 ]});
39 }
40 let confirmation = await new confirmationMessage(interaction)
41 .setEmoji("GUILD.ROLES.EDIT")
42 .setTitle("Verify Role")
43 .setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`)
44 .setColor("Warning")
45 .setInverted(true)
46 .send(true)
pineafan02ba0232022-07-24 22:16:15 +010047 if (confirmation.cancelled) return
pineafan6702cef2022-06-13 17:52:37 +010048 if (confirmation.success) {
49 try {
pineafan4edb7762022-06-26 19:21:04 +010050 await client.database.guilds.write(interaction.guild.id, {"verify.role": role.id, "verify.enabled": true});
pineafanda6e5342022-07-03 10:03:16 +010051 const { log, NucleusColors, entry, renderUser, renderRole } = client.logger
52 try {
53 let data = {
54 meta:{
55 type: 'verifyRoleChanged',
56 displayName: 'Ignored Groups Changed',
57 calculateType: 'nucleusSettingsUpdated',
58 color: NucleusColors.green,
59 emoji: "CONTROL.BLOCKTICK",
60 timestamp: new Date().getTime()
61 },
62 list: {
63 memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
64 changedBy: entry(interaction.user.id, renderUser(interaction.user)),
65 role: entry(role.id, renderRole(role)),
66 },
67 hidden: {
68 guild: interaction.guild.id
69 }
70 }
71 log(data);
72 } catch {}
pineafan6702cef2022-06-13 17:52:37 +010073 } catch (e) {
74 console.log(e)
pineafan4edb7762022-06-26 19:21:04 +010075 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010076 .setTitle("Verify Role")
77 .setDescription(`Something went wrong while setting the verify role`)
78 .setStatus("Danger")
79 .setEmoji("GUILD.ROLES.DELETE")
80 ], components: []});
81 }
82 } else {
pineafan4edb7762022-06-26 19:21:04 +010083 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010084 .setTitle("Verify Role")
85 .setDescription(`No changes were made`)
86 .setStatus("Success")
87 .setEmoji("GUILD.ROLES.CREATE")
88 ], components: []});
89 }
90 }
91 let clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +010092 let data = await client.database.guilds.read(interaction.guild.id);
pineafan6702cef2022-06-13 17:52:37 +010093 let role = data.verify.role;
94 while (true) {
pineafan4edb7762022-06-26 19:21:04 +010095 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010096 .setTitle("Verify Role")
97 .setDescription(role ? `Your verify role is currently set to <@&${role}>` : `You have not set a verify role`)
98 .setStatus("Success")
99 .setEmoji("GUILD.ROLES.CREATE")
pineafane23c4ec2022-07-27 21:56:27 +0100100 ], components: [new MessageActionRow().addComponents([
101 new MessageButton()
102 .setCustomId("clear")
103 .setLabel(clicks ? "Click again to confirm" : "Reset role")
104 .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
105 .setStyle("DANGER")
106 .setDisabled(!role)
pineafan6702cef2022-06-13 17:52:37 +0100107 ])]});
108 let i;
109 try {
pineafanc6158ab2022-06-17 16:34:07 +0100110 i = await m.awaitMessageComponent({time: 300000});
pineafan6702cef2022-06-13 17:52:37 +0100111 } catch(e) { break }
112 i.deferUpdate()
pineafane23c4ec2022-07-27 21:56:27 +0100113 if (i.component.customId === "clear") {
pineafan6702cef2022-06-13 17:52:37 +0100114 clicks += 1;
pineafane23c4ec2022-07-27 21:56:27 +0100115 if (clicks === 2) {
pineafan6702cef2022-06-13 17:52:37 +0100116 clicks = 0;
pineafane23c4ec2022-07-27 21:56:27 +0100117 await client.database.guilds.write(interaction.guild.id, null, ["verify.role", "verify.enabled"])
pineafan6702cef2022-06-13 17:52:37 +0100118 role = undefined;
119 }
120 } else {
121 break
122 }
123 }
pineafan4edb7762022-06-26 19:21:04 +0100124 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +0100125 .setTitle("Verify Role")
126 .setDescription(role ? `Your verify role is currently set to <@&${role}}>` : `You have not set a verify role`)
127 .setStatus("Success")
128 .setEmoji("GUILD.ROLE.CREATE")
129 .setFooter({text: "Message closed"})
130 ], components: [new MessageActionRow().addComponents([new MessageButton()
131 .setCustomId("clear")
132 .setLabel("Clear")
133 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
134 .setStyle("SECONDARY")
pineafane23c4ec2022-07-27 21:56:27 +0100135 .setDisabled(true),
pineafan6702cef2022-06-13 17:52:37 +0100136 ])]});
pineafan4f164f32022-02-26 22:07:12 +0000137}
138
139const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
pineafan6702cef2022-06-13 17:52:37 +0100140 let member = (interaction.member as Discord.GuildMember)
pineafane23c4ec2022-07-27 21:56:27 +0100141 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command"
pineafan4f164f32022-02-26 22:07:12 +0000142 return true;
143}
144
145export { command };
146export { callback };
pineafan6702cef2022-06-13 17:52:37 +0100147export { check };