PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 2 | import Discord, { CommandInteraction, GuildMember, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuOptionBuilder, APIMessageComponentEmoji, StringSelectMenuBuilder, MessageComponentInteraction, StringSelectMenuInteraction } from "discord.js"; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 3 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 5 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | import addPlural from "../../utils/plurals.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 7 | import client from "../../utils/client.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 8 | |
| 9 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 10 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | .setName("track") |
| 12 | .setDescription("Moves a user along a role track") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 13 | .addUserOption((option) => option.setName("user").setDescription("The user to manage").setRequired(true)); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 14 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 15 | const generateFromTrack = (position: number, active: string | boolean, size: number, disabled: string | boolean) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | active = active ? "ACTIVE" : "INACTIVE"; |
| 17 | disabled = disabled ? "GREY." : ""; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 18 | if (position === 0 && size === 1) return "TRACKS.SINGLE." + disabled + active; |
| 19 | if (position === size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | if (position === 0) return "TRACKS.VERTICAL.TOP." + disabled + active; |
| 21 | return "TRACKS.VERTICAL.MIDDLE." + disabled + active; |
| 22 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 23 | |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 24 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 25 | const { renderUser } = client.logger; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 26 | const member = interaction.options.getMember("user") as GuildMember; |
| 27 | const guild = interaction.guild; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | if (!guild) return; |
| 29 | const config = await client.database.guilds.read(guild.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 30 | await interaction.reply({ embeds: LoadingEmbed, ephemeral: true }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | let track = 0; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 32 | let generated; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 33 | const roles = await guild.roles.fetch(); |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 34 | const memberRoles = member.roles; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | let managed: boolean; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 36 | let timedOut = false; |
| 37 | while (!timedOut) { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 38 | const data = config.tracks[track]!; |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 39 | if (data.manageableBy.length) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 40 | managed = data.manageableBy.some((element: string) => { |
| 41 | return memberRoles.cache.has(element); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 42 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 43 | else managed = false; |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 44 | const dropdown = new Discord.StringSelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | .addOptions( |
| 46 | config.tracks.map((option, index) => { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 47 | const hasRoleInTrack = option.track.some((element: string) => { |
| 48 | return memberRoles.cache.has(element); |
| 49 | }); |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 50 | return new SelectMenuOptionBuilder({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 51 | default: index === track, |
| 52 | label: option.name, |
| 53 | value: index.toString(), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 54 | description: option.track.length === 0 ? "No" : addPlural(option.track.length, "role"), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 55 | emoji: client.emojis.resolve( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 56 | getEmojiByName("TRACKS.SINGLE." + (hasRoleInTrack ? "ACTIVE" : "INACTIVE"), "id") |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 57 | ) as APIMessageComponentEmoji |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 58 | }); |
| 59 | }) |
| 60 | ) |
| 61 | .setCustomId("select") |
| 62 | .setMaxValues(1); |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 63 | const allowed: boolean[] = []; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 64 | generated = "**Track:** " + data.name + "\n" + "**Member:** " + renderUser(member.user) + "\n"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 65 | generated += |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 66 | (data.nullable ? "Members do not need a role in this track" : "A role in this track is required") + "\n"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 67 | generated += |
| 68 | (data.retainPrevious |
| 69 | ? "When promoted, the user keeps previous roles" |
| 70 | : "Members will lose their current role when promoted") + "\n"; |
| 71 | generated += |
| 72 | "\n" + |
| 73 | data.track |
| 74 | .map((role, index) => { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 75 | const allow: boolean = |
| 76 | roles.get(role)!.position >= (interaction.member as GuildMember).roles.highest.position && |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 77 | !managed; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 78 | allowed.push(!allow); |
| 79 | return ( |
| 80 | getEmojiByName( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 81 | generateFromTrack(index, memberRoles.cache.has(role), data.track.length, allow) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | ) + |
| 83 | " " + |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 84 | roles.get(role)!.name + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 85 | " [<@&" + |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 86 | roles.get(role)!.id + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 87 | ">]" |
| 88 | ); |
| 89 | }) |
| 90 | .join("\n"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 91 | const selected = []; |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 92 | for (const position of data.track) { |
| 93 | if (memberRoles.cache.has(position)) selected.push(position); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 94 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 95 | const conflict = data.retainPrevious ? false : selected.length > 1; |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 96 | let conflictDropdown: StringSelectMenuBuilder[] = []; |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 97 | const conflictDropdownOptions: SelectMenuOptionBuilder[] = []; |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 98 | let currentRoleIndex: number = -1; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 99 | if (conflict) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 100 | generated += `\n\n${getEmojiByName(`PUNISH.WARN.${managed ? "YELLOW" : "RED"}`)} This user has ${ |
| 101 | selected.length |
| 102 | } roles from this track. `; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 103 | conflictDropdown = []; |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 104 | if (roles.get(selected[0]!)!.position < memberRoles.highest.position || managed) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 105 | generated += |
| 106 | "In order to promote or demote this user, you must select which role the member should keep."; |
| 107 | selected.forEach((role) => { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 108 | conflictDropdownOptions.push( |
| 109 | new SelectMenuOptionBuilder({ |
| 110 | label: roles.get(role)!.name, |
| 111 | value: roles.get(role)!.id |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 112 | }) |
| 113 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 114 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 115 | conflictDropdown = [ |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 116 | new Discord.StringSelectMenuBuilder() |
| 117 | .addOptions(conflictDropdownOptions) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 118 | .setCustomId("conflict") |
| 119 | .setMaxValues(1) |
| 120 | .setPlaceholder("Select a role to keep") |
| 121 | ]; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 122 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | generated += |
| 124 | "You don't have permission to manage one or more of the users roles, and therefore can't select one to keep."; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 125 | } |
| 126 | } else { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 127 | currentRoleIndex = selected.length === 0 ? -1 : data.track.indexOf(selected[0]!.toString()); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 128 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 129 | const m = (await interaction.editReply({ |
| 130 | embeds: [ |
| 131 | new EmojiEmbed() |
| 132 | .setEmoji("TRACKS.ICON") |
| 133 | .setTitle("Tracks") |
| 134 | .setDescription(`${generated}`) |
| 135 | .setStatus("Success") |
| 136 | ], |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 137 | components: [new ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>().addComponents(dropdown)] |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 138 | .concat( |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 139 | conflict && conflictDropdown.length ? [new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(conflictDropdown)] : [] |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 140 | ) |
| 141 | .concat([ |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 142 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 143 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 144 | .setEmoji(getEmojiByName("CONTROL.UP", "id")) |
| 145 | .setLabel("Move up") |
| 146 | .setCustomId("promote") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 147 | .setStyle(ButtonStyle.Success) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 148 | .setDisabled( |
| 149 | conflict || |
| 150 | currentRoleIndex === 0 || |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 151 | (currentRoleIndex === -1 ? false : !allowed[currentRoleIndex - 1]) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 152 | ), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 153 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 154 | .setEmoji(getEmojiByName("CONTROL.DOWN", "id")) |
| 155 | .setLabel("Move down") |
| 156 | .setCustomId("demote") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 157 | .setStyle(ButtonStyle.Danger) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 158 | .setDisabled( |
| 159 | conflict || |
| 160 | (data.nullable |
| 161 | ? currentRoleIndex <= -1 |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 162 | : currentRoleIndex === data.track.length - 1 || currentRoleIndex <= -1) || |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 163 | !allowed[currentRoleIndex] |
| 164 | ) |
| 165 | ]) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 166 | ]) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 167 | })) as Message; |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 168 | let component: MessageComponentInteraction; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 169 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 170 | component = await m.awaitMessageComponent({ |
| 171 | time: 300000, |
| 172 | filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id } |
| 173 | }); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 174 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 175 | timedOut = true; |
| 176 | continue; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 177 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 178 | component.deferUpdate(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 179 | if (component.customId === "conflict") { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 180 | const rolesToRemove = selected.filter((role) => role !== (component as StringSelectMenuInteraction).values[0]); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 181 | await member.roles.remove(rolesToRemove); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 182 | } else if (component.customId === "promote") { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 183 | if ( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 184 | currentRoleIndex === -1 |
| 185 | ? allowed[data.track.length - 1] |
| 186 | : allowed[currentRoleIndex - 1] && allowed[currentRoleIndex] |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 187 | ) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 188 | if (currentRoleIndex === -1) { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 189 | await member.roles.add(data.track[data.track.length - 1]!); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 190 | } else if (currentRoleIndex < data.track.length) { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 191 | if (!data.retainPrevious) await member.roles.remove(data.track[currentRoleIndex]!); |
| 192 | await member.roles.add(data.track[currentRoleIndex - 1]!); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 193 | } |
| 194 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 195 | } else if (component.customId === "demote") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 196 | if (allowed[currentRoleIndex]) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 197 | if (currentRoleIndex === data.track.length - 1) { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 198 | if (data.nullable) await member.roles.remove(data.track[currentRoleIndex]!); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 199 | } else if (currentRoleIndex > -1) { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 200 | await member.roles.remove(data.track[currentRoleIndex]!); |
| 201 | await member.roles.add(data.track[currentRoleIndex + 1]!); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 202 | } |
| 203 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 204 | } else if (component.customId === "select") { |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 205 | track = parseInt((component as StringSelectMenuInteraction).values[0]!); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 206 | } |
| 207 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 208 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 209 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 210 | const check = async (interaction: CommandInteraction) => { |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 211 | const tracks = (await client.database.guilds.read(interaction.guild!.id)).tracks; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 212 | if (tracks.length === 0) throw new Error("This server does not have any tracks"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 213 | const member = interaction.member as GuildMember; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 214 | // Allow the owner to promote anyone |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 215 | if (member.id === interaction.guild!.ownerId) return true; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 216 | // Check if the user can manage any of the tracks |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 217 | let managed = false; |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 218 | const memberRoles = member.roles.cache.map((r) => r.id) |
pineafan | c1c1879 | 2022-08-03 21:41:36 +0100 | [diff] [blame] | 219 | for (const element of tracks) { |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 220 | if (!element.manageableBy.length) continue; |
| 221 | if (!element.manageableBy.some((role: string) => memberRoles.includes(role))) continue; |
pineafan | c1c1879 | 2022-08-03 21:41:36 +0100 | [diff] [blame] | 222 | managed = true; |
| 223 | break; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 224 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 225 | // Check if the user has manage_roles permission |
TheCodedProf | 2ec2ba6 | 2023-01-18 22:26:20 -0500 | [diff] [blame] | 226 | if (!managed && !member.permissions.has("ManageRoles")) |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 227 | throw new Error("You do not have the *Manage Roles* permission"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 228 | // Allow track |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 229 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 230 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 231 | |
| 232 | export { command }; |
| 233 | export { callback }; |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 234 | export { check }; |