blob: d71fdf006be83fc377db193961f603dd71963845 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafanda6e5342022-07-03 10:03:16 +01002import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
3import confirmationMessage from "../../utils/confirmationMessage.js";
4import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan4f164f32022-02-26 22:07:12 +00005import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
6import { WrappedCheck } from "jshaiku";
pineafanda6e5342022-07-03 10:03:16 +01007import client from "../../utils/client.js";
pineafan4f164f32022-02-26 22:07:12 +00008
9const command = (builder: SlashCommandSubcommandBuilder) =>
10 builder
pineafanda6e5342022-07-03 10:03:16 +010011 .setName("verify")
12 .setDescription("Manage the role given after typing /verify")
13 .addRoleOption(option => option.setName("role").setDescription("The role to give after verifying").setRequired(false))
pineafan4f164f32022-02-26 22:07:12 +000014
pineafan6702cef2022-06-13 17:52:37 +010015const callback = async (interaction: CommandInteraction): Promise<any> => {
16 let m;
pineafan4edb7762022-06-26 19:21:04 +010017 m = await interaction.reply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010018 .setTitle("Loading")
19 .setStatus("Danger")
20 .setEmoji("NUCLEUS.LOADING")
21 ], ephemeral: true, fetchReply: true});
22 if (interaction.options.getRole("role")) {
23 let role
24 try {
25 role = interaction.options.getRole("role")
26 } catch {
pineafan4edb7762022-06-26 19:21:04 +010027 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010028 .setEmoji("GUILD.ROLES.DELETE")
29 .setTitle("Verify Role")
30 .setDescription("The role you provided is not a valid role")
31 .setStatus("Danger")
32 ]})
33 }
34 role = role as Discord.Role
35 if (role.guild.id != interaction.guild.id) {
pineafan4edb7762022-06-26 19:21:04 +010036 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010037 .setTitle("Verify Role")
38 .setDescription(`You must choose a role in this server`)
39 .setStatus("Danger")
40 .setEmoji("GUILD.ROLES.DELETE")
41 ]});
42 }
43 let confirmation = await new confirmationMessage(interaction)
44 .setEmoji("GUILD.ROLES.EDIT")
45 .setTitle("Verify Role")
46 .setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`)
47 .setColor("Warning")
48 .setInverted(true)
49 .send(true)
pineafan02ba0232022-07-24 22:16:15 +010050 if (confirmation.cancelled) return
pineafan6702cef2022-06-13 17:52:37 +010051 if (confirmation.success) {
52 try {
pineafan4edb7762022-06-26 19:21:04 +010053 await client.database.guilds.write(interaction.guild.id, {"verify.role": role.id, "verify.enabled": true});
pineafanda6e5342022-07-03 10:03:16 +010054 const { log, NucleusColors, entry, renderUser, renderRole } = client.logger
55 try {
56 let data = {
57 meta:{
58 type: 'verifyRoleChanged',
59 displayName: 'Ignored Groups Changed',
60 calculateType: 'nucleusSettingsUpdated',
61 color: NucleusColors.green,
62 emoji: "CONTROL.BLOCKTICK",
63 timestamp: new Date().getTime()
64 },
65 list: {
66 memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
67 changedBy: entry(interaction.user.id, renderUser(interaction.user)),
68 role: entry(role.id, renderRole(role)),
69 },
70 hidden: {
71 guild: interaction.guild.id
72 }
73 }
74 log(data);
75 } catch {}
pineafan6702cef2022-06-13 17:52:37 +010076 } catch (e) {
77 console.log(e)
pineafan4edb7762022-06-26 19:21:04 +010078 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010079 .setTitle("Verify Role")
80 .setDescription(`Something went wrong while setting the verify role`)
81 .setStatus("Danger")
82 .setEmoji("GUILD.ROLES.DELETE")
83 ], components: []});
84 }
85 } else {
pineafan4edb7762022-06-26 19:21:04 +010086 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010087 .setTitle("Verify Role")
88 .setDescription(`No changes were made`)
89 .setStatus("Success")
90 .setEmoji("GUILD.ROLES.CREATE")
91 ], components: []});
92 }
93 }
94 let clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +010095 let data = await client.database.guilds.read(interaction.guild.id);
pineafan6702cef2022-06-13 17:52:37 +010096 let role = data.verify.role;
97 while (true) {
pineafan4edb7762022-06-26 19:21:04 +010098 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010099 .setTitle("Verify Role")
100 .setDescription(role ? `Your verify role is currently set to <@&${role}>` : `You have not set a verify role`)
101 .setStatus("Success")
102 .setEmoji("GUILD.ROLES.CREATE")
103 ], components: [new MessageActionRow().addComponents([new MessageButton()
104 .setCustomId("clear")
105 .setLabel(clicks ? "Click again to confirm" : "Reset role")
106 .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
107 .setStyle("DANGER")
108 .setDisabled(!role)
109 ])]});
110 let i;
111 try {
pineafanc6158ab2022-06-17 16:34:07 +0100112 i = await m.awaitMessageComponent({time: 300000});
pineafan6702cef2022-06-13 17:52:37 +0100113 } catch(e) { break }
114 i.deferUpdate()
115 if (i.component.customId == "clear") {
116 clicks += 1;
117 if (clicks == 2) {
118 clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +0100119 await client.database.guilds.write(interaction.guild.id, {}, ["verify.role", "verify.enabled"])
pineafan6702cef2022-06-13 17:52:37 +0100120 role = undefined;
121 }
122 } else {
123 break
124 }
125 }
pineafan4edb7762022-06-26 19:21:04 +0100126 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +0100127 .setTitle("Verify Role")
128 .setDescription(role ? `Your verify role is currently set to <@&${role}}>` : `You have not set a verify role`)
129 .setStatus("Success")
130 .setEmoji("GUILD.ROLE.CREATE")
131 .setFooter({text: "Message closed"})
132 ], components: [new MessageActionRow().addComponents([new MessageButton()
133 .setCustomId("clear")
134 .setLabel("Clear")
135 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
136 .setStyle("SECONDARY")
137 .setDisabled(true)
138 ])]});
pineafan4f164f32022-02-26 22:07:12 +0000139}
140
141const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
pineafan6702cef2022-06-13 17:52:37 +0100142 let member = (interaction.member as Discord.GuildMember)
pineafanda6e5342022-07-03 10:03:16 +0100143 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the Manage Server permission to use this command"
pineafan4f164f32022-02-26 22:07:12 +0000144 return true;
145}
146
147export { command };
148export { callback };
pineafan6702cef2022-06-13 17:52:37 +0100149export { check };