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