Fixed a lot of commands, 0 typing errors on those changed

pull/17/head
PineaFan 3 years ago
parent df4996fa2a
commit 100df685e2
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -1,4 +1,3 @@
package.json @Minion3665
tsconfig.json @Minion3665
.prettierrc.json @Minion3665
.prettierignore @Minion3665
@ -6,4 +5,3 @@ tsconfig.json @Minion3665
.eslintignore @Minion3665
.editorconfig @Minion3665
.github/ @Minion3665

@ -1,4 +1,5 @@
let format;
try {
format = (await import("./dist/config/format.js")).default;
} catch (e) {

@ -23,7 +23,7 @@
"node-tesseract-ocr": "^2.2.1",
"pastebin-api": "^5.1.1",
"structured-clone": "^0.2.2",
"typescript": "^4.5.5",
"typescript": "^5.0.0-dev.20230102",
"uuid": "^8.3.2"
},
"name": "nucleus",

@ -68,7 +68,7 @@ export async function create(
.setEmoji("GUILD.TICKET.OPEN")
],
components: [
new ActionRowBuilder().addComponents([
new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
new ButtonBuilder()
.setLabel("Close")
.setStyle(ButtonStyle.Danger)
@ -89,7 +89,7 @@ export async function create(
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: {

@ -3,10 +3,10 @@ import client from "../../utils/client.js";
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;

@ -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 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
}) +
`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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
"Notify user",
false,
undefined,
null,
"The user will be sent a DM",
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
@ -68,12 +67,15 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
)
.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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
],
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 callback = async (interaction: CommandInteraction): Promise<void> => {
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 @@ const check = async (interaction: CommandInteraction) => {
// 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

@ -8,9 +8,9 @@ import Discord, {
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 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
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 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
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 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
.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 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
.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 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
}
i.deferUpdate();
if (i.customId === "filter") {
filteredTypes = (i as SelectMenuInteraction).values;
filteredTypes = (i as StringSelectMenuInteraction).values;
pageIndex = null;
refresh = true;
}
@ -330,7 +337,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 callback = async (interaction: CommandInteraction): Promise<unknown> => {
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;
};

@ -263,7 +263,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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, {

@ -64,7 +64,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
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: [

@ -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 command = (builder: SlashCommandSubcommandBuilder) =>
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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
"Notify user",
false,
null,
null,
"The user will be sent a DM",
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
@ -60,53 +59,51 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
(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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} 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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setCustomId("ticket")
.setLabel("Create ticket")
.setStyle(canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary)
])
.setDisabled(createAppealTicket)
)
]
})) as Discord.Message;
let component;
@ -200,7 +198,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
if (component.customId === "here") {
await interaction.channel.send({
await interaction.channel!.send({
embeds: [
new EmojiEmbed()
.setEmoji("PUNISH.WARN.RED")
@ -220,8 +218,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.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 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
} 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 @@ const check = (interaction: CommandInteraction) => {
// 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");

@ -17,7 +17,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
});
}
let url = "";
let components = [];
let components: ActionRowBuilder[] = [];
if (tag.match(/^(http|https):\/\/[^ "]+$/)) {
url = tag;
components = [
@ -35,7 +35,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
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")

@ -7,11 +7,9 @@ import Discord, {
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";

@ -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 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.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

@ -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";

@ -2,13 +2,15 @@ import fs from "fs";
// @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",

@ -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 @@ client.on("ready", () => {
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); }

@ -5,6 +5,7 @@ import type { VerifySchema } from "../reflex/verify.js";
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 @@ class NucleusClient extends Client {
}
const client = new NucleusClient({
guilds: new Guilds(),
guilds: await new Guilds().setup(),
history: new History(),
notes: new ModNotes(),
premium: new Premium(),

@ -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 @@ async function registerCommands() {
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 @@ export default async function register() {
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)
};

@ -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";

@ -1,3 +1,4 @@
import { TextInputBuilder } from "@discordjs/builders";
import Discord, {
CommandInteraction,
Interaction,
@ -6,8 +7,8 @@ import Discord, {
ButtonBuilder,
MessageComponentInteraction,
ModalSubmitInteraction,
TextInputComponent,
ButtonStyle
ButtonStyle,
TextInputStyle
} from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
@ -65,7 +66,7 @@ class confirmationMessage {
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 @@ class confirmationMessage {
value: callbackClicked,
emoji: emoji,
active: initial ?? false,
onClick: callback,
onClick: callback ?? (async () => null),
response: null
};
return this;
@ -129,7 +130,10 @@ class confirmationMessage {
);
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 @@ class confirmationMessage {
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 @@ class confirmationMessage {
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 @@ class confirmationMessage {
.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 @@ class confirmationMessage {
}
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> {

@ -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 @@ export class Guilds {
}
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 class Premium {
export interface GuildConfig {
id: string;
version: number;
singleEventNotifications: {
statsChannelDeleted: boolean;
};
singleEventNotifications: Record<string, boolean>;
filters: {
images: {
NSFW: boolean;

@ -4,3 +4,8 @@ import getEmojiByName from "./getEmojiByName.js";
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"
}

@ -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 @@ export default async function (
try {
m.delete();
} catch (e) {
client._error(e);
client.emit("error", e as Error);
}
resolve(m);
});
@ -61,7 +61,7 @@ export async function modalInteractionCollector(
.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) => {

@ -2,6 +2,7 @@ import { Agenda } from "@hokify/agenda";
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 @@ class EventScheduler {
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 @@ class EventScheduler {
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 @@ class EventScheduler {
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: {

@ -1,3 +1,4 @@
// @ts-expect-error
import emojis from "../config/emojis.json" assert { type: "json" };
interface EmojisIndex {

@ -25,7 +25,7 @@ export const Logger = {
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) {

@ -16,6 +16,7 @@ export default async function (
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 @@ export default async function (
try {
const channel = await client.channels.fetch(data.logging.staff.channel);
if (!channel) return;
if (!channel.isTextBased()) return;
await channel.send({
embeds: [
new EmojiEmbed()

@ -12,7 +12,7 @@ export default function generateFileName(ending: string): string {
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);

Loading…
Cancel
Save