typing again

pull/17/head
pineafan 3 years ago
parent ad00217fd1
commit 62ce192135
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -7,7 +7,7 @@ export async function create(
guild: Discord.Guild, guild: Discord.Guild,
member: Discord.User, member: Discord.User,
createdBy: Discord.User, createdBy: Discord.User,
reason: string, reason: string | null,
customReason?: string customReason?: string
) { ) {
const config = await client.database.guilds.read(guild.id); const config = await client.database.guilds.read(guild.id);
@ -26,7 +26,7 @@ export async function create(
}); });
if (config.tickets.supportRole !== null) { if (config.tickets.supportRole !== null) {
overwrites.push({ overwrites.push({
id: guild.roles.cache.get(config.tickets.supportRole), id: guild.roles.cache.get(config.tickets.supportRole)!,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
type: "role" type: "role"
}); });

@ -1,4 +1,4 @@
import { CommandInteraction, GuildMember, MessageActionRow, MessageButton } from "discord.js"; import { CommandInteraction, GuildMember, MessageActionRow, MessageButton, User } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@ -26,143 +26,171 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
let reason = null; let reason = null;
let notify = true; let notify = true;
let confirmation; let confirmation;
let cancelled = false; let chosen = false;
let timedOut = false; let timedOut = false;
while (!timedOut && !cancelled) { do {
confirmation = await new confirmationMessage(interaction) confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
.setTitle("Ban") .setTitle("Ban")
.setDescription( .setDescription(
keyValueList({ keyValueList({
user: renderUser(interaction.options.getUser("user")), user: renderUser(interaction.options.getUser("user")),
reason: reason ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ") : "*No reason provided*" reason: reason ? "\n> " + (reason).replaceAll("\n", "\n> ") : "*No reason provided*"
}) + }) +
`The user **will${notify ? "" : " not"}** be notified\n` + `The user **will${notify ? "" : " not"}** be notified\n` +
`${addPlurals( `${addPlurals(
interaction.options.getInteger("delete") ? interaction.options.getInteger("delete") : 0, interaction.options.getNumber("delete") ?? 0,
"day" "day"
)} of messages will be deleted\n\n` + )} of messages will be deleted\n\n` +
`Are you sure you want to ban <@!${(interaction.options.getMember("user") as GuildMember).id}>?` `Are you sure you want to ban <@!${(interaction.options.getMember("user") as GuildMember).id}>?`
) )
.addCustomBoolean(
"notify",
"Notify user",
false,
undefined,
null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
.setColor("Danger") .setColor("Danger")
.addReasonButton(reason ?? "") .addReasonButton(reason ?? "")
.send(reason !== null); .send(reason !== null);
reason = reason ?? ""; reason = reason ?? "";
if (confirmation.cancelled) timedOut = true; if (confirmation.cancelled) timedOut = true;
else if (confirmation.success) cancelled = true; else if (confirmation.success !== undefined) chosen = true;
else if (confirmation.newReason) reason = confirmation.newReason; else if (confirmation.newReason) reason = confirmation.newReason;
else if (confirmation.components) notify = confirmation.components.notify.active; else if (confirmation.components) notify = confirmation.components["notify"]!.active;
} } while (!timedOut && !chosen)
if (timedOut) return; if (timedOut) return;
let dmd = false; if (confirmation.success) {
let dm; reason = reason.length ? reason : null
const config = await client.database.guilds.read(interaction.guild.id); let dmd = false;
try { let dm;
if (notify) { const config = await client.database.guilds.read(interaction.guild!.id);
dm = await (interaction.options.getMember("user") as GuildMember).send({ try {
if (notify) {
dm = await (interaction.options.getMember("user") as GuildMember).send({
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED")
.setTitle("Banned")
.setDescription(
`You have been banned in ${interaction.guild!.name}` + (reason ? ` for:\n> ${reason}` : ".")
)
.setStatus("Danger")
],
components: [
new MessageActionRow().addComponents(
config.moderation.ban.text
? [
new MessageButton()
.setStyle("LINK")
.setLabel(config.moderation.ban.text)
.setURL(config.moderation.ban.link)
]
: []
)
]
});
dmd = true;
}
} catch {
dmd = false;
}
try {
const member = interaction.options.getMember("user") as GuildMember;
member.ban({
days: Number(interaction.options.getNumber("delete") ?? 0),
reason: reason ?? "No reason provided"
});
await client.database.history.create("ban", interaction.guild!.id, member.user, interaction.user, reason);
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const data = {
meta: {
type: "memberBan",
displayName: "Member Banned",
calculateType: "guildMemberPunish",
color: NucleusColors.red,
emoji: "PUNISH.BAN.RED",
timestamp: new Date().getTime()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
bannedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: interaction.guild!.memberCount
},
hidden: {
guild: interaction.guild!.id
}
};
log(data);
} catch {
await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
.setTitle("Banned") .setTitle("Ban")
.setDescription( .setDescription("Something went wrong and the user was not banned")
`You have been banned in ${interaction.guild.name}` + (reason ? ` for:\n> ${reason}` : ".")
)
.setStatus("Danger") .setStatus("Danger")
], ],
components: [ components: []
new MessageActionRow().addComponents(
config.moderation.ban.text
? [
new MessageButton()
.setStyle("LINK")
.setLabel(config.moderation.ban.text)
.setURL(config.moderation.ban.link)
]
: []
)
]
}); });
dmd = true; if (dmd && dm) await dm.delete();
return;
} }
} catch { const failed = !dmd && notify;
dmd = false; await interaction.editReply({
} embeds: [
try { new EmojiEmbed()
const member = interaction.options.getMember("user") as GuildMember; .setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
member.ban({ .setTitle("Ban")
days: Number(interaction.options.getNumber("delete") ?? 0), .setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
reason: reason ?? "No reason provided" .setStatus(failed ? "Warning" : "Success")
],
components: []
}); });
await client.database.history.create("ban", interaction.guild.id, member.user, interaction.user, reason); } else {
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const data = {
meta: {
type: "memberBan",
displayName: "Member Banned",
calculateType: "guildMemberPunish",
color: NucleusColors.red,
emoji: "PUNISH.BAN.RED",
timestamp: new Date().getTime()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
bannedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: interaction.guild.memberCount
},
hidden: {
guild: interaction.guild.id
}
};
log(data);
} catch {
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.GREEN")
.setTitle("Ban") .setTitle("Ban")
.setDescription("Something went wrong and the user was not banned") .setDescription("No changes were made")
.setStatus("Danger") .setStatus("Success")
], ],
components: [] components: []
}); });
if (dmd) await dm.delete();
return;
} }
const failed = !dmd && notify;
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle("Ban")
.setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
],
components: []
});
}; };
const check = (interaction: CommandInteraction) => { const check = async (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember; const member = interaction.member as GuildMember;
const me = interaction.guild.me!; const me = interaction.guild!.me!;
const apply = interaction.options.getMember("user") as GuildMember; let apply = interaction.options.getUser("user") as User | GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const memberPos = member.roles ? member.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; let applyPos = 0
const applyPos = apply.roles ? apply.roles.highest.position : 0; try {
apply = await interaction.guild!.members.fetch(apply.id) as GuildMember
applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
} catch {
apply = apply as User
}
// Do not allow banning the owner // Do not allow banning the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot ban the owner of the server"); if (member.id === interaction.guild!.ownerId) throw new Error("You cannot ban the owner of the server");
// Check if Nucleus can ban the member // Check if Nucleus can ban the member
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member"); if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to ban // Check if Nucleus has permission to ban
if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission"); if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission");
// Do not allow banning Nucleus // Do not allow banning Nucleus
if (member.id === interaction.guild.me.id) throw new Error("I cannot ban myself"); if (member.id === interaction.guild!.me!.id) throw new Error("I cannot ban myself");
// Allow the owner to ban anyone // Allow the owner to ban anyone
if (member.id === interaction.guild.ownerId) return true; if (member.id === interaction.guild!.ownerId) return true;
// Check if the user has ban_members permission // Check if the user has ban_members permission
if (!member.permissions.has("BAN_MEMBERS")) throw new Error("You do not have the *Ban Members* permission"); if (!member.permissions.has("BAN_MEMBERS")) throw new Error("You do not have the *Ban Members* permission");
// Check if the user is below on the role list // Check if the user is below on the role list

@ -8,6 +8,7 @@ import Discord, {
MessageButton, MessageButton,
MessageComponentInteraction, MessageComponentInteraction,
ModalSubmitInteraction, ModalSubmitInteraction,
SelectMenuInteraction,
TextInputComponent TextInputComponent
} from "discord.js"; } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
@ -256,7 +257,7 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
} }
i.deferUpdate(); i.deferUpdate();
if (i.customId === "filter") { if (i.customId === "filter") {
filteredTypes = i.values; filteredTypes = (i as SelectMenuInteraction).values;
pageIndex = null; pageIndex = null;
refresh = true; refresh = true;
} }

