blob: 7a68c64cc165e66d11102421969f79bf285226bd [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)
50 if (confirmation.success) {
51 try {
pineafan4edb7762022-06-26 19:21:04 +010052 await client.database.guilds.write(interaction.guild.id, {"verify.role": role.id, "verify.enabled": true});
pineafanda6e5342022-07-03 10:03:16 +010053 const { log, NucleusColors, entry, renderUser, renderRole } = client.logger
54 try {
55 let data = {
56 meta:{
57 type: 'verifyRoleChanged',
58 displayName: 'Ignored Groups Changed',
59 calculateType: 'nucleusSettingsUpdated',
60 color: NucleusColors.green,
61 emoji: "CONTROL.BLOCKTICK",
62 timestamp: new Date().getTime()
63 },
64 list: {
65 memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
66 changedBy: entry(interaction.user.id, renderUser(interaction.user)),
67 role: entry(role.id, renderRole(role)),
68 },
69 hidden: {
70 guild: interaction.guild.id
71 }
72 }
73 log(data);
74 } catch {}
pineafan6702cef2022-06-13 17:52:37 +010075 } catch (e) {
76 console.log(e)
pineafan4edb7762022-06-26 19:21:04 +010077 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010078 .setTitle("Verify Role")
79 .setDescription(`Something went wrong while setting the verify role`)
80 .setStatus("Danger")
81 .setEmoji("GUILD.ROLES.DELETE")
82 ], components: []});
83 }
84 } else {
pineafan4edb7762022-06-26 19:21:04 +010085 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010086 .setTitle("Verify Role")
87 .setDescription(`No changes were made`)
88 .setStatus("Success")
89 .setEmoji("GUILD.ROLES.CREATE")
90 ], components: []});
91 }
92 }
93 let clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +010094 let data = await client.database.guilds.read(interaction.guild.id);
pineafan6702cef2022-06-13 17:52:37 +010095 let role = data.verify.role;
96 while (true) {
pineafan4edb7762022-06-26 19:21:04 +010097 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010098 .setTitle("Verify Role")
99 .setDescription(role ? `Your verify role is currently set to <@&${role}>` : `You have not set a verify role`)
100 .setStatus("Success")
101 .setEmoji("GUILD.ROLES.CREATE")
102 ], components: [new MessageActionRow().addComponents([new MessageButton()
103 .setCustomId("clear")
104 .setLabel(clicks ? "Click again to confirm" : "Reset role")
105 .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
106 .setStyle("DANGER")
107 .setDisabled(!role)
108 ])]});
109 let i;
110 try {
pineafanc6158ab2022-06-17 16:34:07 +0100111 i = await m.awaitMessageComponent({time: 300000});
pineafan6702cef2022-06-13 17:52:37 +0100112 } catch(e) { break }
113 i.deferUpdate()
114 if (i.component.customId == "clear") {
115 clicks += 1;
116 if (clicks == 2) {
117 clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +0100118 await client.database.guilds.write(interaction.guild.id, {}, ["verify.role", "verify.enabled"])
pineafan6702cef2022-06-13 17:52:37 +0100119 role = undefined;
120 }
121 } else {
122 break
123 }
124 }
pineafan4edb7762022-06-26 19:21:04 +0100125 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +0100126 .setTitle("Verify Role")
127 .setDescription(role ? `Your verify role is currently set to <@&${role}}>` : `You have not set a verify role`)
128 .setStatus("Success")
129 .setEmoji("GUILD.ROLE.CREATE")
130 .setFooter({text: "Message closed"})
131 ], components: [new MessageActionRow().addComponents([new MessageButton()
132 .setCustomId("clear")
133 .setLabel("Clear")
134 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
135 .setStyle("SECONDARY")
136 .setDisabled(true)
137 ])]});
pineafan4f164f32022-02-26 22:07:12 +0000138}
139
140const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
pineafan6702cef2022-06-13 17:52:37 +0100141 let member = (interaction.member as Discord.GuildMember)
pineafanda6e5342022-07-03 10:03:16 +0100142 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the Manage Server permission to use this command"
pineafan4f164f32022-02-26 22:07:12 +0000143 return true;
144}
145
146export { command };
147export { callback };
pineafan6702cef2022-06-13 17:52:37 +0100148export { check };