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,
member: Discord.User,
createdBy: Discord.User,
reason: string,
reason: string | null,
customReason?: string
) {
const config = await client.database.guilds.read(guild.id);
@ -26,7 +26,7 @@ export async function create(
});
if (config.tickets.supportRole !== null) {
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"],
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 confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@ -26,37 +26,48 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
let reason = null;
let notify = true;
let confirmation;
let cancelled = false;
let chosen = false;
let timedOut = false;
while (!timedOut && !cancelled) {
do {
confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.BAN.RED")
.setTitle("Ban")
.setDescription(
keyValueList({
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` +
`${addPlurals(
interaction.options.getInteger("delete") ? interaction.options.getInteger("delete") : 0,
interaction.options.getNumber("delete") ?? 0,
"day"
)} of messages will be deleted\n\n` +
`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")
.addReasonButton(reason ?? "")
.send(reason !== null);
reason = reason ?? "";
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.components) notify = confirmation.components.notify.active;
}
else if (confirmation.components) notify = confirmation.components["notify"]!.active;
} while (!timedOut && !chosen)
if (timedOut) return;
if (confirmation.success) {
reason = reason.length ? reason : null
let dmd = false;
let dm;
const config = await client.database.guilds.read(interaction.guild.id);
const config = await client.database.guilds.read(interaction.guild!.id);
try {
if (notify) {
dm = await (interaction.options.getMember("user") as GuildMember).send({
@ -65,7 +76,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setEmoji("PUNISH.BAN.RED")
.setTitle("Banned")
.setDescription(
`You have been banned in ${interaction.guild.name}` + (reason ? ` for:\n> ${reason}` : ".")
`You have been banned in ${interaction.guild!.name}` + (reason ? ` for:\n> ${reason}` : ".")
)
.setStatus("Danger")
],
@ -93,7 +104,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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);
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: {
@ -111,10 +122,10 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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
serverMemberCount: interaction.guild!.memberCount
},
hidden: {
guild: interaction.guild.id
guild: interaction.guild!.id
}
};
log(data);
@ -129,7 +140,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
],
components: []
});
if (dmd) await dm.delete();
if (dmd && dm) await dm.delete();
return;
}
const failed = !dmd && notify;
@ -143,26 +154,43 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
],
components: []
});
} else {
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.BAN.GREEN")
.setTitle("Ban")
.setDescription("No changes were made")
.setStatus("Success")
],
components: []
});
}
};
const check = (interaction: CommandInteraction) => {
const check = async (interaction: CommandInteraction) => {
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 new Error("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;
const me = interaction.guild!.me!;
let apply = interaction.options.getUser("user") as User | GuildMember;
const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
let applyPos = 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
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
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to ban
if (!me.permissions.has("BAN_MEMBERS")) throw new Error("I do not have the *Ban Members* permission");
// 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
if (member.id === interaction.guild.ownerId) return true;
if (member.id === interaction.guild!.ownerId) return true;
// 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");
// Check if the user is below on the role list

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

@ -1,6 +1,7 @@
import { CommandInteraction, GuildMember, MessageActionRow, MessageButton } from "discord.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
@ -19,15 +20,15 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
let notify = true;
let confirmation;
let timedOut = false;
let success = false;
while (!timedOut && !success) {
let chosen = false;
while (!timedOut && !chosen) {
confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.KICK.RED")
.setTitle("Kick")
.setDescription(
keyValueList({
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` +
`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);
reason = reason ?? "";
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.components) {
notify = confirmation.components.notify.active;
notify = confirmation.components["notify"]!.active;
}
}
if (timedOut) return;
let dmd = false;
let dm;
const config = await client.database.guilds.read(interaction.guild.id);
const config = await client.database.guilds.read(interaction.guild!.id);
try {
if (notify) {
dm = await (interaction.options.getMember("user") as GuildMember).send({
@ -55,7 +56,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("PUNISH.KICK.RED")
.setTitle("Kicked")
.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")
],
@ -80,8 +81,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
try {
(interaction.options.getMember("user") as GuildMember).kick(reason ?? "No reason provided.");
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 timeInServer = member.joinedTimestamp ? entry(
new Date().getTime() - member.joinedTimestamp,
humanizeDuration(new Date().getTime() - member.joinedTimestamp, {
round: true
})
) : entry(null, "*Unknown*")
const data = {
meta: {
type: "memberKick",
@ -98,12 +105,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
kickedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
timeInServer: entry(
new Date().getTime() - member.joinedTimestamp,
humanizeDuration(new Date().getTime() - member.joinedTimestamp, {
round: true
})
),
timeInServer: timeInServer,
accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
serverMemberCount: member.guild.memberCount
},
@ -123,7 +125,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
],
components: []
});
if (dmd) await dm.delete();
if (dmd && dm) await dm.delete();
return;
}
const failed = !dmd && notify;
@ -141,22 +143,21 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const me = interaction.guild!.me!;
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 ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
// 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
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to kick
if (!me.permissions.has("KICK_MEMBERS")) throw new Error("I do not have the *Kick Members* permission");
// 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
if (member.id === interaction.guild.ownerId) return true;
if (member.id === interaction.guild!.ownerId) return true;
// 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");
// Check if the user is below on the role list

@ -1,10 +1,11 @@
import { LoadingEmbed } from "./../../utils/defaultEmbeds.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 getEmojiByName from "../../utils/getEmojiByName.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import keyValueList from "../../utils/generateKeyValueList.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration";
import client from "../../utils/client.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,
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" : "";
if (config.moderation.mute.role)
serverSettingsDescription +=
@ -158,13 +159,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
// TODO:[Modals] Replace this with a modal
let reason = null;
let reason: string | null = null;
let notify = true;
let createAppealTicket = false;
let confirmation;
let timedOut = false;
let success = false;
while (!timedOut && !success) {
do {
confirmation = await new confirmationMessage(interaction)
.setEmoji("PUNISH.MUTE.RED")
.setTitle("Mute")
@ -174,7 +175,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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 +
@ -186,9 +187,9 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.addCustomBoolean(
"appeal",
"Create appeal ticket",
!(await areTicketsEnabled(interaction.guild.id)),
!(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
@ -197,7 +198,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
"notify",
"Notify user",
false,
null,
undefined,
null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
@ -209,14 +210,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (confirmation.success) success = true;
if (confirmation.newReason) reason = confirmation.newReason;
if (confirmation.components) {
notify = confirmation.components.notify.active;
createAppealTicket = confirmation.components.appeal.active;
}
notify = confirmation.components["notify"]!.active;
createAppealTicket = confirmation.components["appeal"]!.active;
}
} while (!timedOut && !success)
if (timedOut) return;
let dmd = false;
let dm;
const config = await client.database.guilds.read(interaction.guild.id);
if (confirmation.success) {
try {
if (notify) {
dm = await user.send({
@ -225,7 +226,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("PUNISH.MUTE.RED")
.setTitle("Muted")
.setDescription(
`You have been muted in ${interaction.guild.name}` +
`You have been muted in ${interaction.guild!.name}` +
(reason
? ` for:\n> ${reason}`
: ".\n\n" +
@ -234,8 +235,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}: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}>`
(confirmation.components!["appeal"]!.response
? `You can appeal this here: <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus("Danger")
@ -266,7 +267,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role);
await client.database.eventScheduler.schedule("naturalUnmute", new Date().getTime() + muteTime * 1000, {
guild: interaction.guild.id,
guild: interaction.guild!.id,
user: user.id,
expires: new Date().getTime() + muteTime * 1000
});
@ -279,7 +280,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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,
guild: interaction.guild!.id,
user: user.id,
role: config.moderation.mute.role
});
@ -299,10 +300,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
],
components: []
}); // TODO: make this clearer
if (dmd) await dm.delete();
if (dmd && dm) 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: [
@ -312,8 +313,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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}>`
(confirmation.components!["appeal"]!.response
? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus(failed ? "Warning" : "Success")
@ -337,26 +338,37 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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)),
mutedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user)),
reason: entry(reason, reason ? reason : "*No reason provided*")
},
hidden: {
guild: interaction.guild.id
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: []
});
}
};
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
const me = interaction.guild.me!;
const me = interaction.guild!.me!;
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 ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
// 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
if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
// Check if Nucleus has permission to mute
@ -364,7 +376,7 @@ const check = (interaction: CommandInteraction) => {
// Do not allow muting Nucleus
if (member.id === me.id) throw new Error("I cannot mute myself");
// 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
if (!member.permissions.has("MODERATE_MEMBERS"))
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 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 ? member.roles.highest.position : 0;
const mePos = me.roles ? me.roles.highest.position : 0;
const applyPos = apply.roles ? apply.roles.highest.position : 0;
const memberPos = member.roles.cache.size ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size ? me.roles.highest.position : 0;
const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0;
// Do not allow any changing of the owner
if (member.id === interaction.guild.ownerId) throw new Error("You cannot change the owner's nickname");
// Check if Nucleus can change the nickname

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

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

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

@ -34,16 +34,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
)
.setColor("Danger")
.send(true);
if (confirmation.cancelled)
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Moderation Commands")
.setDescription("No changes were made")
.setStatus("Success")
.setEmoji("GUILD.ROLES.CREATE")
]
});
if (confirmation.cancelled) return
if (confirmation.success) {
await client.database.guilds.write(interaction.guild.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)
.setEmoji("CHANNEL.TEXT.EDIT")
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Attachment Log Channel")
.setDescription(
"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)
.setEmoji("CHANNEL.TEXT.EDIT")
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Log Channel")
.setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`)
.setColor("Warning")

@ -56,7 +56,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT")
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Staff Notifications Channel")
.setDescription(
"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, "-");
}
const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT")
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setTitle("Stats Channel")
.setDescription(
`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)
.setEmoji("GUILD.TICKET.ARCHIVED")
.setEmoji("GUILD.TICKET.ARCHIVED", "GUILD.TICKET.CLOSE")
.setTitle("Tickets")
.setDescription(
(options.category ? `**Category:** ${options.category.name}\n` : "") +

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

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

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

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

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

@ -26,6 +26,8 @@ class confirmationMessage {
interaction: CommandInteraction;
title = "";
emoji = "";
redEmoji: string | null = null;
timeoutText: string | null = null;
description = "";
color: "Danger" | "Warning" | "Success" = "Success";
customButtons: Record<string, CustomBoolean<unknown>> = {};
@ -40,12 +42,14 @@ class confirmationMessage {
this.title = title;
return this;
}
setEmoji(emoji: string) {
setEmoji(emoji: string, redEmoji?: string) {
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;
}
setDescription(description: string) {
setDescription(description: string, timedOut?: string) {
this.description = description;
if (timedOut) this.timeoutText = timedOut; // TODO also this
return this;
}
setColor(color: "Danger" | "Warning" | "Success") {
@ -256,13 +260,29 @@ class confirmationMessage {
}
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 (cancelled) returnValue.cancelled = true;
if (cancelled) {
await this.timeoutError()
returnValue.cancelled = true;
}
if (newReason) returnValue.newReason = newReason;
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;

Loading…
Cancel
Save