pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../utils/defaultEmbeds.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 2 | import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js"; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [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 | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 5 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 6 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
| 7 | import keyValueList from "../../utils/generateKeyValueList.js"; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 8 | // @ts-expect-error |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 9 | import humanizeDuration from "humanize-duration"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 10 | import client from "../../utils/client.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 11 | import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 12 | |
| 13 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 14 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | .setName("mute") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 16 | .setDescription("Mutes a member, stopping them from talking in the server") |
| 17 | .addUserOption((option) => option.setName("user").setDescription("The user to mute").setRequired(true)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 18 | .addIntegerOption((option) => |
| 19 | option |
| 20 | .setName("days") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 21 | .setDescription("The number of days to mute the user for | Default: 0") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | .setMinValue(0) |
| 23 | .setMaxValue(27) |
| 24 | .setRequired(false) |
| 25 | ) |
| 26 | .addIntegerOption((option) => |
| 27 | option |
| 28 | .setName("hours") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 29 | .setDescription("The number of hours to mute the user for | Default: 0") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 30 | .setMinValue(0) |
| 31 | .setMaxValue(23) |
| 32 | .setRequired(false) |
| 33 | ) |
| 34 | .addIntegerOption((option) => |
| 35 | option |
| 36 | .setName("minutes") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 37 | .setDescription("The number of minutes to mute the user for | Default: 0") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 38 | .setMinValue(0) |
| 39 | .setMaxValue(59) |
| 40 | .setRequired(false) |
| 41 | ) |
| 42 | .addIntegerOption((option) => |
| 43 | option |
| 44 | .setName("seconds") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 45 | .setDescription("The number of seconds to mute the user for | Default: 0") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 46 | .setMinValue(0) |
| 47 | .setMaxValue(59) |
| 48 | .setRequired(false) |
| 49 | ); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 50 | |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 51 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 52 | const { log, NucleusColors, renderUser, entry, renderDelta } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 53 | const user = interaction.options.getMember("user") as GuildMember; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 54 | const time = { |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 55 | days: interaction.options.getInteger("days") ?? 0, |
| 56 | hours: interaction.options.getInteger("hours") ?? 0, |
| 57 | minutes: interaction.options.getInteger("minutes") ?? 0, |
| 58 | seconds: interaction.options.getInteger("seconds") ?? 0 |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 59 | }; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 60 | const config = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 61 | let serverSettingsDescription = config.moderation.mute.timeout ? "given a timeout" : ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 62 | if (config.moderation.mute.role) |
| 63 | serverSettingsDescription += |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 64 | (serverSettingsDescription ? " and " : "") + `given the <@&${config.moderation.mute.role}> role`; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 65 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 66 | let muteTime = time.days * 24 * 60 * 60 + time.hours * 60 * 60 + time.minutes * 60 + time.seconds; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 67 | if (muteTime === 0) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 68 | const m = (await interaction.reply({ |
| 69 | embeds: [ |
| 70 | new EmojiEmbed() |
| 71 | .setEmoji("PUNISH.MUTE.GREEN") |
| 72 | .setTitle("Mute") |
| 73 | .setDescription("How long should the user be muted") |
| 74 | .setStatus("Success") |
| 75 | ], |
| 76 | components: [ |
| 77 | new MessageActionRow().addComponents([ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 78 | new Discord.MessageButton().setCustomId("1m").setLabel("1 Minute").setStyle("SECONDARY"), |
| 79 | new Discord.MessageButton().setCustomId("10m").setLabel("10 Minutes").setStyle("SECONDARY"), |
| 80 | new Discord.MessageButton().setCustomId("30m").setLabel("30 Minutes").setStyle("SECONDARY"), |
| 81 | new Discord.MessageButton().setCustomId("1h").setLabel("1 Hour").setStyle("SECONDARY") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | ]), |
| 83 | new MessageActionRow().addComponents([ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 84 | new Discord.MessageButton().setCustomId("6h").setLabel("6 Hours").setStyle("SECONDARY"), |
| 85 | new Discord.MessageButton().setCustomId("12h").setLabel("12 Hours").setStyle("SECONDARY"), |
| 86 | new Discord.MessageButton().setCustomId("1d").setLabel("1 Day").setStyle("SECONDARY"), |
| 87 | new Discord.MessageButton().setCustomId("1w").setLabel("1 Week").setStyle("SECONDARY") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | ]), |
| 89 | new MessageActionRow().addComponents([ |
| 90 | new Discord.MessageButton() |
| 91 | .setCustomId("cancel") |
| 92 | .setLabel("Cancel") |
| 93 | .setStyle("DANGER") |
| 94 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 95 | ]) |
| 96 | ], |
| 97 | ephemeral: true, |
| 98 | fetchReply: true |
| 99 | })) as Message; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 100 | let component; |
| 101 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 102 | component = await m.awaitMessageComponent({ |
| 103 | filter: (m) => m.user.id === interaction.user.id, |
| 104 | time: 300000 |
| 105 | }); |
| 106 | } catch { |
| 107 | return; |
| 108 | } |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 109 | component.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 110 | if (component.customId === "cancel") |
| 111 | return interaction.editReply({ |
| 112 | embeds: [ |
| 113 | new EmojiEmbed() |
| 114 | .setEmoji("PUNISH.MUTE.RED") |
| 115 | .setTitle("Mute") |
| 116 | .setDescription("Mute cancelled") |
| 117 | .setStatus("Danger") |
| 118 | ] |
| 119 | }); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 120 | switch (component.customId) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 121 | case "1m": { |
| 122 | muteTime = 60; |
| 123 | break; |
| 124 | } |
| 125 | case "10m": { |
| 126 | muteTime = 60 * 10; |
| 127 | break; |
| 128 | } |
| 129 | case "30m": { |
| 130 | muteTime = 60 * 30; |
| 131 | break; |
| 132 | } |
| 133 | case "1h": { |
| 134 | muteTime = 60 * 60; |
| 135 | break; |
| 136 | } |
| 137 | case "6h": { |
| 138 | muteTime = 60 * 60 * 6; |
| 139 | break; |
| 140 | } |
| 141 | case "12h": { |
| 142 | muteTime = 60 * 60 * 12; |
| 143 | break; |
| 144 | } |
| 145 | case "1d": { |
| 146 | muteTime = 60 * 60 * 24; |
| 147 | break; |
| 148 | } |
| 149 | case "1w": { |
| 150 | muteTime = 60 * 60 * 24 * 7; |
| 151 | break; |
| 152 | } |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 153 | } |
| 154 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 155 | await interaction.reply({ |
| 156 | embeds: LoadingEmbed, |
| 157 | ephemeral: true, |
| 158 | fetchReply: true |
| 159 | }); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 160 | } |
pineafan | 5d1908e | 2022-02-28 21:34:47 +0000 | [diff] [blame] | 161 | // TODO:[Modals] Replace this with a modal |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 162 | let reason: string | null = null; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 163 | let notify = true; |
| 164 | let createAppealTicket = false; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 165 | let confirmation; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 166 | let timedOut = false; |
| 167 | let success = false; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 168 | do { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 169 | confirmation = await new confirmationMessage(interaction) |
| 170 | .setEmoji("PUNISH.MUTE.RED") |
| 171 | .setTitle("Mute") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 172 | .setDescription( |
| 173 | keyValueList({ |
| 174 | user: renderUser(user.user), |
| 175 | time: `${humanizeDuration(muteTime * 1000, { |
| 176 | round: true |
| 177 | })}`, |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 178 | reason: reason ? "\n> " + (reason).replaceAll("\n", "\n> ") : "*No reason provided*" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 179 | }) + |
| 180 | "The user will be " + |
| 181 | serverSettingsDescription + |
| 182 | "\n" + |
| 183 | `The user **will${notify ? "" : " not"}** be notified\n\n` + |
| 184 | `Are you sure you want to mute <@!${user.id}>?` |
| 185 | ) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 186 | .setColor("Danger") |
| 187 | .addCustomBoolean( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 188 | "appeal", |
| 189 | "Create appeal ticket", |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 190 | !(await areTicketsEnabled(interaction.guild!.id)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 191 | async () => |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 192 | await create(interaction.guild!, interaction.options.getUser("user")!, interaction.user, reason), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 193 | "An appeal ticket will be created when Confirm is clicked", |
| 194 | "CONTROL.TICKET", |
| 195 | createAppealTicket |
| 196 | ) |
| 197 | .addCustomBoolean( |
| 198 | "notify", |
| 199 | "Notify user", |
| 200 | false, |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 201 | undefined, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 202 | null, |
| 203 | "ICONS.NOTIFY." + (notify ? "ON" : "OFF"), |
| 204 | notify |
| 205 | ) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 206 | .addReasonButton(reason ?? "") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 207 | .send(true); |
| 208 | reason = reason ?? ""; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 209 | if (confirmation.cancelled) timedOut = true; |
| 210 | if (confirmation.success) success = true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 211 | if (confirmation.newReason) reason = confirmation.newReason; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 212 | if (confirmation.components) { |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 213 | notify = confirmation.components["notify"]!.active; |
| 214 | createAppealTicket = confirmation.components["appeal"]!.active; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 215 | } |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 216 | } while (!timedOut && !success) |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 217 | if (timedOut) return; |
| 218 | let dmd = false; |
| 219 | let dm; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 220 | if (confirmation.success) { |
| 221 | try { |
| 222 | if (notify) { |
| 223 | dm = await user.send({ |
| 224 | embeds: [ |
| 225 | new EmojiEmbed() |
| 226 | .setEmoji("PUNISH.MUTE.RED") |
| 227 | .setTitle("Muted") |
| 228 | .setDescription( |
| 229 | `You have been muted in ${interaction.guild!.name}` + |
| 230 | (reason |
| 231 | ? ` for:\n> ${reason}` |
| 232 | : ".\n\n" + |
| 233 | `You will be unmuted at: <t:${ |
| 234 | Math.round(new Date().getTime() / 1000) + muteTime |
| 235 | }:D> at <t:${Math.round(new Date().getTime() / 1000) + muteTime}:T> (<t:${ |
| 236 | Math.round(new Date().getTime() / 1000) + muteTime |
| 237 | }:R>)`) + |
| 238 | (confirmation.components!["appeal"]!.response |
| 239 | ? `You can appeal this here: <#${confirmation.components!["appeal"]!.response}>` |
| 240 | : "") |
| 241 | ) |
| 242 | .setStatus("Danger") |
| 243 | ], |
| 244 | components: [ |
| 245 | new MessageActionRow().addComponents( |
| 246 | config.moderation.mute.text |
| 247 | ? [ |
| 248 | new MessageButton() |
| 249 | .setStyle("LINK") |
| 250 | .setLabel(config.moderation.mute.text) |
| 251 | .setURL(config.moderation.mute.link) |
| 252 | ] |
| 253 | : [] |
| 254 | ) |
| 255 | ] |
| 256 | }); |
| 257 | dmd = true; |
| 258 | } |
| 259 | } catch { |
| 260 | dmd = false; |
| 261 | } |
| 262 | const member = user; |
| 263 | let errors = 0; |
| 264 | try { |
| 265 | if (config.moderation.mute.timeout) { |
| 266 | await member.timeout(muteTime * 1000, reason || "No reason provided"); |
| 267 | if (config.moderation.mute.role !== null) { |
| 268 | await member.roles.add(config.moderation.mute.role); |
| 269 | await client.database.eventScheduler.schedule("naturalUnmute", new Date().getTime() + muteTime * 1000, { |
| 270 | guild: interaction.guild!.id, |
| 271 | user: user.id, |
| 272 | expires: new Date().getTime() + muteTime * 1000 |
| 273 | }); |
| 274 | } |
| 275 | } |
| 276 | } catch { |
| 277 | errors++; |
| 278 | } |
| 279 | try { |
| 280 | if (config.moderation.mute.role !== null) { |
| 281 | await member.roles.add(config.moderation.mute.role); |
| 282 | await client.database.eventScheduler.schedule("unmuteRole", new Date().getTime() + muteTime * 1000, { |
| 283 | guild: interaction.guild!.id, |
| 284 | user: user.id, |
| 285 | role: config.moderation.mute.role |
| 286 | }); |
| 287 | } |
| 288 | } catch (e) { |
| 289 | console.log(e); |
| 290 | errors++; |
| 291 | } |
| 292 | if (errors === 2) { |
| 293 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 294 | embeds: [ |
| 295 | new EmojiEmbed() |
| 296 | .setEmoji("PUNISH.MUTE.RED") |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 297 | .setTitle("Mute") |
| 298 | .setDescription("Something went wrong and the user was not muted") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 299 | .setStatus("Danger") |
| 300 | ], |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 301 | components: [] |
| 302 | }); // TODO: make this clearer |
| 303 | if (dmd && dm) await dm.delete(); |
| 304 | return; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 305 | } |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 306 | await client.database.history.create("mute", interaction.guild!.id, member.user, interaction.user, reason); |
| 307 | const failed = !dmd && notify; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 308 | await interaction.editReply({ |
| 309 | embeds: [ |
| 310 | new EmojiEmbed() |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 311 | .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 312 | .setTitle("Mute") |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 313 | .setDescription( |
| 314 | "The member was muted" + |
| 315 | (failed ? ", but could not be notified" : "") + |
| 316 | (confirmation.components!["appeal"]!.response |
| 317 | ? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>` |
| 318 | : "") |
| 319 | ) |
| 320 | .setStatus(failed ? "Warning" : "Success") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 321 | ], |
| 322 | components: [] |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 323 | }); |
| 324 | const data = { |
| 325 | meta: { |
| 326 | type: "memberMute", |
| 327 | displayName: "Member Muted", |
| 328 | calculateType: "guildMemberPunish", |
| 329 | color: NucleusColors.yellow, |
| 330 | emoji: "PUNISH.WARN.YELLOW", |
| 331 | timestamp: new Date().getTime() |
| 332 | }, |
| 333 | list: { |
| 334 | memberId: entry(member.user.id, `\`${member.user.id}\``), |
| 335 | name: entry(member.user.id, renderUser(member.user)), |
| 336 | mutedUntil: entry( |
| 337 | new Date().getTime() + muteTime * 1000, |
| 338 | renderDelta(new Date().getTime() + muteTime * 1000) |
| 339 | ), |
| 340 | muted: entry(new Date().getTime(), renderDelta(new Date().getTime() - 1000)), |
| 341 | mutedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user)), |
| 342 | reason: entry(reason, reason ? reason : "*No reason provided*") |
| 343 | }, |
| 344 | hidden: { |
| 345 | guild: interaction.guild!.id |
| 346 | } |
| 347 | }; |
| 348 | log(data); |
| 349 | } else { |
| 350 | await interaction.editReply({ |
| 351 | embeds: [ |
| 352 | new EmojiEmbed() |
| 353 | .setEmoji("PUNISH.BAN.GREEN") |
| 354 | .setTitle("Softban") |
| 355 | .setDescription("No changes were made") |
| 356 | .setStatus("Success") |
| 357 | ], |
| 358 | components: [] |
| 359 | }); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 360 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 361 | }; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 362 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 363 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 364 | const member = interaction.member as GuildMember; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 365 | const me = interaction.guild!.me!; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 366 | const apply = interaction.options.getMember("user") as GuildMember; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 367 | const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0; |
| 368 | const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0; |
| 369 | const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0; |
pineafan | c1c1879 | 2022-08-03 21:41:36 +0100 | [diff] [blame] | 370 | // Do not allow muting the owner |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 371 | if (member.id === interaction.guild!.ownerId) throw new Error("You cannot mute the owner of the server"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 372 | // Check if Nucleus can mute the member |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 373 | if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 374 | // Check if Nucleus has permission to mute |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 375 | if (!me.permissions.has("MODERATE_MEMBERS")) throw new Error("I do not have the *Moderate Members* permission"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 376 | // Do not allow muting Nucleus |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 377 | if (member.id === me.id) throw new Error("I cannot mute myself"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 378 | // Allow the owner to mute anyone |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame^] | 379 | if (member.id === interaction.guild!.ownerId) return true; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 380 | // Check if the user has moderate_members permission |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 381 | if (!member.permissions.has("MODERATE_MEMBERS")) |
| 382 | throw new Error("You do not have the *Moderate Members* permission"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 383 | // Check if the user is below on the role list |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 384 | if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member"); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 385 | // Allow mute |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 386 | return true; |
| 387 | }; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 388 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 389 | export { command, callback, check }; |