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) { |
PineaFan | a6e3793 | 2023-09-25 22:09:08 +0100 | [diff] [blame^] | 87 | let formattedReason: string | null = null; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 88 | if (reason) { |
PineaFan | a6e3793 | 2023-09-25 22:09:08 +0100 | [diff] [blame^] | 89 | formattedReason = reason |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 90 | .split("\n") |
| 91 | .map((line) => "> " + line) |
| 92 | .join("\n"); |
| 93 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 94 | const messageData: { |
| 95 | embeds: EmojiEmbed[]; |
| 96 | components: ActionRowBuilder<ButtonBuilder>[]; |
| 97 | } = { |
| 98 | embeds: [ |
| 99 | new EmojiEmbed() |
| 100 | .setEmoji("PUNISH.WARN.RED") |
| 101 | .setTitle("Warned") |
| 102 | .setDescription( |
| 103 | `You have been warned in ${interaction.guild.name}` + |
PineaFan | a6e3793 | 2023-09-25 22:09:08 +0100 | [diff] [blame^] | 104 | (formattedReason ? ` for:\n${formattedReason}` : ".\n*No reason was provided*") + |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 105 | "\n\n" + |
| 106 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 107 | ? `You can appeal this in the ticket created in <#${ |
| 108 | confirmation.components!["appeal"]!.response |
| 109 | }>` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 110 | : "") |
| 111 | ) |
| 112 | .setStatus("Danger") |
| 113 | ], |
| 114 | components: [] |
| 115 | }; |
| 116 | if (config.moderation.warn.text && config.moderation.warn.link) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 117 | messageData.embeds[0]!.setFooter(LinkWarningFooter); |
| 118 | messageData.components.push( |
| 119 | new ActionRowBuilder<Discord.ButtonBuilder>().addComponents( |
| 120 | new ButtonBuilder() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 121 | .setStyle(ButtonStyle.Link) |
| 122 | .setLabel(config.moderation.warn.text) |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 123 | .setURL(config.moderation.warn.link.replaceAll("{id}", member.id)) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 124 | ) |
| 125 | ); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 126 | } |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 127 | await member.send(messageData); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 128 | dmSent = true; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 129 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 130 | } catch (e) { |
| 131 | dmSent = false; |
| 132 | } |
| 133 | const data = { |
| 134 | meta: { |
| 135 | type: "memberWarn", |
| 136 | displayName: "Member warned", |
| 137 | calculateType: "guildMemberPunish", |
| 138 | color: NucleusColors.yellow, |
| 139 | emoji: "PUNISH.WARN.YELLOW", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 140 | timestamp: Date.now() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 141 | }, |
| 142 | list: { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 143 | user: entry(member.user.id, renderUser(member.user)), |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 144 | warnedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)), |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 145 | reason: reason ? reason : "*No reason provided*" |
| 146 | }, |
| 147 | separate: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 148 | end: |
| 149 | getEmojiByName("ICONS.NOTIFY." + (notify ? "ON" : "OFF")) + |
| 150 | ` The user was ${notify ? "" : "not "}notified` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 151 | }, |
| 152 | hidden: { |
| 153 | guild: interaction.guild.id |
| 154 | } |
| 155 | }; |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 156 | 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] | 157 | await log(data); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 158 | const failed = !dmSent && notify; |
| 159 | if (!failed) { |
| 160 | await interaction.editReply({ |
| 161 | embeds: [ |
| 162 | new EmojiEmbed() |
| 163 | .setEmoji("PUNISH.WARN.GREEN") |
| 164 | .setTitle("Warn") |
| 165 | .setDescription( |
| 166 | "The user was warned" + |
| 167 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 168 | ? ` and an appeal ticket was opened in <#${ |
| 169 | confirmation.components!["appeal"]!.response |
| 170 | }>` |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 171 | : "") |
| 172 | ) |
| 173 | .setStatus("Success") |
| 174 | ], |
| 175 | components: [] |
| 176 | }); |
| 177 | } else { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 178 | const canSeeChannel = member.permissionsIn(interaction.channel as Discord.TextChannel).has("ViewChannel"); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 179 | const m = (await interaction.editReply({ |
| 180 | embeds: [ |
| 181 | new EmojiEmbed() |
| 182 | .setEmoji("PUNISH.WARN.RED") |
| 183 | .setTitle("Warn") |
| 184 | .setDescription("The user's DMs are not open\n\nWhat would you like to do?") |
| 185 | .setStatus("Danger") |
| 186 | ], |
| 187 | components: [ |
| 188 | new ActionRowBuilder<Discord.ButtonBuilder>().addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 189 | new Discord.ButtonBuilder() |
| 190 | .setCustomId("log") |
| 191 | .setLabel("Ignore and log") |
| 192 | .setStyle(ButtonStyle.Secondary), |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 193 | new Discord.ButtonBuilder() |
| 194 | .setCustomId("here") |
| 195 | .setLabel("Warn here") |
| 196 | .setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary) |
| 197 | .setDisabled(!canSeeChannel), |
| 198 | new Discord.ButtonBuilder() |
| 199 | .setCustomId("ticket") |
| 200 | .setLabel("Create ticket") |
| 201 | .setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary) |
| 202 | .setDisabled(createAppealTicket) |
| 203 | ) |
| 204 | ] |
| 205 | })) as Discord.Message; |
| 206 | let component; |
| 207 | try { |
| 208 | component = await m.awaitMessageComponent({ |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 209 | filter: (i) => |
| 210 | 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] | 211 | time: 300000 |
| 212 | }); |
| 213 | } catch (e) { |
| 214 | return await interaction.editReply({ |
| 215 | embeds: [ |
| 216 | new EmojiEmbed() |
| 217 | .setEmoji("PUNISH.WARN.GREEN") |
| 218 | .setTitle("Warn") |
| 219 | .setDescription("No changes were made") |
| 220 | .setStatus("Success") |
| 221 | ], |
| 222 | components: [] |
| 223 | }); |
| 224 | } |
| 225 | if (component.customId === "here") { |
| 226 | await interaction.channel!.send({ |
| 227 | embeds: [ |
| 228 | new EmojiEmbed() |
| 229 | .setEmoji("PUNISH.WARN.RED") |
| 230 | .setTitle("Warn") |
| 231 | .setDescription("You have been warned" + (reason ? ` for:\n> ${reason}` : ".")) |
| 232 | .setStatus("Danger") |
| 233 | ], |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 234 | content: `<@!${member.id}>`, |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 235 | allowedMentions: { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 236 | users: [member.id] |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 237 | } |
| 238 | }); |
| 239 | return await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 240 | embeds: [ |
| 241 | new EmojiEmbed() |
| 242 | .setEmoji("PUNISH.WARN.GREEN") |
| 243 | .setTitle("Warn") |
| 244 | .setDescription( |
| 245 | "The user was warned" + |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 246 | (createAppealTicket |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 247 | ? ` and an appeal ticket was opened in <#${ |
| 248 | confirmation.components!["appeal"]!.response |
| 249 | }>` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 250 | : "") |
| 251 | ) |
| 252 | .setStatus("Success") |
| 253 | ], |
| 254 | components: [] |
| 255 | }); |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 256 | } else if (component.customId === "log") { |
| 257 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 258 | embeds: [ |
| 259 | new EmojiEmbed() |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 260 | .setEmoji("PUNISH.WARN.GREEN") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 261 | .setTitle("Warn") |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 262 | .setDescription("The warn was logged") |
| 263 | .setStatus("Success") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 264 | ], |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 265 | components: [] |
| 266 | }); |
| 267 | } else if (component.customId === "ticket") { |
| 268 | const ticketChannel = await create( |
| 269 | interaction.guild, |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 270 | member.user, |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 271 | interaction.user, |
| 272 | reason, |
| 273 | "Warn Notification" |
| 274 | ); |
| 275 | if (ticketChannel === null) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 276 | return await interaction.editReply({ |
| 277 | embeds: [ |
| 278 | new EmojiEmbed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 279 | .setEmoji("PUNISH.WARN.RED") |
| 280 | .setTitle("Warn") |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 281 | .setDescription("A ticket could not be created") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 282 | .setStatus("Danger") |
| 283 | ], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 284 | components: [] |
| 285 | }); |
| 286 | } |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 287 | await interaction.editReply({ |
| 288 | embeds: [ |
| 289 | new EmojiEmbed() |
| 290 | .setEmoji("PUNISH.WARN.GREEN") |
| 291 | .setTitle("Warn") |
| 292 | .setDescription(`A ticket was created in <#${ticketChannel}>`) |
| 293 | .setStatus("Success") |
| 294 | ], |
| 295 | components: [] |
| 296 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 297 | } |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 298 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 299 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 300 | |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 301 | const check = (interaction: CommandInteraction | ButtonInteraction, partial: boolean = false, target?: GuildMember) => { |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 302 | if (!interaction.guild) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 303 | const member = interaction.member as GuildMember; |
TheCodedProf | a9e3e03 | 2023-04-22 17:32:19 -0400 | [diff] [blame] | 304 | if (!member.permissions.has("ManageMessages")) return "You do not have the *Manage Messages* permission"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 305 | if (partial) return true; |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 306 | let apply: GuildMember; |
| 307 | if (interaction.isButton()) { |
| 308 | apply = target!; |
| 309 | } else { |
| 310 | apply = interaction.options.getMember("user") as GuildMember; |
| 311 | } |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 312 | const memberPos = member.roles.cache.size ? member.roles.highest.position : 0; |
| 313 | const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 314 | // Do not allow warning bots |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 315 | if (member.user.bot) return "I cannot warn bots"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 316 | // Allow the owner to warn anyone |
PineaFan | a00db1b | 2023-01-02 15:32:54 +0000 | [diff] [blame] | 317 | if (member.id === interaction.guild.ownerId) return true; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 318 | // Check if the user has moderate_members permission |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 319 | // Check if the user is below on the role list |
TheCodedProf | 0941da4 | 2023-02-18 20:28:04 -0500 | [diff] [blame] | 320 | 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] | 321 | // Allow warn |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 322 | return true; |
| 323 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 324 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 325 | export { command, callback, check }; |