@ -1,6 +1,7 @@
import { CommandInteraction, GuildMember, MessageActionRow, MessageButton } from "discord.js"; import { CommandInteraction, GuildMember, MessageActionRow, MessageButton } from "discord.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js"; import keyValueList from "../../utils/generateKeyValueList.js";
@ -19,15 +20,15 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
let notify = true; let notify = true;
let confirmation; let confirmation;
let timedOut = false; let timedOut = false;
let success = false; let chosen = false;
while (!timedOut && !success) { while (!timedOut && !chosen) {
confirmation = await new confirmationMessage(interaction) confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.KICK.RED") .setEmoji("PUNISH.KICK.RED")
.setTitle("Kick") .setTitle("Kick")
.setDescription( .setDescription(
keyValueList({ keyValueList({
user: renderUser(interaction.options.getUser("user")), user: renderUser(interaction.options.getUser("user")),
reason: reason ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ") : "*No reason provided*" reason: reason ? "\n> " + (reason).replaceAll("\n", "\n> ") : "*No reason provided*"
}) + }) +
`The user **will${notify ? "" : " not"}** be notified\n\n` + `The user **will${notify ? "" : " not"}** be notified\n\n` +
`Are you sure you want to kick <@!${(interaction.options.getMember("user") as GuildMember).id}>?` `Are you sure you want to kick <@!${(interaction.options.getMember("user") as GuildMember).id}>?`
@ -37,16 +38,16 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.send(reason !== null); .send(reason !== null);
reason = reason ?? ""; reason = reason ?? "";
if (confirmation.cancelled) timedOut = true; if (confirmation.cancelled) timedOut = true;
else if (confirmation.success) success = true; else if (confirmation.success !== undefined) chosen = true;
else if (confirmation.newReason) reason = confirmation.newReason; else if (confirmation.newReason) reason = confirmation.newReason;
else if (confirmation.components) { else if (confirmation.components) {
notify = confirmation.components.notify.active; notify = confirmation.components["notify"]!.active;
} }
} }
if (timedOut) return; if (timedOut) return;
let dmd = false; let dmd = false;
let dm; let dm;
const config = await client.database.guilds.read(interaction.guild.id); const config = await client.database.guilds.read(interaction.guild!.id);
try { try {
if (notify) { if (notify) {
dm = await (interaction.options.getMember("user") as GuildMember).send({ dm = await (interaction.options.getMember("user") as GuildMember).send({
@ -55,7 +56,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("PUNISH.KICK.RED") .setEmoji("PUNISH.KICK.RED")
.setTitle("Kicked") .setTitle("Kicked")
.setDescription( .setDescription(
`You have been kicked in ${interaction.guild.name}` + (reason ? ` for:\n> ${reason}` : ".") `You have been kicked in ${interaction.guild!.name}` + (reason ? ` for:\n> ${reason}` : ".")
) )
.setStatus("Danger") .setStatus("Danger")
], ],
@ -80,8 +81,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
try { try {
(interaction.options.getMember("user") as GuildMember).kick(reason ?? "No reason provided."); (interaction.options.getMember("user") as GuildMember).kick(reason ?? "No reason provided.");
const member = interaction.options.getMember("user") as GuildMember; const member = interaction.options.getMember("user") as GuildMember;
await client.database.history.create("kick", interaction.guild.id, member.user, interaction.user, reason); await client.database.history.create("kick", interaction.guild!.id, member.user, interaction.user, reason);
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger; const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const timeInServer = member.joinedTimestamp ? entry(
new Date().getTime() - member.joinedTimestamp,
humanizeDuration(new Date().getTime() - member.joinedTimestamp, {
round: true
})
) : entry(null, "*Unknown*")
const data = { const data = {
meta: { meta: {
type: "memberKick", type: "memberKick",
@ -98,12 +105,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())), kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
kickedBy: entry(interaction.user.id, renderUser(interaction.user)), kickedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"), reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
timeInServer: entry( timeInServer: timeInServer,
new Date().getTime() - member.joinedTimestamp,
humanizeDuration(new Date().getTime() - member.joinedTimestamp, {
round: true
})
),
accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)), accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: member.guild.memberCount serverMemberCount: member.guild.memberCount
}, },
@ -123,7 +125,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
], ],
components: [] components: []
}); });
if (dmd) await dm.delete(); if (dmd && dm) await dm.delete();
return; return;
} }
const failed = !dmd && notify; const failed = !dmd && notify;
@ -141,22 +143,21 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const check = (interaction: CommandInteraction) => { const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember; const member = interaction.member as GuildMember;
const me = interaction.guild.me!; const me = interaction.guild!.me!;
const apply = interaction.options.getMember("user") as GuildMember; const apply = interaction.options.getMember("user") as GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const memberPos = member.roles ? member.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow kicking the owner // Do not allow kicking the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot kick the owner of the server"); if (member.id === interaction.guild!.ownerId) throw new Error("You cannot kick the owner of the server");
// Check if Nucleus can kick the member // Check if Nucleus can kick the member
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member"); if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to kick // Check if Nucleus has permission to kick
if (!me.permissions.has("KICK_MEMBERS")) throw new Error("I do not have the *Kick Members* permission"); if (!me.permissions.has("KICK_MEMBERS")) throw new Error("I do not have the *Kick Members* permission");
// Do not allow kicking Nucleus // Do not allow kicking Nucleus
if (member.id === interaction.guild.me.id) throw new Error("I cannot kick myself"); if (member.id === interaction.guild!.me!.id) throw new Error("I cannot kick myself");
// Allow the owner to kick anyone // Allow the owner to kick anyone
if (member.id === interaction.guild.ownerId) return true; if (member.id === interaction.guild!.ownerId) return true;
// Check if the user has kick_members permission // Check if the user has kick_members permission
if (!member.permissions.has("KICK_MEMBERS")) throw new Error("You do not have the *Kick Members* permission"); if (!member.permissions.has("KICK_MEMBERS")) throw new Error("You do not have the *Kick Members* permission");
// Check if the user is below on the role list // Check if the user is below on the role list

@ -1,10 +1,11 @@
import { LoadingEmbed } from "./../../utils/defaultEmbeds.js"; 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 type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js"; import getEmojiByName from "../../utils/getEmojiByName.js";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
import keyValueList from "../../utils/generateKeyValueList.js"; import keyValueList from "../../utils/generateKeyValueList.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import client from "../../utils/client.js"; import client from "../../utils/client.js";
import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js"; import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js";
@ -56,7 +57,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
minutes: interaction.options.getInteger("minutes") ?? 0, minutes: interaction.options.getInteger("minutes") ?? 0,
seconds: interaction.options.getInteger("seconds") ?? 0 seconds: interaction.options.getInteger("seconds") ?? 0
}; };
const config = await client.database.guilds.read(interaction.guild.id); 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) if (config.moderation.mute.role)
serverSettingsDescription += serverSettingsDescription +=
@ -158,13 +159,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
// TODO:[Modals] Replace this with a modal // TODO:[Modals] Replace this with a modal
let reason = null; let reason: string | null = null;
let notify = true; let notify = true;
let createAppealTicket = false; let createAppealTicket = false;
let confirmation; let confirmation;
let timedOut = false; let timedOut = false;
let success = false; let success = false;
while (!timedOut && !success) { do {
confirmation = await new confirmationMessage(interaction) confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.MUTE.RED") .setEmoji("PUNISH.MUTE.RED")
.setTitle("Mute") .setTitle("Mute")
@ -174,7 +175,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
time: `${humanizeDuration(muteTime * 1000, { time: `${humanizeDuration(muteTime * 1000, {
round: true 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 " + "The user will be " +
serverSettingsDescription + serverSettingsDescription +
@ -186,9 +187,9 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.addCustomBoolean( .addCustomBoolean(
"appeal", "appeal",
"Create appeal ticket", "Create appeal ticket",
!(await areTicketsEnabled(interaction.guild.id)), !(await areTicketsEnabled(interaction.guild!.id)),
async () => 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", "An appeal ticket will be created when Confirm is clicked",
"CONTROL.TICKET", "CONTROL.TICKET",
createAppealTicket createAppealTicket
@ -197,7 +198,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
"notify", "notify",
"Notify user", "Notify user",
false, false,
null, undefined,
null, null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"), "ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify notify
@ -209,154 +210,165 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (confirmation.success) success = true; if (confirmation.success) success = true;
if (confirmation.newReason) reason = confirmation.newReason; if (confirmation.newReason) reason = confirmation.newReason;
if (confirmation.components) { if (confirmation.components) {
notify = confirmation.components.notify.active; notify = confirmation.components["notify"]!.active;
createAppealTicket = confirmation.components.appeal.active; createAppealTicket = confirmation.components["appeal"]!.active;
} }
} } while (!timedOut && !success)
if (timedOut) return; if (timedOut) return;
let dmd = false; let dmd = false;
let dm; let dm;
const config = await client.database.guilds.read(interaction.guild.id); if (confirmation.success) {
try { try {
if (notify) { if (notify) {
dm = await user.send({ dm = await user.send({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED") .setEmoji("PUNISH.MUTE.RED")
.setTitle("Muted") .setTitle("Muted")
.setDescription( .setDescription(
`You have been muted in ${interaction.guild.name}` + `You have been muted in ${interaction.guild!.name}` +
(reason (reason
? ` for:\n> ${reason}` ? ` for:\n> ${reason}`
: ".\n\n" + : ".\n\n" +
`You will be unmuted at: <t:${ `You will be unmuted at: <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:${ }: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
}:R>)`) + }:R>)`) +
(confirmation.components.appeal.response (confirmation.components!["appeal"]!.response
? `You can appeal this here: <#${confirmation.components.appeal.response}>` ? `You can appeal this here: <#${confirmation.components!["appeal"]!.response}>`
: "") : "")
)
.setStatus("Danger")
],
components: [
new MessageActionRow().addComponents(
config.moderation.mute.text
? [
new MessageButton()
.setStyle("LINK")
.setLabel(config.moderation.mute.text)
.setURL(config.moderation.mute.link)
]
: []
) )
.setStatus("Danger") ]
], });
components: [ dmd = true;
new MessageActionRow().addComponents( }
config.moderation.mute.text } catch {
? [ dmd = false;
new MessageButton()
.setStyle("LINK")
.setLabel(config.moderation.mute.text)
.setURL(config.moderation.mute.link)
]
: []
)
]
});
dmd = true;
} }
} catch { const member = user;
dmd = false; let errors = 0;
} try {
const member = user; if (config.moderation.mute.timeout) {
let errors = 0; await member.timeout(muteTime * 1000, reason || "No reason provided");
try { if (config.moderation.mute.role !== null) {
if (config.moderation.mute.timeout) { await member.roles.add(config.moderation.mute.role);
await member.timeout(muteTime * 1000, reason || "No reason provided"); await client.database.eventScheduler.schedule("naturalUnmute", new Date().getTime() + muteTime * 1000, {
guild: interaction.guild!.id,
user: user.id,
expires: new Date().getTime() + muteTime * 1000
});
}
}
} catch {
errors++;
}
try {
if (config.moderation.mute.role !== null) { if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role); await member.roles.add(config.moderation.mute.role);
await client.database.eventScheduler.schedule("naturalUnmute", new Date().getTime() + muteTime * 1000, { await client.database.eventScheduler.schedule("unmuteRole", new Date().getTime() + muteTime * 1000, {
guild: interaction.guild.id, guild: interaction.guild!.id,
user: user.id, user: user.id,
expires: new Date().getTime() + muteTime * 1000 role: config.moderation.mute.role
}); });
} }
} catch (e) {
console.log(e);
errors++;
} }
} catch { if (errors === 2) {
errors++; await interaction.editReply({
} embeds: [
try { new EmojiEmbed()
if (config.moderation.mute.role !== null) { .setEmoji("PUNISH.MUTE.RED")
await member.roles.add(config.moderation.mute.role); .setTitle("Mute")
await client.database.eventScheduler.schedule("unmuteRole", new Date().getTime() + muteTime * 1000, { .setDescription("Something went wrong and the user was not muted")
guild: interaction.guild.id, .setStatus("Danger")
user: user.id, ],
role: config.moderation.mute.role components: []
}); }); // TODO: make this clearer
if (dmd && dm) await dm.delete();
return;
} }
} catch (e) { await client.database.history.create("mute", interaction.guild!.id, member.user, interaction.user, reason);
console.log(e); const failed = !dmd && notify;
errors++;
}
if (errors === 2) {
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED") .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
.setTitle("Mute") .setTitle("Mute")
.setDescription("Something went wrong and the user was not muted") .setDescription(
.setStatus("Danger") "The member was muted" +
(failed ? ", but could not be notified" : "") +
(confirmation.components!["appeal"]!.response
? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus(failed ? "Warning" : "Success")
], ],
components: [] components: []
}); // TODO: make this clearer });
if (dmd) await dm.delete(); const data = {
return; meta: {
type: "memberMute",
displayName: "Member Muted",
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.WARN.YELLOW",
timestamp: new Date().getTime()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
mutedUntil: entry(
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)),
reason: entry(reason, reason ? reason : "*No reason provided*")
},
hidden: {
guild: interaction.guild!.id
}
};
log(data);
} else {
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.BAN.GREEN")
.setTitle("Softban")
.setDescription("No changes were made")
.setStatus("Success")
],
components: []
});
} }
await client.database.history.create("mute", interaction.guild.id, member.user, interaction.user, reason);
const failed = !dmd && notify;
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
.setTitle("Mute")
.setDescription(
"The member was muted" +
(failed ? ", but could not be notified" : "") +
(confirmation.components.appeal.response
? ` and an appeal ticket was opened in <#${confirmation.components.appeal.response}>`
: "")
)
.setStatus(failed ? "Warning" : "Success")
],
components: []
});
const data = {
meta: {
type: "memberMute",
displayName: "Member Muted",
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.WARN.YELLOW",
timestamp: new Date().getTime()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
mutedUntil: entry(
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)),
reason: entry(reason, reason ? reason : "*No reason provided*")
},
hidden: {
guild: interaction.guild.id
}
};
log(data);
}; };
const check = (interaction: CommandInteraction) => { const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember; const member = interaction.member as GuildMember;
const me = interaction.guild.me!; const me = interaction.guild!.me!;
const apply = interaction.options.getMember("user") as GuildMember; const apply = interaction.options.getMember("user") as GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const memberPos = member.roles ? member.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
// Do not allow muting the owner // Do not allow muting the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot mute the owner of the server"); if (member.id === interaction.guild!.ownerId) throw new Error("You cannot mute the owner of the server");
// Check if Nucleus can mute the member // Check if Nucleus can mute the member
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member"); if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to mute // Check if Nucleus has permission to mute
@ -364,7 +376,7 @@ const check = (interaction: CommandInteraction) => {
// Do not allow muting Nucleus // Do not allow muting Nucleus
if (member.id === me.id) throw new Error("I cannot mute myself"); if (member.id === me.id) throw new Error("I cannot mute myself");
// Allow the owner to mute anyone // Allow the owner to mute anyone
if (member.id === interaction.guild.ownerId) return true; if (member.id === interaction.guild!.ownerId) return true;
// Check if the user has moderate_members permission // Check if the user has moderate_members permission
if (!member.permissions.has("MODERATE_MEMBERS")) if (!member.permissions.has("MODERATE_MEMBERS"))
throw new Error("You do not have the *Moderate Members* permission"); throw new Error("You do not have the *Moderate Members* permission");

@ -169,9 +169,9 @@ const check = (interaction: CommandInteraction) => {
const me = interaction.guild.me!; const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember; const apply = interaction.options.getMember("user") as GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0; const memberPos = member.roles.cache.size ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; const mePos = me.roles.cache.size ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0; const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0;
// Do not allow any changing of the owner // Do not allow any changing of the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot change the owner's nickname"); if (member.id === interaction.guild.ownerId) throw new Error("You cannot change the owner's nickname");
// Check if Nucleus can change the nickname // Check if Nucleus can change the nickname

@ -149,9 +149,9 @@ const check = (interaction: CommandInteraction) => {
const me = interaction.guild.me!; const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember; const apply = interaction.options.getMember("user") as GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0; const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0; const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
// Do not allow softbanning the owner // Do not allow softbanning the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot softban the owner of the server"); if (member.id === interaction.guild.ownerId) throw new Error("You cannot softban the owner of the server");
// Check if Nucleus can ban the member // Check if Nucleus can ban the member

@ -136,9 +136,9 @@ const check = (interaction: CommandInteraction) => {
const me = interaction.guild.me!; const me = interaction.guild.me!;
const apply = interaction.options.getMember("user") as GuildMember; const apply = interaction.options.getMember("user") as GuildMember;
if (member === null || me === null || apply === null) throw new Error("That member is not in the server"); if (member === null || me === null || apply === null) throw new Error("That member is not in the server");
const memberPos = member.roles ? member.roles.highest.position : 0; const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0; const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0; const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
// Do not allow unmuting the owner // Do not allow unmuting the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot unmute the owner of the server"); if (member.id === interaction.guild.ownerId) throw new Error("You cannot unmute the owner of the server");
// Check if Nucleus can unmute the member // Check if Nucleus can unmute the member

@ -21,7 +21,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
let confirmation; let confirmation;
let timedOut = false; let timedOut = false;
let success = false; let success = false;
while (!timedOut && !success) { do {
confirmation = await new confirmationMessage(interaction) confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.WARN.RED") .setEmoji("PUNISH.WARN.RED")
.setTitle("Warn") .setTitle("Warn")
@ -57,13 +57,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.send(reason !== null); .send(reason !== null);
reason = reason ?? ""; reason = reason ?? "";
if (confirmation.cancelled) timedOut = true; if (confirmation.cancelled) timedOut = true;
else if (confirmation.success) success = true; else if (confirmation.success !== undefined) success = true;
else if (confirmation.newReason) reason = confirmation.newReason; else if (confirmation.newReason) reason = confirmation.newReason;
else if (confirmation.components) { else if (confirmation.components) {
notify = confirmation.components.notify.active; notify = confirmation.components.notify.active;
createAppealTicket = confirmation.components.appeal.active; createAppealTicket = confirmation.components.appeal.active;
} }
} } while (!timedOut && !success)
if (timedOut) return; if (timedOut) return;
if (confirmation.success) { if (confirmation.success) {
let dmd = false; let dmd = false;
@ -294,7 +294,7 @@ const check = (interaction: CommandInteraction) => {
// Do not allow warning bots // Do not allow warning bots
if (member.user.bot) throw new Error("I cannot warn bots"); if (member.user.bot) throw new Error("I cannot warn bots");
// Allow the owner to warn anyone // Allow the owner to warn anyone
if (member.id === interaction.guild.ownerId) return true; if (member.id === interaction.guild!.ownerId) return true;
// Check if the user has moderate_members permission // Check if the user has moderate_members permission
if (!member.permissions.has("MODERATE_MEMBERS")) if (!member.permissions.has("MODERATE_MEMBERS"))
throw new Error("You do not have the *Moderate Members* permission"); throw new Error("You do not have the *Moderate Members* permission");

@ -34,16 +34,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
) )
.setColor("Danger") .setColor("Danger")
.send(true); .send(true);
if (confirmation.cancelled) if (confirmation.cancelled) return
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Moderation Commands")
.setDescription("No changes were made")
.setStatus("Success")
.setEmoji("GUILD.ROLES.CREATE")
]
});
if (confirmation.success) { if (confirmation.success) {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild.id, {
["moderation.mute.role"]: interaction.options.getRole("role").id ["moderation.mute.role"]: interaction.options.getRole("role").id

@ -54,7 +54,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT") .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Attachment Log Channel") .setTitle("Attachment Log Channel")
.setDescription( .setDescription(
"This will be the channel all attachments will be sent to.\n\n" + "This will be the channel all attachments will be sent to.\n\n" +

@ -53,7 +53,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT") .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Log Channel") .setTitle("Log Channel")
.setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`) .setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`)
.setColor("Warning") .setColor("Warning")

@ -56,7 +56,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT") .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Staff Notifications Channel") .setTitle("Staff Notifications Channel")
.setDescription( .setDescription(
"This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" + "This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" +

@ -78,7 +78,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
newName = newName.toLowerCase().replace(/[\s]/g, "-"); newName = newName.toLowerCase().replace(/[\s]/g, "-");
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT") .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Stats Channel") .setTitle("Stats Channel")
.setDescription( .setDescription(
`Are you sure you want to set <#${channel.id}> to a stats channel?\n\n*Preview: ${newName.replace( `Are you sure you want to set <#${channel.id}> to a stats channel?\n\n*Preview: ${newName.replace(

@ -143,7 +143,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.TICKET.ARCHIVED") .setEmoji("GUILD.TICKET.ARCHIVED", "GUILD.TICKET.CLOSE")
.setTitle("Tickets") .setTitle("Tickets")
.setDescription( .setDescription(
(options.category ? `**Category:** ${options.category.name}\n` : "") + (options.category ? `**Category:** ${options.category.name}\n` : "") +
@ -151,10 +151,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
(options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") + (options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") +
(options.enabled !== null (options.enabled !== null
? `**Enabled:** ${ ? `**Enabled:** ${
options.enabled options.enabled
? `${getEmojiByName("CONTROL.TICK")} Yes` ? `${getEmojiByName("CONTROL.TICK")} Yes`
: `${getEmojiByName("CONTROL.CROSS")} No` : `${getEmojiByName("CONTROL.CROSS")} No`
}\n` }\n`
: "") + : "") +
"\nAre you sure you want to apply these settings?" "\nAre you sure you want to apply these settings?"
) )

@ -62,7 +62,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.ROLES.EDIT") .setEmoji("GUILD.ROLES.EDIT", "GUILD.ROLES.DELETE")
.setTitle("Verify Role") .setTitle("Verify Role")
.setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`) .setDescription(`Are you sure you want to set the verify role to <@&${role.id}>?`)
.setColor("Warning") .setColor("Warning")

@ -95,7 +95,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (channel) options.channel = renderChannel(channel); if (channel) options.channel = renderChannel(channel);
if (message) options.message = "\n> " + message; if (message) options.message = "\n> " + message;
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.ROLES.EDIT") .setEmoji("GUILD.ROLES.EDIT", "GUILD.ROLES.DELETE")
.setTitle("Welcome Events") .setTitle("Welcome Events")
.setDescription(generateKeyValueList(options)) .setDescription(generateKeyValueList(options))
.setColor("Warning") .setColor("Warning")

@ -64,7 +64,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true ephemeral: true
}); });
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.NICKNAME.YELLOW") .setEmoji("PUNISH.NICKNAME.YELLOW", "PUNISH.NICKNAME.RED")
.setTitle("Tag create") .setTitle("Tag create")
.setDescription( .setDescription(
keyValueList({ keyValueList({

@ -27,7 +27,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true ephemeral: true
}); });
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.NICKNAME.YELLOW") .setEmoji("PUNISH.NICKNAME.YELLOW", "PUNISH.NICKNAME.RED")
.setTitle("Tag Delete") .setTitle("Tag Delete")
.setDescription( .setDescription(
keyValueList({ keyValueList({

@ -79,7 +79,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true ephemeral: true
}); });
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.NICKNAME.YELLOW") .setEmoji("PUNISH.NICKNAME.YELLOW", "PUNISH.NICKNAME.RED")
.setTitle("Tag Edit") .setTitle("Tag Edit")
.setDescription( .setDescription(
keyValueList({ keyValueList({

@ -26,6 +26,8 @@ class confirmationMessage {
interaction: CommandInteraction; interaction: CommandInteraction;
title = ""; title = "";
emoji = ""; emoji = "";
redEmoji: string | null = null;
timeoutText: string | null = null;
description = ""; description = "";
color: "Danger" | "Warning" | "Success" = "Success"; color: "Danger" | "Warning" | "Success" = "Success";
customButtons: Record<string, CustomBoolean<unknown>> = {}; customButtons: Record<string, CustomBoolean<unknown>> = {};
@ -40,12 +42,14 @@ class confirmationMessage {
this.title = title; this.title = title;
return this; return this;
} }
setEmoji(emoji: string) { setEmoji(emoji: string, redEmoji?: string) {
this.emoji = emoji; this.emoji = emoji;
if (redEmoji) this.redEmoji = redEmoji; // TODO: go through all confirmation messages and change them to use this, and not do their own edits
return this; return this;
} }
setDescription(description: string) { setDescription(description: string, timedOut?: string) {
this.description = description; this.description = description;
if (timedOut) this.timeoutText = timedOut; // TODO also this
return this; return this;
} }
setColor(color: "Danger" | "Warning" | "Success") { setColor(color: "Danger" | "Warning" | "Success") {
@ -256,13 +260,29 @@ class confirmationMessage {
} }
const returnValue: Awaited<ReturnType<typeof this.send>> = {}; const returnValue: Awaited<ReturnType<typeof this.send>> = {};
if (returnComponents) returnValue.components = this.customButtons; if (returnComponents || success !== undefined) returnValue.components = this.customButtons;
if (success !== undefined) returnValue.success = success; if (success !== undefined) returnValue.success = success;
if (cancelled) returnValue.cancelled = true; if (cancelled) {
await this.timeoutError()
returnValue.cancelled = true;
}
if (newReason) returnValue.newReason = newReason; if (newReason) returnValue.newReason = newReason;
return returnValue; return returnValue;
} }
async timeoutError(): Promise<void> {
await this.interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle(this.title)
.setDescription("We closed this message because it was not used for a while.")
.setStatus("Danger")
.setEmoji(this.redEmoji ?? this.emoji)
],
components: []
})
}
} }
export default confirmationMessage; export default confirmationMessage;

Loading…
Cancel
Save