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