Bug fixes and ~~performance~~ typing improvements
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index b430191..dc44e5a 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -1,11 +1,5 @@
import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
-import Discord, {
- CommandInteraction,
- GuildMember,
- Message,
- MessageActionRow,
- MessageButton
-} from "discord.js";
+import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
@@ -13,29 +7,17 @@
import keyValueList from "../../utils/generateKeyValueList.js";
import humanizeDuration from "humanize-duration";
import client from "../../utils/client.js";
-import {
- areTicketsEnabled,
- create
-} from "../../actions/createModActionTicket.js";
+import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
.setName("mute")
- .setDescription(
- "Mutes a member, stopping them from talking in the server"
- )
- .addUserOption((option) =>
- option
- .setName("user")
- .setDescription("The user to mute")
- .setRequired(true)
- )
+ .setDescription("Mutes a member, stopping them from talking in the server")
+ .addUserOption((option) => option.setName("user").setDescription("The user to mute").setRequired(true))
.addIntegerOption((option) =>
option
.setName("days")
- .setDescription(
- "The number of days to mute the user for | Default: 0"
- )
+ .setDescription("The number of days to mute the user for | Default: 0")
.setMinValue(0)
.setMaxValue(27)
.setRequired(false)
@@ -43,9 +25,7 @@
.addIntegerOption((option) =>
option
.setName("hours")
- .setDescription(
- "The number of hours to mute the user for | Default: 0"
- )
+ .setDescription("The number of hours to mute the user for | Default: 0")
.setMinValue(0)
.setMaxValue(23)
.setRequired(false)
@@ -53,9 +33,7 @@
.addIntegerOption((option) =>
option
.setName("minutes")
- .setDescription(
- "The number of minutes to mute the user for | Default: 0"
- )
+ .setDescription("The number of minutes to mute the user for | Default: 0")
.setMinValue(0)
.setMaxValue(59)
.setRequired(false)
@@ -63,17 +41,14 @@
.addIntegerOption((option) =>
option
.setName("seconds")
- .setDescription(
- "The number of seconds to mute the user for | Default: 0"
- )
+ .setDescription("The number of seconds to mute the user for | Default: 0")
.setMinValue(0)
.setMaxValue(59)
.setRequired(false)
);
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
- const { log, NucleusColors, renderUser, entry, renderDelta } =
- client.logger;
+ const { log, NucleusColors, renderUser, entry, renderDelta } = client.logger;
const user = interaction.options.getMember("user") as GuildMember;
const time = {
days: interaction.options.getInteger("days") ?? 0,
@@ -82,19 +57,12 @@
seconds: interaction.options.getInteger("seconds") ?? 0
};
const config = await client.database.guilds.read(interaction.guild.id);
- let serverSettingsDescription = config.moderation.mute.timeout
- ? "given a timeout"
- : "";
+ let serverSettingsDescription = config.moderation.mute.timeout ? "given a timeout" : "";
if (config.moderation.mute.role)
serverSettingsDescription +=
- (serverSettingsDescription ? " and " : "") +
- `given the <@&${config.moderation.mute.role}> role`;
+ (serverSettingsDescription ? " and " : "") + `given the <@&${config.moderation.mute.role}> role`;
- let muteTime =
- time.days * 24 * 60 * 60 +
- time.hours * 60 * 60 +
- time.minutes * 60 +
- time.seconds;
+ let muteTime = time.days * 24 * 60 * 60 + time.hours * 60 * 60 + time.minutes * 60 + time.seconds;
if (muteTime === 0) {
const m = (await interaction.reply({
embeds: [
@@ -106,40 +74,16 @@
],
components: [
new MessageActionRow().addComponents([
- new Discord.MessageButton()
- .setCustomId("1m")
- .setLabel("1 Minute")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("10m")
- .setLabel("10 Minutes")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("30m")
- .setLabel("30 Minutes")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("1h")
- .setLabel("1 Hour")
- .setStyle("SECONDARY")
+ new Discord.MessageButton().setCustomId("1m").setLabel("1 Minute").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("10m").setLabel("10 Minutes").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("30m").setLabel("30 Minutes").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("1h").setLabel("1 Hour").setStyle("SECONDARY")
]),
new MessageActionRow().addComponents([
- new Discord.MessageButton()
- .setCustomId("6h")
- .setLabel("6 Hours")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("12h")
- .setLabel("12 Hours")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("1d")
- .setLabel("1 Day")
- .setStyle("SECONDARY"),
- new Discord.MessageButton()
- .setCustomId("1w")
- .setLabel("1 Week")
- .setStyle("SECONDARY")
+ new Discord.MessageButton().setCustomId("6h").setLabel("6 Hours").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("12h").setLabel("12 Hours").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("1d").setLabel("1 Day").setStyle("SECONDARY"),
+ new Discord.MessageButton().setCustomId("1w").setLabel("1 Week").setStyle("SECONDARY")
]),
new MessageActionRow().addComponents([
new Discord.MessageButton()
@@ -228,9 +172,7 @@
time: `${humanizeDuration(muteTime * 1000, {
round: true
})}`,
- reason: reason
- ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ")
- : "*No reason provided*"
+ reason: reason ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ") : "*No reason provided*"
}) +
"The user will be " +
serverSettingsDescription +
@@ -244,12 +186,7 @@
"Create appeal ticket",
!(await areTicketsEnabled(interaction.guild.id)),
async () =>
- await create(
- interaction.guild,
- interaction.options.getUser("user"),
- interaction.user,
- reason
- ),
+ await create(interaction.guild, interaction.options.getUser("user"), interaction.user, reason),
"An appeal ticket will be created when Confirm is clicked",
"CONTROL.TICKET",
createAppealTicket
@@ -291,17 +228,9 @@
? ` for:\n> ${reason}`
: ".\n\n" +
`You will be unmuted at: <t:${
- Math.round(
- new Date().getTime() / 1000
- ) + muteTime
- }:D> at <t:${
- Math.round(
- new Date().getTime() / 1000
- ) + muteTime
- }:T> (<t:${
- Math.round(
- new Date().getTime() / 1000
- ) + muteTime
+ Math.round(new Date().getTime() / 1000) + muteTime
+ }:D> at <t:${Math.round(new Date().getTime() / 1000) + muteTime}:T> (<t:${
+ Math.round(new Date().getTime() / 1000) + muteTime
}:R>)`) +
(confirmation.components.appeal.response
? `You can appeal this here: <#${confirmation.components.appeal.response}>`
@@ -331,10 +260,7 @@
let errors = 0;
try {
if (config.moderation.mute.timeout) {
- await member.timeout(
- muteTime * 1000,
- reason || "No reason provided"
- );
+ await member.timeout(muteTime * 1000, reason || "No reason provided");
if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role);
await client.database.eventScheduler.schedule(
@@ -354,15 +280,11 @@
try {
if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role);
- await client.database.eventScheduler.schedule(
- "unmuteRole",
- new Date().getTime() + muteTime * 1000,
- {
- guild: interaction.guild.id,
- user: user.id,
- role: config.moderation.mute.role
- }
- );
+ await client.database.eventScheduler.schedule("unmuteRole", new Date().getTime() + muteTime * 1000, {
+ guild: interaction.guild.id,
+ user: user.id,
+ role: config.moderation.mute.role
+ });
}
} catch (e) {
console.log(e);
@@ -374,9 +296,7 @@
new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED")
.setTitle("Mute")
- .setDescription(
- "Something went wrong and the user was not muted"
- )
+ .setDescription("Something went wrong and the user was not muted")
.setStatus("Danger")
],
components: []
@@ -384,13 +304,7 @@
if (dmd) await dm.delete();
return;
}
- await client.database.history.create(
- "mute",
- interaction.guild.id,
- member.user,
- interaction.user,
- reason
- );
+ await client.database.history.create("mute", interaction.guild.id, member.user, interaction.user, reason);
const failed = !dmd && notify;
await interaction.editReply({
embeds: [
@@ -424,14 +338,8 @@
new Date().getTime() + muteTime * 1000,
renderDelta(new Date().getTime() + muteTime * 1000)
),
- muted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime() - 1000)
- ),
- mutedBy: entry(
- interaction.member.user.id,
- renderUser(interaction.member.user)
- ),
+ muted: entry(new Date().getTime(), renderDelta(new Date().getTime() - 1000)),
+ mutedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
reason: entry(reason, reason ? reason : "*No reason provided*")
},
hidden: {
@@ -457,30 +365,24 @@
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember;
- if (member === null || me === null || apply === null)
- throw "That member is not in the server";
+ if (member === null || me === null || apply === null) throw "That member is not in the server";
const memberPos = member.roles ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow muting the owner
- if (member.id === interaction.guild.ownerId)
- throw "You cannot mute the owner of the server";
+ if (member.id === interaction.guild.ownerId) throw "You cannot mute the owner of the server";
// Check if Nucleus can mute the member
- if (!(mePos > applyPos))
- throw "I do not have a role higher than that member";
+ if (!(mePos > applyPos)) throw "I do not have a role higher than that member";
// Check if Nucleus has permission to mute
- if (!me.permissions.has("MODERATE_MEMBERS"))
- throw "I do not have the *Moderate Members* permission";
+ if (!me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission";
// Do not allow muting Nucleus
if (member.id === me.id) throw "I cannot mute myself";
// Allow the owner to mute anyone
if (member.id === interaction.guild.ownerId) return true;
// Check if the user has moderate_members permission
- if (!member.permissions.has("MODERATE_MEMBERS"))
- throw "You do not have the *Moderate Members* permission";
+ if (!member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
// Check if the user is below on the role list
- if (!(memberPos > applyPos))
- throw "You do not have a role higher than that member";
+ if (!(memberPos > applyPos)) throw "You do not have a role higher than that member";
// Allow mute
return true;
};