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