Fixed a lot of commands, 0 typing errors on those changed
diff --git a/src/actions/createModActionTicket.ts b/src/actions/createModActionTicket.ts
index 8a733cf..61a94ba 100644
--- a/src/actions/createModActionTicket.ts
+++ b/src/actions/createModActionTicket.ts
@@ -68,7 +68,7 @@
.setEmoji("GUILD.TICKET.OPEN")
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setLabel("Close")
.setStyle(ButtonStyle.Danger)
@@ -89,7 +89,7 @@
list: {
ticketFor: entry(member.id, renderUser(member)),
createdBy: entry(createdBy.id, renderUser(createdBy)),
- created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ created: entry((new Date().getTime()).toString(), renderDelta(new Date().getTime())),
ticketChannel: entry(c.id, renderChannel(c))
},
hidden: {
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
index bd4c1db..0db4232 100644
--- a/src/actions/tickets/delete.ts
+++ b/src/actions/tickets/delete.ts
@@ -3,10 +3,10 @@
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
-export default async function (interaction) {
+export default async function (interaction: Discord.CommandInteraction) {
const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
- const config = await client.database.guilds.read(interaction.guild.id);
+ const config = await client.database.guilds.read(interaction.guild!.id);
let thread = false;
if (interaction.channel instanceof Discord.ThreadChannel) thread = true;
const threadChannel = interaction.channel as Discord.ThreadChannel;
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index 5f4f41c..6deb4ad 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -1,10 +1,11 @@
-import { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, User, ButtonStyle } from "discord.js";
+import Discord, { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, User, ButtonStyle } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
import addPlurals from "../../utils/plurals.js";
import client from "../../utils/client.js";
+import { LinkWarningFooter } from "../../utils/defaultEmbeds.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
@@ -12,11 +13,10 @@
.setName("ban")
.setDescription("Bans a user from the server")
.addUserOption((option) => option.setName("user").setDescription("The user to ban").setRequired(true))
- .addStringOption((option) => option.setName("reason").setDescription("The reason for the ban").setRequired(false))
.addNumberOption((option) =>
option
.setName("delete")
- .setDescription("The days of messages to delete | Default: 0")
+ .setDescription("Delete this number of days of messages from the user | Default: 0")
.setMinValue(0)
.setMaxValue(7)
.setRequired(false)
@@ -42,9 +42,8 @@
}) +
`The user **will${notify ? "" : " not"}** be notified\n` +
`${addPlurals(
- (interaction.options.get("delete")?.value as number | null) ?? 0,
- "day"
- )} of messages will be deleted\n\n` +
+ (interaction.options.get("delete")?.value as number | null) ?? 0, "day")
+ } of messages will be deleted\n\n` +
`Are you sure you want to ban <@!${(interaction.options.getMember("user") as GuildMember).id}>?`
)
.addCustomBoolean(
@@ -52,7 +51,7 @@
"Notify user",
false,
undefined,
- null,
+ "The user will be sent a DM",
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
@@ -68,12 +67,15 @@
if (timedOut) return;
if (confirmation.success) {
reason = reason.length ? reason : null
- let dmd = false;
- let dm;
+ let dmSent = false;
+ let dmMessage;
const config = await client.database.guilds.read(interaction.guild!.id);
try {
if (notify) {
- dm = await (interaction.options.getMember("user") as GuildMember).send({
+ const messageData: {
+ embeds: EmojiEmbed[];
+ components: ActionRowBuilder<ButtonBuilder>[];
+ } = {
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED")
@@ -83,25 +85,30 @@
)
.setStatus("Danger")
],
- components: config.moderation.ban.text ? [
- new ActionRowBuilder().addComponents([
- new ButtonBuilder()
+ components: []
+ };
+ if (config.moderation.ban.text && config.moderation.ban.link) {
+ messageData.embeds[0]!.setFooter(LinkWarningFooter)
+ messageData.components.push(new ActionRowBuilder<Discord.ButtonBuilder>()
+ .addComponents(new ButtonBuilder()
.setStyle(ButtonStyle.Link)
.setLabel(config.moderation.ban.text)
- .setURL(config.moderation.ban.link!)
- ])
- ] : []
- });
- dmd = true;
+ .setURL(config.moderation.ban.link)
+ )
+ )
+ }
+ dmMessage = await (interaction.options.getMember("user") as GuildMember).send(messageData);
+ dmSent = true;
}
} catch {
- dmd = false;
+ dmSent = false;
}
try {
const member = interaction.options.getMember("user") as GuildMember;
+ const days: number = interaction.options.get("delete")?.value as number | null ?? 0;
member.ban({
- days: Number(interaction.options.getNumber("delete") ?? 0),
- reason: reason ?? "No reason provided"
+ deleteMessageSeconds: days * 24 * 60 * 60,
+ 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;
@@ -117,10 +124,10 @@
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())),
+ banned: entry(new Date().getTime().toString(), 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)),
+ accountCreated: entry(member.user.createdAt.toString(), renderDelta(member.user.createdAt.getTime())),
serverMemberCount: interaction.guild!.memberCount
},
hidden: {
@@ -139,10 +146,10 @@
],
components: []
});
- if (dmd && dm) await dm.delete();
+ if (dmSent && dmMessage) await dmMessage.delete();
return;
}
- const failed = !dmd && notify;
+ const failed = !dmSent && notify;
await interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -169,7 +176,7 @@
const check = async (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- const me = interaction.guild!.me!;
+ const me = interaction.guild!.members.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;
@@ -185,13 +192,13 @@
// 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");
+ if (!me.permissions.has("BanMembers")) 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 === me.id) throw new Error("I cannot ban myself");
// Allow the owner to ban anyone
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");
+ if (!member.permissions.has("BanMembers")) throw new Error("You do not have the *Ban Members* permission");
// Check if the user is below on the role list
if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
// Allow ban
diff --git a/src/commands/mod/info.ts b/src/commands/mod/info.ts
index bed0f86..12c414f 100644
--- a/src/commands/mod/info.ts
+++ b/src/commands/mod/info.ts
@@ -8,9 +8,9 @@
ButtonBuilder,
MessageComponentInteraction,
ModalSubmitInteraction,
- SelectMenuInteraction,
TextInputComponent,
- ButtonStyle
+ ButtonStyle,
+ StringSelectMenuInteraction
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -101,8 +101,15 @@
let currentYear = new Date().getFullYear();
let pageIndex: number | null = null;
let history, current: TimelineSection;
+ history = await client.database.history.read(member.guild.id, member.id, currentYear);
+ history = history
+ .sort(
+ (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
+ b.occurredAt.getTime() - a.occurredAt.getTime()
+ )
+ .reverse();
let m: Message;
- let refresh = true;
+ let refresh = false;
let filteredTypes: string[] = [];
let openFilterPane = false;
let timedOut = false;
@@ -149,7 +156,7 @@
const components = (
openFilterPane
? [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents(
new Discord.SelectMenuBuilder()
.setOptions(
Object.entries(types).map(([key, value]) => ({
@@ -163,11 +170,11 @@
.setMaxValues(Object.keys(types).length)
.setCustomId("filter")
.setPlaceholder("Select at least one event")
- ])
+ )
]
: []
).concat([
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId("prevYear")
.setLabel((currentYear - 1).toString())
@@ -187,7 +194,7 @@
.setStyle(ButtonStyle.Secondary)
.setDisabled(currentYear === new Date().getFullYear())
]),
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setLabel("Mod notes")
.setCustomId("modNotes")
@@ -258,7 +265,7 @@
}
i.deferUpdate();
if (i.customId === "filter") {
- filteredTypes = (i as SelectMenuInteraction).values;
+ filteredTypes = (i as StringSelectMenuInteraction).values;
pageIndex = null;
refresh = true;
}
@@ -330,7 +337,7 @@
.setStatus("Success")
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setLabel(`${note ? "Modify" : "Create"} note`)
.setStyle(ButtonStyle.Primary)
@@ -353,11 +360,11 @@
}
if (i.customId === "modify") {
await i.showModal(
- new Discord.Modal()
+ new Discord.ModalBuilder()
.setCustomId("modal")
.setTitle("Editing moderator note")
.addComponents(
- new ActionRowBuilder<TextInputComponent>().addComponents(
+ new ActionRowBuilder<Discord.TextInputComponent>().addComponents(
new TextInputComponent()
.setCustomId("note")
.setLabel("Note")
@@ -377,7 +384,7 @@
.setEmoji("GUILD.TICKET.OPEN")
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
@@ -415,7 +422,7 @@
const check = (interaction: CommandInteraction) => {
const member = interaction.member as GuildMember;
- if (!member.permissions.has("MODERATE_MEMBERS"))
+ if (!member.permissions.has("ModerateMembers"))
throw new Error("You do not have the *Moderate Members* permission");
return true;
};
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index 1f541c8..db0d68b 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -263,7 +263,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("naturalUnmute", new Date().getTime() + muteTime * 1000, {
diff --git a/src/commands/mod/unmute.ts b/src/commands/mod/unmute.ts
index 2dd3a2a..0ce63d1 100644
--- a/src/commands/mod/unmute.ts
+++ b/src/commands/mod/unmute.ts
@@ -64,7 +64,7 @@
}
const member = interaction.options.getMember("user") as GuildMember;
try {
- member.timeout(0, reason ?? "No reason provided");
+ member.timeout(0, reason ?? "*No reason provided*");
} catch {
await interaction.editReply({
embeds: [
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index 2fc5a06..5125587 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -1,10 +1,11 @@
import Discord, { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
-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";
import { create, areTicketsEnabled } from "../../actions/createModActionTicket.js";
import client from "../../utils/client.js";
+import { LinkWarningFooter } from "../../utils/defaultEmbeds.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
@@ -15,7 +16,7 @@
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { log, NucleusColors, renderUser, entry } = client.logger;
// TODO:[Modals] Replace this with a modal
- let reason = null;
+ let reason: string | null = null;
let notify = true;
let createAppealTicket = false;
let confirmation;
@@ -27,20 +28,18 @@
.setTitle("Warn")
.setDescription(
keyValueList({
- user: renderUser(interaction.options.getUser("user")),
+ user: renderUser(interaction.options.getUser("user")!),
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 warn <@!${(interaction.options.getMember("user") as GuildMember).id}>?`
)
.setColor("Danger")
.addCustomBoolean(
"appeal",
"Create appeal ticket",
- !(await areTicketsEnabled(interaction.guild.id)),
- async () =>
- await create(interaction.guild, interaction.options.getUser("user"), interaction.user, reason),
- "An appeal ticket will be created when Confirm is clicked",
+ !(await areTicketsEnabled(interaction.guild!.id)),
+ async () => await create(interaction.guild!, interaction.options.getUser("user")!, interaction.user, reason),
+ "An appeal ticket will be created",
"CONTROL.TICKET",
createAppealTicket
)
@@ -49,7 +48,7 @@
"Notify user",
false,
null,
- null,
+ "The user will be sent a DM",
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
@@ -60,53 +59,51 @@
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;
+ notify = confirmation.components["notify"]!.active;
+ createAppealTicket = confirmation.components["appeal"]!.active;
}
} while (!timedOut && !success)
if (timedOut) return;
if (confirmation.success) {
- let dmd = false;
+ let dmSent = false;
+ const config = await client.database.guilds.read(interaction.guild!.id);
try {
if (notify) {
- const config = await client.database.guilds.read(interaction.guild.id);
- await (interaction.options.getMember("user") as GuildMember).send({
+ const messageData: {
+ embeds: EmojiEmbed[];
+ components: ActionRowBuilder<ButtonBuilder>[];
+ } = {
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.WARN.RED")
.setTitle("Warned")
.setDescription(
- `You have been warned in ${interaction.guild.name}` +
- (reason ? ` for:\n> ${reason}` : ".") +
+ `You have been warned in ${interaction.guild!.name}` +
+ (reason ? ` for:\n> ${reason}` : ".\n*No reason was provided*") +
"\n\n" +
- (confirmation.components.appeal.response
- ? `You can appeal this here ticket: <#${confirmation.components.appeal.response}>`
+ (createAppealTicket
+ ? `You can appeal this in the ticket created in <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus("Danger")
- .setFooter({
- text: config.moderation.warn.text
- ? "The button below is set by the server admins. Do not enter any passwords or other account details on the linked site."
- : "",
- iconURL:
- "https://cdn.discordapp.com/emojis/952295894370369587.webp?size=128&quality=lossless"
- })
],
- components: config.moderation.warn.text
- ? [
- new ActionRowBuilder().addComponents([
- new ButtonBuilder()
- .setStyle(ButtonStyle.Link)
- .setLabel(config.moderation.warn.text)
- .setURL(config.moderation.warn.link)
- ])
- ]
- : []
- });
- dmd = true;
+ components: []
+ };
+ if (config.moderation.warn.text && config.moderation.warn.link) {
+ messageData.embeds[0]!.setFooter(LinkWarningFooter)
+ messageData.components.push(new ActionRowBuilder<Discord.ButtonBuilder>()
+ .addComponents(new ButtonBuilder()
+ .setStyle(ButtonStyle.Link)
+ .setLabel(config.moderation.warn.text)
+ .setURL(config.moderation.warn.link)
+ )
+ )
+ }
+ await (interaction.options.getMember("user") as GuildMember).send(messageData);
+ dmSent = true;
}
- } catch {
- dmd = false;
+ } catch (e) {
+ dmSent = false;
}
const data = {
meta: {
@@ -122,22 +119,22 @@
(interaction.options.getMember("user") as GuildMember).user.id,
renderUser((interaction.options.getMember("user") as GuildMember).user)
),
- warnedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- reason: reason ? `\n> ${reason}` : "No reason provided"
+ warnedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
+ reason: reason ? `\n> ${reason}` : "*No reason provided*"
},
hidden: {
- guild: interaction.guild.id
+ guild: interaction.guild!.id
}
};
await client.database.history.create(
"warn",
- interaction.guild.id,
+ interaction.guild!.id,
(interaction.options.getMember("user") as GuildMember).user,
interaction.user,
reason
);
log(data);
- const failed = !dmd && notify;
+ const failed = !dmSent && notify;
if (!failed) {
await interaction.editReply({
embeds: [
@@ -146,8 +143,8 @@
.setTitle("Warn")
.setDescription(
"The user was warned" +
- (confirmation.components.appeal.response
- ? ` and an appeal ticket was opened in <#${confirmation.components.appeal.response}>`
+ (createAppealTicket
+ ? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus("Success")
@@ -157,7 +154,7 @@
} else {
const canSeeChannel = (interaction.options.getMember("user") as GuildMember)
.permissionsIn(interaction.channel as Discord.TextChannel)
- .has("VIEW_CHANNEL");
+ .has("ViewChannel");
const m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -167,7 +164,7 @@
.setStatus("Danger")
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
new Discord.ButtonBuilder().setCustomId("log").setLabel("Ignore and log").setStyle(ButtonStyle.Secondary),
new Discord.ButtonBuilder()
.setCustomId("here")
@@ -178,7 +175,8 @@
.setCustomId("ticket")
.setLabel("Create ticket")
.setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary)
- ])
+ .setDisabled(createAppealTicket)
+ )
]
})) as Discord.Message;
let component;
@@ -200,7 +198,7 @@
});
}
if (component.customId === "here") {
- await interaction.channel.send({
+ await interaction.channel!.send({
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.WARN.RED")
@@ -220,8 +218,8 @@
.setTitle("Warn")
.setDescription(
"The user was warned" +
- (confirmation.response
- ? ` and an appeal ticket was opened in <#${confirmation.response}>`
+ (createAppealTicket
+ ? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>`
: "")
)
.setStatus("Success")
@@ -241,8 +239,8 @@
});
} else if (component.customId === "ticket") {
const ticketChannel = await create(
- interaction.guild,
- interaction.options.getUser("user"),
+ interaction.guild!,
+ interaction.options.getUser("user")!,
interaction.user,
reason,
"Warn Notification"
@@ -296,7 +294,7 @@
// Allow the owner to warn anyone
if (member.id === interaction.guild!.ownerId) return true;
// Check if the user has moderate_members permission
- if (!member.permissions.has("MODERATE_MEMBERS"))
+ if (!member.permissions.has("ModerateMembers"))
throw new Error("You do not have the *Moderate Members* permission");
// Check if the user is below on the role list
if (!(memberPos > applyPos)) throw new Error("You do not have a role higher than that member");
diff --git a/src/commands/tag.ts b/src/commands/tag.ts
index 7a1e8fa..c54d7ab 100644
--- a/src/commands/tag.ts
+++ b/src/commands/tag.ts
@@ -17,7 +17,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tag")
- .setDescription(`Tag \`${interaction.options.getString("tag")}\` does not exist`)
+ .setDescription(`Tag \`${interaction.options.get("tag")}\` does not exist`)
.setEmoji("PUNISH.NICKNAME.RED")
.setStatus("Danger")
],
@@ -25,7 +25,7 @@
});
}
let url = "";
- let components = [];
+ let components: ActionRowBuilder[] = [];
if (tag.match(/^(http|https):\/\/[^ "]+$/)) {
url = tag;
components = [
@@ -35,7 +35,7 @@
return await interaction.reply({
embeds: [
new EmojiEmbed()
- .setTitle(interaction.options.getString("tag"))
+ .setTitle(interaction.options.get("tag").value)
.setDescription(tag)
.setEmoji("PUNISH.NICKNAME.GREEN")
.setStatus("Success")
diff --git a/src/commands/user/about.ts b/src/commands/user/about.ts
index 44e6d3b..d62a426 100644
--- a/src/commands/user/about.ts
+++ b/src/commands/user/about.ts
@@ -7,11 +7,9 @@
Component,
ButtonBuilder,
MessageComponentInteraction,
- MessageSelectOptionData,
- SelectMenuInteraction,
ButtonStyle
} 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 generateKeyValueList from "../../utils/generateKeyValueList.js";
diff --git a/src/commands/user/avatar.ts b/src/commands/user/avatar.ts
index 00be0c9..5980072 100644
--- a/src/commands/user/avatar.ts
+++ b/src/commands/user/avatar.ts
@@ -1,5 +1,6 @@
-import Discord, { CommandInteraction } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { CommandInteraction } from "discord.js";
+import type Discord from "discord.js";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import generateKeyValueList from "../../utils/generateKeyValueList.js";
import client from "../../utils/client.js";
@@ -24,10 +25,10 @@
.setDescription(
generateKeyValueList({
member: renderUser(member.user),
- url: member.user.displayAvatarURL({ dynamic: true })
+ url: member.user.displayAvatarURL({ forceStatic: false })
})
)
- .setImage(member.user.displayAvatarURL({ dynamic: true }))
+ .setImage(member.user.displayAvatarURL({ forceStatic: true }))
],
ephemeral: true,
fetchReply: true
diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
index dd736aa..06f498a 100644
--- a/src/commands/user/track.ts
+++ b/src/commands/user/track.ts
@@ -1,6 +1,6 @@
import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
import Discord, { CommandInteraction, GuildMember, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle } 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 addPlural from "../../utils/plurals.js";
diff --git a/src/config/format.ts b/src/config/format.ts
index 3890f66..ddd164e 100644
--- a/src/config/format.ts
+++ b/src/config/format.ts
@@ -2,13 +2,15 @@
// @ts-expect-error
import * as readLine from "node:readline/promises";
-const defaultDict = {
+const defaultDict: Record<string, string | string[] | boolean> = {
developmentToken: "Your development bot token (Used for testing in one server, rather than production)",
developmentGuildID: "Your development guild ID",
enableDevelopment: true,
token: "Your bot token",
managementGuildID: "Your management guild ID (Used for running management commands on the bot)",
owners: [],
+ commandsFolder: "Your built commands folder (usually dist/commands)",
+ eventsFolder: "Your built events folder (usually dist/events)",
verifySecret:
"If using verify, enter a code here which matches the secret sent back by your website. You can use a random code if you do not have one already. (Optional)",
mongoUrl: "Your Mongo connection string, e.g. mongodb://127.0.0.1:27017",
diff --git a/src/index.ts b/src/index.ts
index eac8818..f7fdde5 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,6 @@
import runServer from "./api/index.js";
import client from "./utils/client.js";
+// @ts-expect-error
import config from "./config/main.json" assert { type: "json" };
import register from "./utils/commandRegistration/register.js";
@@ -11,6 +12,9 @@
process.on("unhandledRejection", (err) => {
console.error(err);
});
+process.on("uncaughtException", (err) => {
+ console.error(err);
+});
if (config.enableDevelopment) { await client.login(config.developmentToken); }
else { await client.login(config.token); }
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 61cf3bf..53267f2 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -5,6 +5,7 @@
import { Guilds, History, ModNotes, Premium } from "../utils/database.js";
import EventScheduler from "../utils/eventScheduler.js";
import type { RoleMenuSchema } from "../actions/roleMenu.js";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
@@ -38,7 +39,7 @@
}
const client = new NucleusClient({
- guilds: new Guilds(),
+ guilds: await new Guilds().setup(),
history: new History(),
notes: new ModNotes(),
premium: new Premium(),
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 1b55496..64f6e77 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -1,14 +1,16 @@
import { Interaction, SlashCommandBuilder } from 'discord.js';
+// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import client from "../client.js";
import fs from "fs";
-import Discord from "discord.js";
const colours = {
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
+ blue: "\x1b[34m",
+ purple: "\x1b[35m",
none: "\x1b[0m"
}
@@ -52,10 +54,10 @@
if (developmentMode) {
const guild = await client.guilds.fetch(config.developmentGuildID);
if (updateCommands) guild.commands.set(processed);
- console.log(`Commands registered in ${guild.name}`)
+ console.log(`${colours.purple}Commands registered in ${guild.name}${colours.none}`)
} else {
if (updateCommands) client.application!.commands.set(processed);
- console.log(`Commands registered globally`)
+ console.log(`${colours.blue}Commands registered globally${colours.none}`)
}
};
@@ -120,4 +122,7 @@
await registerCommandHandler();
await registerEvents();
console.log(`${colours.green}Registered commands and events${colours.none}`)
+ console.log(
+ (config.enableDevelopment ? `${colours.purple}Bot started in Development mode` :
+ `${colours.blue}Bot started in Production mode`) + colours.none)
};
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index 76ecabe..45cb8f1 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -1,5 +1,6 @@
import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
import type { SlashCommandBuilder } from "discord.js";
+// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import getSubcommandsInFolder from "./getFilesInFolder.js";
import client from "../client.js";
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 18e6ea0..87724f3 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,3 +1,4 @@
+import { TextInputBuilder } from "@discordjs/builders";
import Discord, {
CommandInteraction,
Interaction,
@@ -6,8 +7,8 @@
ButtonBuilder,
MessageComponentInteraction,
ModalSubmitInteraction,
- TextInputComponent,
- ButtonStyle
+ ButtonStyle,
+ TextInputStyle
} from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
@@ -65,7 +66,7 @@
customId: string,
title: string,
disabled: boolean,
- callback: () => Promise<unknown> = async () => null,
+ callback: (() => Promise<unknown>) | null = async () => null,
callbackClicked: string | null,
emoji?: string,
initial?: boolean
@@ -76,7 +77,7 @@
value: callbackClicked,
emoji: emoji,
active: initial ?? false,
- onClick: callback,
+ onClick: callback ?? (async () => null),
response: null
};
return this;
@@ -129,7 +130,10 @@
);
const components = [];
for (let i = 0; i < fullComponents.length; i += 5) {
- components.push(new ActionRowBuilder().addComponents(fullComponents.slice(i, i + 5)));
+ components.push(new ActionRowBuilder<
+ Discord.ButtonBuilder | Discord.StringSelectMenuBuilder |
+ Discord.RoleSelectMenuBuilder | Discord.UserSelectMenuBuilder
+ >().addComponents(fullComponents.slice(i, i + 5)));
}
const object = {
embeds: [
@@ -155,7 +159,7 @@
let m: Message;
try {
if (editOnly) {
- m = (await this.interaction.editReply(object)) as Message;
+ m = (await this.interaction.editReply(object)) as unknown as Message;
} else {
m = (await this.interaction.reply(object)) as unknown as Message;
}
@@ -194,17 +198,17 @@
continue;
} else if (component.customId === "reason") {
await component.showModal(
- new Discord.Modal()
+ new Discord.ModalBuilder()
.setCustomId("modal")
.setTitle("Editing reason")
.addComponents(
- new ActionRowBuilder<TextInputComponent>().addComponents(
- new TextInputComponent()
+ new ActionRowBuilder<TextInputBuilder>().addComponents(
+ new TextInputBuilder()
.setCustomId("reason")
.setLabel("Reason")
.setMaxLength(2000)
.setRequired(false)
- .setStyle("PARAGRAPH")
+ .setStyle(TextInputStyle.Paragraph)
.setPlaceholder("Spammed in #general")
.setValue(this.reason ? this.reason : "")
)
@@ -219,13 +223,13 @@
.setEmoji(this.emoji)
],
components: [
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel("Back")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle(ButtonStyle.Primary)
.setCustomId("back")
- ])
+ )
]
});
let out;
@@ -269,7 +273,12 @@
}
if (newReason) returnValue.newReason = newReason;
- return returnValue;
+ const typedReturnValue = returnValue as {cancelled: true} |
+ { success: boolean, components: Record<string, CustomBoolean<unknown>>, newReason?: string} |
+ { newReason: string, components: Record<string, CustomBoolean<unknown>> } |
+ { components: Record<string, CustomBoolean<unknown>> };
+
+ return typedReturnValue;
}
async timeoutError(): Promise<void> {
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 2ae6af9..2624fc9 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,5 +1,6 @@
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
const mongoClient = new MongoClient(config.mongoUrl);
@@ -16,6 +17,7 @@
}
async setup(): Promise<Guilds> {
+ // @ts-expect-error
this.defaultData = (await import("../config/default.json", { assert: { type: "json" } }))
.default as unknown as GuildConfig;
return this;
@@ -184,9 +186,7 @@
export interface GuildConfig {
id: string;
version: number;
- singleEventNotifications: {
- statsChannelDeleted: boolean;
- };
+ singleEventNotifications: Record<string, boolean>;
filters: {
images: {
NSFW: boolean;
diff --git a/src/utils/defaultEmbeds.ts b/src/utils/defaultEmbeds.ts
index 2334504..39a6080 100644
--- a/src/utils/defaultEmbeds.ts
+++ b/src/utils/defaultEmbeds.ts
@@ -4,3 +4,8 @@
export const LoadingEmbed = [
new EmojiEmbed().setDescription(`${getEmojiByName("NUCLEUS.LOADING")} One moment...`).setStatus("Danger")
];
+
+export const LinkWarningFooter = {
+ text: "The button below will take you to a website set by the server moderators. Do not enter any passwords unless it is from a trusted website.",
+ iconURL: "https://cdn.discordapp.com/emojis/952295894370369587.webp?size=128&quality=lossless"
+}
\ No newline at end of file
diff --git a/src/utils/dualCollector.ts b/src/utils/dualCollector.ts
index abc6bb3..714a2d9 100644
--- a/src/utils/dualCollector.ts
+++ b/src/utils/dualCollector.ts
@@ -1,4 +1,4 @@
-import Discord, { Interaction, Message, MessageComponentInteraction } from "discord.js";
+import Discord, { Client, Interaction, Message, MessageComponentInteraction } from "discord.js";
import client from "./client.js";
export default async function (
@@ -26,7 +26,7 @@
try {
m.delete();
} catch (e) {
- client._error(e);
+ client.emit("error", e as Error);
}
resolve(m);
});
@@ -61,7 +61,7 @@
.on("collect", (i: Interaction) => {
resolve(i);
});
- const mod = new Discord.InteractionCollector(client, {
+ const mod = new Discord.InteractionCollector(client as Client, {
filter: (i: Interaction) => modalFilter(i),
time: 300000
}).on("collect", async (i: Interaction) => {
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index 203e05b..0a32a1e 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -2,6 +2,7 @@
import client from "./client.js";
import * as fs from "fs";
import * as path from "path";
+// @ts-expect-error
import config from "../config/main.json" assert { type: "json" };
class EventScheduler {
@@ -19,11 +20,11 @@
const guild = await client.guilds.fetch(job.attrs.data.guild);
const user = await guild.members.fetch(job.attrs.data.user);
const role = await guild.roles.fetch(job.attrs.data.role);
- await user.roles.remove(role);
+ if (role) await user.roles.remove(role);
await job.remove();
});
this.agenda.define("deleteFile", async (job) => {
- fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), client._error);
+ fs.rm(path.resolve("dist/utils/temp", job.attrs.data.fileName), (e) => { client.emit("error", e as Error); });
await job.remove();
});
this.agenda.define("naturalUnmute", async (job) => {
@@ -34,7 +35,7 @@
try {
await client.database.history.create("unmute", user.guild.id, user.user, null, null, null, null);
} catch (e) {
- client._error(e);
+ client.emit("error", e as Error);
}
const data = {
meta: {
@@ -48,7 +49,7 @@
list: {
memberId: entry(user.user.id, `\`${user.user.id}\``),
name: entry(user.user.id, renderUser(user.user)),
- unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ unmuted: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
unmutedBy: entry(null, "*Time out ended*")
},
hidden: {
diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts
index 3fa2b53..7824982 100644
--- a/src/utils/getEmojiByName.ts
+++ b/src/utils/getEmojiByName.ts
@@ -1,3 +1,4 @@
+// @ts-expect-error
import emojis from "../config/emojis.json" assert { type: "json" };
interface EmojisIndex {
diff --git a/src/utils/log.ts b/src/utils/log.ts
index a578b69..b097798 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -25,7 +25,7 @@
const delta = num2 - num1;
return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`;
},
- entry(value: string, displayValue: string): { value: string; displayValue: string } {
+ entry(value: string | null, displayValue: string): { value: string | null; displayValue: string } {
return { value: value, displayValue: displayValue };
},
renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) {
diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts
index 8f011e3..e762487 100644
--- a/src/utils/singleNotify.ts
+++ b/src/utils/singleNotify.ts
@@ -16,6 +16,7 @@
severity: "Critical" | "Warning" | "Info" = "Info"
) {
const data = await client.database.guilds.read(guild);
+ if (data.logging.staff.channel === null) return;
if (message === true) {
return await client.database.guilds.write(guild, {
[`singleEventNotifications.${type}`]: false
@@ -28,6 +29,7 @@
try {
const channel = await client.channels.fetch(data.logging.staff.channel);
if (!channel) return;
+ if (!channel.isTextBased()) return;
await channel.send({
embeds: [
new EmojiEmbed()
diff --git a/src/utils/temp/generateFileName.ts b/src/utils/temp/generateFileName.ts
index 8534846..3aab64c 100644
--- a/src/utils/temp/generateFileName.ts
+++ b/src/utils/temp/generateFileName.ts
@@ -12,7 +12,7 @@
if (fs.existsSync(`./${fileName}`)) {
fileName = generateFileName(ending);
}
- client.database.eventScheduler.schedule("deleteFile", new Date().getTime() + 60 * 1000, {
+ client.database.eventScheduler.schedule("deleteFile", (new Date().getTime() + 60 * 1000).toString(), {
fileName: `${fileName}.${ending}`
});
return path.join(__dirname, fileName + "." + ending);