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