pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 1 | import Discord, { |
| 2 | CommandInteraction, |
| 3 | GuildMember, |
| 4 | ActionRowBuilder, |
| 5 | ButtonBuilder, |
| 6 | ButtonStyle, |
| 7 | ButtonInteraction |
| 8 | } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 9 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 10 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 11 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 12 | import keyValueList from "../../utils/generateKeyValueList.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 13 | import { create, areTicketsEnabled } from "../../actions/createModActionTicket.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | import client from "../../utils/client.js"; |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 15 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 16 | import { LinkWarningFooter } from "../../utils/defaults.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 17 | |
| 18 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 19 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | .setName("warn") |
| 21 | .setDescription("Warns a user") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 22 | .addUserOption((option) => option.setName("user").setDescription("The user to warn").setRequired(true)); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 23 | |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 24 | const callback = async ( |
| 25 | interaction: CommandInteraction | ButtonInteraction, |
| 26 | member?: GuildMember |
| 27 | ): Promise<unknown> => { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 28 | if (!interaction.guild) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | const { log, NucleusColors, renderUser, entry } = client.logger; |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 30 | if (!interaction.isButton()) member = interaction.options.getMember("user") as GuildMember; |
| 31 | if (!member) return; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 32 | // TODO:[Modals] Replace this with a modal |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 33 | let reason: string | null = null; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 34 | let notify = true; |
| 35 | let createAppealTicket = false; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 36 | let confirmation; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 37 | let timedOut = false; |
| 38 | let success = false; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 39 | do { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 40 | confirmation = await new confirmationMessage(interaction) |
| 41 | .setEmoji("PUNISH.WARN.RED") |
| 42 | .setTitle("Warn") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 43 | .setDescription( |
| 44 | keyValueList({ |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 45 | user: renderUser(member.user), |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 46 | reason: reason ? "\n> " + reason.replaceAll("\n", "\n> ") : "*No reason provided*" |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 47 | }) + `Are you sure you want to warn <@!${member.id}>?` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | ) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 49 | .setColor("Danger") |
| 50 | .addCustomBoolean( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 51 | "appeal", |
| 52 | "Create appeal ticket", |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 53 | !(await areTicketsEnabled(interaction.guild.id)), |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 54 | async () => await create(interaction.guild!, member!.user, interaction.user, reason), |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 55 | "An appeal ticket will be created", |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 56 | null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 57 | "CONTROL.TICKET", |
| 58 | createAppealTicket |
| 59 | ) |
| 60 | .addCustomBoolean( |
| 61 | "notify", |
| 62 | "Notify user", |
| 63 | false, |
| 64 | null, |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 65 | "The user will be sent a DM", |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 66 | null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 67 | "ICONS.NOTIFY." + (notify ? "ON" : "OFF"), |
| 68 | notify |
| 69 | ) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 70 | .addReasonButton(reason ?? "") |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 71 | .setFailedMessage("No changes were made", "Success", "PUNISH.WARN.GREEN") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 72 | .send(reason !== null); |
| 73 | reason = reason ?? ""; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 74 | if (confirmation.cancelled) timedOut = true; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 75 | else if (confirmation.success !== undefined) success = true; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 76 | else if (confirmation.newReason) reason = confirmation.newReason; |
| 77 | else if (confirmation.components) { |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 78 | notify = confirmation.components["notify"]!.active; |
| 79 | createAppealTicket = confirmation.components["appeal"]!.active; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 80 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 81 | } while (!timedOut && !success); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 82 | if (timedOut || !success) return; |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 83 | let dmSent = false; |
| 84 | const config = await client.database.guilds.read(interaction.guild.id); |
| 85 | try { |
| 86 | if (notify) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 87 | if (reason) { |
| 88 | reason = reason |
| 89 | .split("\n") |
| 90 | .map((line) => "> " + line) |
| 91 | .join("\n"); |
| 92 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 93 | const messageData: { |
| 94 | embeds: EmojiEmbed[]; |
| 95 | components: ActionRowBuilder<ButtonBuilder>[]; |
| 96 | } = { |
| 97 | embeds: [ |
| 98 | new EmojiEmbed() |
| 99 | .setEmoji("PUNISH.WARN.RED") |
| 100 | .setTitle("Warned") |
| 101 | .setDescription( |
| 102 | `You have been warned in ${interaction.guild.name}` + |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 103 | (reason ? ` for:\n${reason}` : ".\n*No reason was provided*") + |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 104 | "\n\n" + |
| 105 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 106 | ? `You can appeal this in the ticket created in <#${ |
| 107 | confirmation.components!["appeal"]!.response |
| 108 | }>` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 109 | : "") |
| 110 | ) |
| 111 | .setStatus("Danger") |
| 112 | ], |
| 113 | components: [] |
| 114 | }; |
| 115 | if (config.moderation.warn.text && config.moderation.warn.link) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 116 | messageData.embeds[0]!.setFooter(LinkWarningFooter); |
| 117 | messageData.components.push( |
| 118 | new ActionRowBuilder<Discord.ButtonBuilder>().addComponents( |
| 119 | new ButtonBuilder() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 120 | .setStyle(ButtonStyle.Link) |
| 121 | .setLabel(config.moderation.warn.text) |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 122 | .setURL(config.moderation.warn.link.replaceAll("{id}", member.id)) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 123 | ) |
| 124 | ); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 125 | } |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 126 | await member.send(messageData); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 127 | dmSent = true; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 128 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 129 | } catch (e) { |
| 130 | dmSent = false; |
| 131 | } |
| 132 | const data = { |
| 133 | meta: { |
| 134 | type: "memberWarn", |
| 135 | displayName: "Member warned", |
| 136 | calculateType: "guildMemberPunish", |
| 137 | color: NucleusColors.yellow, |
| 138 | emoji: "PUNISH.WARN.YELLOW", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 139 | timestamp: Date.now() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 140 | }, |
| 141 | list: { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 142 | user: entry(member.user.id, renderUser(member.user)), |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 143 | warnedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)), |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 144 | reason: reason ? reason : "*No reason provided*" |
| 145 | }, |
| 146 | separate: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 147 | end: |
| 148 | getEmojiByName("ICONS.NOTIFY." + (notify ? "ON" : "OFF")) + |
| 149 | ` The user was ${notify ? "" : "not "}notified` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 150 | }, |
| 151 | hidden: { |
| 152 | guild: interaction.guild.id |
| 153 | } |
| 154 | }; |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 155 | await client.database.history.create("warn", interaction.guild.id, member.user, interaction.user, reason); |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 156 | await log(data); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 157 | const failed = !dmSent && notify; |
| 158 | if (!failed) { |
| 159 | await interaction.editReply({ |
| 160 | embeds: [ |
| 161 | new EmojiEmbed() |
| 162 | .setEmoji("PUNISH.WARN.GREEN") |
| 163 | .setTitle("Warn") |
| 164 | .setDescription( |
| 165 | "The user was warned" + |
| 166 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 167 | ? ` and an appeal ticket was opened in <#${ |
| 168 | confirmation.components!["appeal"]!.response |
| 169 | }>` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 170 | : "") |
| 171 | ) |
| 172 | .setStatus("Success") |
| 173 | ], |
| 174 | components: [] |
| 175 | }); |
| 176 | } else { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 177 | const canSeeChannel = member.permissionsIn(interaction.channel as Discord.TextChannel).has("ViewChannel"); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 178 | const m = (await interaction.editReply({ |
| 179 | embeds: [ |
| 180 | new EmojiEmbed() |
| 181 | .setEmoji("PUNISH.WARN.RED") |
| 182 | .setTitle("Warn") |
| 183 | .setDescription("The user's DMs are not open\n\nWhat would you like to do?") |
| 184 | .setStatus("Danger") |
| 185 | ], |
| 186 | components: [ |
| 187 | new ActionRowBuilder<Discord.ButtonBuilder>().addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 188 | new Discord.ButtonBuilder() |
| 189 | .setCustomId("log") |
| 190 | .setLabel("Ignore and log") |
| 191 | .setStyle(ButtonStyle.Secondary), |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 192 | new Discord.ButtonBuilder() |
| 193 | .setCustomId("here") |
| 194 | .setLabel("Warn here") |
| 195 | .setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary) |
| 196 | .setDisabled(!canSeeChannel), |
| 197 | new Discord.ButtonBuilder() |
| 198 | .setCustomId("ticket") |
| 199 | .setLabel("Create ticket") |
| 200 | .setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary) |
| 201 | .setDisabled(createAppealTicket) |
| 202 | ) |
| 203 | ] |
| 204 | })) as Discord.Message; |
| 205 | let component; |
| 206 | try { |
| 207 | component = await m.awaitMessageComponent({ |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 208 | filter: (i) => |
| 209 | i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.id === m.id, |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 210 | time: 300000 |
| 211 | }); |
| 212 | } catch (e) { |
| 213 | return await interaction.editReply({ |
| 214 | embeds: [ |
| 215 | new EmojiEmbed() |
| 216 | .setEmoji("PUNISH.WARN.GREEN") |
| 217 | .setTitle("Warn") |
| 218 | .setDescription("No changes were made") |
| 219 | .setStatus("Success") |
| 220 | ], |
| 221 | components: [] |
| 222 | }); |
| 223 | } |
| 224 | if (component.customId === "here") { |
| 225 | await interaction.channel!.send({ |
| 226 | embeds: [ |
| 227 | new EmojiEmbed() |
| 228 | .setEmoji("PUNISH.WARN.RED") |
| 229 | .setTitle("Warn") |
| 230 | .setDescription("You have been warned" + (reason ? ` for:\n> ${reason}` : ".")) |
| 231 | .setStatus("Danger") |
| 232 | ], |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 233 | content: `<@!${member.id}>`, |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 234 | allowedMentions: { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 235 | users: [member.id] |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 236 | } |
| 237 | }); |
| 238 | return await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 239 | embeds: [ |
| 240 | new EmojiEmbed() |
| 241 | .setEmoji("PUNISH.WARN.GREEN") |
| 242 | .setTitle("Warn") |
| 243 | .setDescription( |
| 244 | "The user was warned" + |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 245 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 246 | ? ` and an appeal ticket was opened in <#${ |
| 247 | confirmation.components!["appeal"]!.response |
| 248 | }>` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 249 | : "") |
| 250 | ) |
| 251 | .setStatus("Success") |
| 252 | ], |
| 253 | components: [] |
| 254 | }); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 255 | } else if (component.customId === "log") { |
| 256 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 257 | embeds: [ |
| 258 | new EmojiEmbed() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 259 | .setEmoji("PUNISH.WARN.GREEN") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 260 | .setTitle("Warn") |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 261 | .setDescription("The warn was logged") |
| 262 | .setStatus("Success") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 263 | ], |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 264 | components: [] |
| 265 | }); |
| 266 | } else if (component.customId === "ticket") { |
| 267 | const ticketChannel = await create( |
| 268 | interaction.guild, |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 269 | member.user, |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 270 | interaction.user, |
| 271 | reason, |
| 272 | "Warn Notification" |
| 273 | ); |
| 274 | if (ticketChannel === null) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 275 | return await interaction.editReply({ |
| 276 | embeds: [ |
| 277 | new EmojiEmbed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 278 | .setEmoji("PUNISH.WARN.RED") |
| 279 | .setTitle("Warn") |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 280 | .setDescription("A ticket could not be created") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 281 | .setStatus("Danger") |
| 282 | ], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 283 | components: [] |
| 284 | }); |
| 285 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 286 | await interaction.editReply({ |
| 287 | embeds: [ |
| 288 | new EmojiEmbed() |
| 289 | .setEmoji("PUNISH.WARN.GREEN") |
| 290 | .setTitle("Warn") |
| 291 | .setDescription(`A ticket was created in <#${ticketChannel}>`) |
| 292 | .setStatus("Success") |
| 293 | ], |
| 294 | components: [] |
| 295 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 296 | } |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 297 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 298 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 299 | |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 300 | const check = (interaction: CommandInteraction | ButtonInteraction, partial: boolean = false, target?: GuildMember) => { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 301 | if (!interaction.guild) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 302 | const member = interaction.member as GuildMember; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 303 | if (!member.permissions.has("ModerateMembers")) return "You do not have the *Moderate Members* permission"; |
| 304 | if (partial) return true; |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 305 | let apply: GuildMember; |
| 306 | if (interaction.isButton()) { |
| 307 | apply = target!; |
| 308 | } else { |
| 309 | apply = interaction.options.getMember("user") as GuildMember; |
| 310 | } |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 311 | const memberPos = member.roles.cache.size ? member.roles.highest.position : 0; |
| 312 | const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 313 | // Do not allow warning bots |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 314 | if (member.user.bot) return "I cannot warn bots"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 315 | // Allow the owner to warn anyone |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 316 | if (member.id === interaction.guild.ownerId) return true; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 317 | // Check if the user has moderate_members permission |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 318 | // Check if the user is below on the role list |
TheCodedProf | 0941da4 | 2023-02-18 20:28:04 -0500 | [diff] [blame] | 319 | if (!(memberPos > applyPos)) return `You do not have a role higher than <@${apply.id}>`; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 320 | // Allow warn |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 321 | return true; |
| 322 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 323 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 324 | export { command, callback, check }; |