Fix all missing await issues (eslint)

pull/42/head
Skyler Grey 3 years ago
parent d1157318c0
commit f4f21c4e18
Signed by: Minion3665
GPG Key ID: 1AFD10256B3C714D

@ -23,6 +23,8 @@
"caughtErrorsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-explicit-any": "error"
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-floating-promises": "error"
}
}

@ -36,6 +36,7 @@
"dev": "rm -rf dist && eslint src --fix && tsc && node --experimental-json-modules --enable-source-maps dist/index.js",
"force-dev": "clear; rm -rf dist; tsc-suppress && node --experimental-json-modules --enable-source-maps dist/index.js",
"lint": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint src; echo 'To auto-fix everything possible, please run `yarn lint-fix`'; true",
"lint-no-stylecheck": "echo 'Linting...'; eslint src; echo 'A full lint and style check is required for PRs to be accepted. Please run `yarn lint` before committing'; true",
"lint-fix": "echo 'Fixing eslint issues...'; eslint src --fix; echo 'Reformatting...'; prettier --write --loglevel warn --cache .; true",
"lint-list": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint src; echo 'To view errors in more detail, please run `yarn lint`'; true",
"lint-ci": "echo 'Style checking...' && prettier --check . && echo 'Linting...' && eslint src",

@ -115,8 +115,8 @@ export async function create(
type: Discord.ChannelType.PrivateThread,
reason: "Creating ticket"
})) as Discord.PrivateThreadChannel;
c.members.add(user.id);
c.members.add(createdBy.id);
await c.members.add(user.id);
await c.members.add(createdBy.id);
try {
await c.send({
content:
@ -174,7 +174,7 @@ export async function create(
guild: guild.id
}
};
log(data);
await log(data);
return c.id;
}

@ -175,7 +175,7 @@ export async function callback(interaction: CommandInteraction | ButtonInteracti
console.log(e);
return;
}
component.deferUpdate();
await component.deferUpdate();
}
}
@ -246,7 +246,7 @@ export async function callback(interaction: CommandInteraction | ButtonInteracti
console.log(e);
return;
}
component.deferUpdate();
await component.deferUpdate();
if (component.customId === "back") {
page = Math.max(0, page - 1);
} else if (component.customId === "next") {

@ -155,7 +155,7 @@ export default async function (interaction: CommandInteraction | ButtonInteracti
new ActionRowBuilder<ButtonBuilder>().addComponents(formattedTicketTypes.slice(i, i + 5))
);
}
component.update({
await component.update({
embeds: [
new EmojiEmbed()
.setTitle("Create Ticket")
@ -280,7 +280,7 @@ export default async function (interaction: CommandInteraction | ButtonInteracti
type: Discord.ChannelType.PrivateThread,
reason: "Creating ticket"
})) as Discord.PrivateThreadChannel;
c.members.add(interaction.member!.user.id);
await c.members.add(interaction.member!.user.id);
try {
await c.send({
content:
@ -357,7 +357,7 @@ export default async function (interaction: CommandInteraction | ButtonInteracti
guild: interaction.guild.id
}
};
log(data);
await log(data);
await interaction.editReply({
embeds: [
new EmojiEmbed()

@ -78,7 +78,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
guild: interaction.guild.id
}
};
log(data);
await log(data);
await channel.delete();
} else if (status === "Active") {
@ -86,12 +86,12 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
// Archive the ticket
await interaction.channel.fetch();
if (channel.isThread()) {
channel.setName(`${channel.name.replace("Active", "Archived")}`);
channel.members.remove(channel.name.split(" - ")[1]!);
await channel.setName(`${channel.name.replace("Active", "Archived")}`);
await channel.members.remove(channel.name.split(" - ")[1]!);
} else {
channel.setTopic(`${(channel.topic ?? "").replace("Active", "Archived")}`);
await channel.setTopic(`${(channel.topic ?? "").replace("Active", "Archived")}`);
if (!channel.topic!.includes("Archived")) {
channel.setTopic("0 Archived");
await channel.setTopic("0 Archived");
}
await channel.permissionOverwrites.delete(channel.topic!.split(" ")[0]!);
}
@ -153,7 +153,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
guild: interaction.guild.id
}
};
log(data);
await log(data);
}
return;
}
@ -170,28 +170,28 @@ async function purgeByUser(member: string, guild: string) {
if (tickets.type === Discord.ChannelType.GuildCategory) {
// For channels, the topic is the user ID, then the word Active
const category = tickets as Discord.CategoryChannel;
category.children.cache.forEach((element) => {
for (const [_id, element] of category.children.cache) {
if (!(element.type === Discord.ChannelType.GuildText)) return;
if (!((element as Discord.TextChannel).topic ?? "").includes(member)) return;
try {
element.delete();
await element.delete();
deleted++;
} catch (e) {
console.error(e);
}
});
};
} else {
// For threads, the name is the users name, id, then the word Active
const channel = tickets as Discord.TextChannel;
channel.threads.cache.forEach((element: Discord.ThreadChannel) => {
for (const [_id, element] of channel.threads.cache) {
if (!element.name.includes(member)) return;
try {
element.delete();
await element.delete();
deleted++;
} catch (e) {
console.error(e);
}
});
};
}
if (!deleted) return;
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
@ -214,7 +214,7 @@ async function purgeByUser(member: string, guild: string) {
guild: guild
}
};
log(data);
await log(data);
}
export { purgeByUser };

@ -35,7 +35,7 @@ const runServer = (client: NucleusClient) => {
await member.roles.add(client.verify[code]!.rID);
const interaction = client.verify[code]!.interaction;
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Verify")
@ -70,7 +70,7 @@ const runServer = (client: NucleusClient) => {
guild: guild.id
}
};
log(data);
await log(data);
} catch {
res.sendStatus(500);
}
@ -80,12 +80,12 @@ const runServer = (client: NucleusClient) => {
}
});
app.get("/verify/:code", jsonParser, function (req: express.Request, res: express.Response) {
app.get("/verify/:code", jsonParser, async function (req: express.Request, res: express.Response) {
const code = req.params.code;
if (client.verify[code]) {
try {
const interaction = client.verify[code]!.interaction;
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Verify")
@ -124,12 +124,12 @@ const runServer = (client: NucleusClient) => {
}
});
app.get("/rolemenu/:code", jsonParser, function (req: express.Request, res: express.Response) {
app.get("/rolemenu/:code", jsonParser, async function (req: express.Request, res: express.Response) {
const code = req.params.code;
if (client.roleMenu[code] !== undefined) {
try {
const interaction = client.roleMenu[code]!.interaction;
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Roles")

@ -266,7 +266,7 @@ async function showHistory(member: Discord.GuildMember, interaction: CommandInte
}
});
} catch (e) {
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")

@ -126,7 +126,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem
dmSent = false;
}
try {
member.ban({
await member.ban({
deleteMessageSeconds: deleteDays * 24 * 60 * 60,
reason: reason ?? "*No reason provided*"
});
@ -159,7 +159,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem
guild: interaction.guild.id
}
};
log(data);
await log(data);
} catch {
await interaction.editReply({
embeds: [

@ -114,7 +114,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem
dmSent = false;
}
try {
member.kick(reason || "No reason provided");
await member.kick(reason || "No reason provided");
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
@ -157,7 +157,7 @@ const callback = async (interaction: CommandInteraction | ButtonInteraction, mem
data.list.joined = entry(member.joinedTimestamp.toString(), renderDelta(member.joinedTimestamp));
}
await client.database.history.create("kick", interaction.guild.id, member.user, interaction.user, reason);
log(data);
await log(data);
} catch {
await interaction.editReply({
embeds: [

@ -132,7 +132,7 @@ const callback = async (
} catch {
return;
}
component.deferUpdate();
await component.deferUpdate();
if (component.customId === "cancel")
return interaction.editReply({
embeds: [
@ -389,7 +389,7 @@ const callback = async (
guild: interaction.guild.id
}
};
log(data);
await log(data);
const failed = !status.dm && notify;
await interaction.editReply({
embeds: [

@ -153,7 +153,7 @@ const callback = async (
let before: string | null;
try {
before = member.nickname;
member.setNickname(newNickname ?? null, "Nucleus Nickname command");
await member.setNickname(newNickname ?? null, "Nucleus Nickname command");
await client.database.history.create(
"nickname",
interaction.guild!.id,
@ -202,7 +202,7 @@ const callback = async (
guild: interaction.guild!.id
}
};
log(data);
await log(data);
const failed = !dmSent && notify;
await interaction.editReply({
embeds: [

@ -100,7 +100,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
})) as Discord.Message;
let component;
try {
component = m.awaitMessageComponent({
component = await m.awaitMessageComponent({
filter: (i) => i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id,
time: 300000
});
@ -108,12 +108,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
timedOut = true;
continue;
}
(await component).deferUpdate();
if ((await component).customId === "done") {
await component.deferUpdate();
if (component.customId === "done") {
amountSelected = true;
continue;
}
const amount = parseInt((await component).customId);
const amount = parseInt(component.customId);
let messages: Discord.Message[] = [];
await (interaction.channel as TextChannel).messages.fetch({ limit: amount }).then(async (ms) => {
@ -167,7 +167,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
guild: interaction.guild.id
}
};
log(data);
await log(data);
const newOut = await client.database.transcripts.createTranscript(
"purge",
deleted,
@ -209,7 +209,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
return;
}
if (component.customId === "download") {
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
@ -221,7 +221,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
files: [attachmentObject]
});
} else {
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
@ -261,12 +261,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
} else {
const toDelete = (
await (
await (interaction.channel as TextChannel).messages.fetch({
limit: 100
})
).filter((m) => m.author.id === user.id)
).first(interaction.options.get("amount")?.value as number);
await (interaction.channel as TextChannel).messages.fetch({
limit: 100
})
)
.filter((m) => m.author.id === user.id)
.first(interaction.options.get("amount")?.value as number);
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
}
} catch (e) {
@ -326,7 +326,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
guild: interaction.guild.id
}
};
log(data);
await log(data);
const messageArray: Message[] = messages
.filter(
(message) =>

@ -51,7 +51,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.send();
if (confirmation.cancelled || !confirmation.success) return;
try {
(interaction.channel as TextChannel).setRateLimitPerUser(time);
await (interaction.channel as TextChannel).setRateLimitPerUser(time);
} catch (e) {
await interaction.editReply({
embeds: [

@ -128,7 +128,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
try {
const member = interaction.options.getMember("user") as GuildMember;
const days: number = (interaction.options.get("delete")?.value as number | null) ?? 0;
member.ban({
await member.ban({
deleteMessageSeconds: days * 24 * 60 * 60,
reason: reason ?? "*No reason provided*"
});
@ -162,7 +162,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
guild: interaction.guild.id
}
};
log(data);
await log(data);
} catch {
await interaction.editReply({
embeds: [

@ -76,7 +76,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
guild: interaction.guild.id
}
};
log(data);
await log(data);
} catch {
await interaction.editReply({
embeds: [

@ -76,7 +76,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
const member = interaction.options.getMember("user") as GuildMember;
try {
member.timeout(0, reason ?? "*No reason provided*");
await member.timeout(0, reason ?? "*No reason provided*");
} catch {
await interaction.editReply({
embeds: [
@ -122,7 +122,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
guild: interaction.guild.id
}
};
log(data);
await log(data);
const failed = !dmSent && notify;
await interaction.editReply({
embeds: [

@ -153,7 +153,7 @@ const callback = async (
}
};
await client.database.history.create("warn", interaction.guild.id, member.user, interaction.user, reason);
log(data);
await log(data);
const failed = !dmSent && notify;
if (!failed) {
await interaction.editReply({

@ -6,7 +6,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
builder.setName("guide").setDescription("Shows the welcome guide for the bot");
const callback = async (interaction: CommandInteraction) => {
guide(interaction.guild!, interaction);
await guide(interaction.guild!, interaction);
};
export { command };

@ -7,7 +7,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
builder.setName("invite").setDescription("Invites Nucleus to your server");
const callback = async (interaction: CommandInteraction): Promise<void> => {
interaction.reply({
await interaction.reply({
embeds: [
new EmojiEmbed()
.setTitle("Invite")

@ -13,7 +13,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
const initial = Date.now();
await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
const ping = Date.now() - initial;
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Ping")

@ -106,7 +106,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
const member = await (await interaction.client.guilds.fetch("684492926528651336")).members
.fetch(interaction.user.id)
.catch(() => {
interaction.editReply({
void interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Premium")
@ -197,7 +197,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
if ((dbMember?.appliesTo.length ?? 0) > 0)
userPremiumServers = "\nIf you want to remove premium from a server, run this command in your DMs with me.";
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Premium")
@ -216,10 +216,10 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
} catch (e) {
return;
}
i.deferUpdate();
await i.deferUpdate();
const guild = i.guild!;
if (count - appliesTo.length <= 0) {
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Premium")
@ -235,7 +235,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
});
} else {
await client.database.premium.addPremium(interaction.user.id, guild.id);
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Premium")

@ -35,7 +35,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
fetchReply: true
});
if (config.owners.includes(interaction.user.id)) {
interaction.editReply({
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Admin")
@ -96,7 +96,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
} catch {
return;
}
out.deferUpdate();
await out.deferUpdate();
const GuildID = out.fields.getTextInputValue("guildID");
if (!client.guilds.cache.has(GuildID)) {
await interaction.editReply({
@ -126,7 +126,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
} catch {
return;
}
i.deferUpdate();
await i.deferUpdate();
const guild = (await client.guilds.fetch(GuildID)) as Guild | null;
if (!guild) {
await interaction.editReply({

@ -214,7 +214,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
em.setFooter({ text: "Message closed" });
interaction.editReply({ embeds: [em], components: [] });
await interaction.editReply({ embeds: [em], components: [] });
return;
}
}

@ -32,7 +32,7 @@ const filterLevels = {
const callback = async (interaction: CommandInteraction): Promise<void> => {
const guild = interaction.guild!;
const { renderUser, renderDelta } = client.logger;
interaction.reply({
await interaction.reply({
embeds: [
new EmojiEmbed()
.setTitle("Server Info")

@ -1076,12 +1076,12 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
} else {
switch (i.values[0]) {
case "invites": {
i.deferUpdate();
await i.deferUpdate();
config.invite = await inviteMenu(i, m, config.invite);
break;
}
case "mentions": {
i.deferUpdate();
await i.deferUpdate();
config.pings = await mentionMenu(i, m, config.pings);
break;
}

@ -89,7 +89,7 @@ const reorderRoleMenuPages = async (interaction: CommandInteraction, m: Message,
out = null;
}
if (!out) return;
out.deferUpdate();
await out.deferUpdate();
if (out.isButton()) return;
const values = out.values;
@ -218,7 +218,7 @@ const editRoleMenuPage = async (
`**Max:** ${data.max}\n`
);
interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] });
await interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] });
let i: StringSelectMenuInteraction | ButtonInteraction;
try {
i = (await m.awaitMessageComponent({
@ -304,7 +304,7 @@ const createRoleMenuOptionPage = async (
}\n`
);
interaction.editReply({
await interaction.editReply({
embeds: [embed],
components: [new ActionRowBuilder<RoleSelectMenuBuilder>().addComponents(roleSelect), buttons]
});

@ -198,7 +198,7 @@ const addStatsChannel = async (
)
]
});
showModal(i, { name: newChannelName, enabled: newChannelEnabled });
await showModal(i, { name: newChannelName, enabled: newChannelEnabled });
const out: Discord.ModalSubmitInteraction | ButtonInteraction | null =
await modalInteractionCollector(m, interaction.user);
@ -336,7 +336,7 @@ const callback = async (interaction: CommandInteraction) => {
}
}
interaction.editReply({
await interaction.editReply({
embeds: [embed],
components: [
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect),
@ -367,7 +367,7 @@ const callback = async (interaction: CommandInteraction) => {
modified = true;
switch (i.values[0]!) {
case "edit": {
showModal(i, current!);
await showModal(i, current!);
await interaction.editReply({
embeds: [
new EmojiEmbed()
@ -439,7 +439,7 @@ const callback = async (interaction: CommandInteraction) => {
}
case "save": {
await client.database.guilds.write(interaction.guild.id, { stats: currentObject });
singleNotify("statsChannelDeleted", interaction.guild.id, true);
await singleNotify("statsChannelDeleted", interaction.guild.id, true);
modified = false;
await client.memory.forceUpdate(interaction.guild.id);
break;

@ -142,7 +142,7 @@ const reorderTracks = async (
out = null;
}
if (!out) return;
out.deferUpdate();
await out.deferUpdate();
if (out.isButton()) return;
const values = out.values;
@ -268,7 +268,7 @@ const editTrack = async (
];
if (current.track.length >= 1) comps.splice(1, 0, selectMenu);
interaction.editReply({ embeds: [embed], components: comps });
await interaction.editReply({ embeds: [embed], components: comps });
let out: ButtonInteraction | RoleSelectMenuInteraction | StringSelectMenuInteraction | null;
@ -286,7 +286,7 @@ const editTrack = async (
if (out.isButton()) {
switch (out.customId) {
case "back": {
out.deferUpdate();
await out.deferUpdate();
closed = true;
break;
}
@ -295,23 +295,23 @@ const editTrack = async (
break;
}
case "reorder": {
out.deferUpdate();
await out.deferUpdate();
current.track = (await reorderTracks(interaction, out, message, roles, current.track))!;
break;
}
case "retainPrevious": {
out.deferUpdate();
await out.deferUpdate();
current.retainPrevious = !current.retainPrevious;
break;
}
case "nullable": {
out.deferUpdate();
await out.deferUpdate();
current.nullable = !current.nullable;
break;
}
}
} else if (out.isStringSelectMenu()) {
out.deferUpdate();
await out.deferUpdate();
switch (out.customId) {
case "removeRole": {
const index = current.track.findIndex(
@ -322,7 +322,7 @@ const editTrack = async (
}
}
} else {
out.deferUpdate();
await out.deferUpdate();
switch (out.customId) {
case "addRole": {
const role = out.values![0]!;
@ -476,7 +476,7 @@ const callback = async (interaction: CommandInteraction) => {
break;
}
case "save": {
client.database.guilds.write(interaction.guild!.id, { tracks: tracks });
await client.database.guilds.write(interaction.guild!.id, { tracks: tracks });
modified = false;
await client.memory.forceUpdate(interaction.guild!.id);
break;

@ -82,7 +82,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (i.isButton()) {
switch (i.customId) {
case "save": {
client.database.guilds.write(interaction.guild.id, { verify: data });
await client.database.guilds.write(interaction.guild.id, { verify: data });
config = await client.database.guilds.read(interaction.guild.id);
data = Object.assign({}, config.verify);
await client.memory.forceUpdate(interaction.guild.id);

@ -129,7 +129,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
continue;
}
i.deferUpdate();
await i.deferUpdate();
if (i.isButton()) {
switch (i.customId) {
case "roleSave": {

@ -178,7 +178,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
timedOut = true;
continue;
}
component.deferUpdate();
await component.deferUpdate();
if (component.customId === "conflict") {
const rolesToRemove = selected.filter(
(role) => role !== (component as StringSelectMenuInteraction).values[0]

@ -5,7 +5,7 @@ import verify from "../reflex/verify.js";
const command = new SlashCommandBuilder().setName("verify").setDescription("Get verified in the server");
const callback = async (interaction: CommandInteraction): Promise<void> => {
verify(interaction);
await verify(interaction);
};
export { command };

@ -19,14 +19,14 @@ const command = new ContextMenuCommandBuilder().setName("Purge up to here");
async function waitForButton(m: Discord.Message, member: Discord.GuildMember): Promise<boolean> {
let component;
try {
component = m.awaitMessageComponent({
component = await m.awaitMessageComponent({
time: 200000,
filter: (i) => i.user.id === member.id && i.channel!.id === m.channel.id && i.message.id === m.id
});
} catch (e) {
return false;
}
(await component).deferUpdate();
await component.deferUpdate();
return true;
}
@ -210,7 +210,7 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => {
guild: interaction.guild!.id
}
};
log(data);
await log(data);
const messages: Message[] = deleted
.map((m) => m)
.filter((m) => m instanceof Message)

@ -81,5 +81,5 @@ export async function callback(client: NucleusClient, channel: GuildBasedChannel
guild: channel.guild.id
}
};
log(data);
await log(data);
}

@ -123,5 +123,5 @@ export async function callback(client: NucleusClient, channel: GuildBasedChannel
guild: channel.guild.id
}
};
log(data);
await log(data);
}

@ -301,5 +301,5 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
guild: newChannel.guild.id
}
};
log(data);
await log(data);
}

@ -30,5 +30,5 @@ export async function callback(client: NucleusClient, emoji: GuildEmoji) {
guild: emoji.guild.id
}
};
log(data);
await log(data);
}

@ -31,5 +31,5 @@ export async function callback(client: NucleusClient, emoji: GuildEmoji) {
guild: emoji.guild.id
}
};
log(data);
await log(data);
}

@ -37,5 +37,5 @@ export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newE
guild: newEmoji.guild.id
}
};
log(data);
await log(data);
}

@ -9,7 +9,7 @@ export const event = "guildBanAdd";
export async function callback(client: NucleusClient, ban: GuildBan) {
const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
await statsChannelRemove(ban.user, ban.guild);
purgeByUser(ban.user.id, ban.guild.id);
await purgeByUser(ban.user.id, ban.guild.id);
if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return;
const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanAdd)).filter(
(entry: GuildAuditLogsEntry) => (entry.target! as User).id === ban.user.id
@ -39,5 +39,5 @@ export async function callback(client: NucleusClient, ban: GuildBan) {
guild: ban.guild.id
}
};
log(data);
await log(data);
}

@ -33,5 +33,5 @@ export async function callback(client: NucleusClient, ban: GuildBan) {
guild: ban.guild.id
}
};
log(data);
await log(data);
}

@ -5,5 +5,5 @@ import guide from "../reflex/guide.js";
export const event = "guildCreate";
export async function callback(_client: NucleusClient, guild: Guild) {
guide(guild);
await guide(guild);
}

@ -84,7 +84,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
});
}
data = Object.assign(data, { list: list });
log(data);
await log(data);
}
}
const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberUpdate)).filter(
@ -93,7 +93,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
if (before.nickname !== after.nickname) {
doMemberChecks(after, after.guild);
await doMemberChecks(after, after.guild);
await client.database.history.create(
"nickname",
after.guild.id,
@ -123,7 +123,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
guild: after.guild.id
}
};
log(data);
await log(data);
}
if (
(before.communicationDisabledUntilTimestamp ?? 0) < Date.now() &&
@ -163,8 +163,8 @@ export async function callback(client: NucleusClient, before: GuildMember, after
guild: after.guild.id
}
};
log(data);
client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil?.toISOString()!, {
await log(data);
await client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil?.toISOString()!, {
guild: after.guild.id,
user: after.id,
expires: after.communicationDisabledUntilTimestamp
@ -204,8 +204,8 @@ export async function callback(client: NucleusClient, before: GuildMember, after
guild: after.guild.id
}
};
log(data);
client.database.eventScheduler.cancel("naturalUnmute", {
await log(data);
await client.database.eventScheduler.cancel("naturalUnmute", {
guild: after.guild.id,
user: after.id,
expires: before.communicationDisabledUntilTimestamp

@ -93,5 +93,5 @@ export async function callback(client: NucleusClient, before: Guild, after: Guil
guild: after.id
}
};
log(data);
await log(data);
}

@ -33,5 +33,5 @@ export async function callback(client: NucleusClient, invite: Invite) {
guild: invite.guild!.id
}
};
log(data);
await log(data);
}

@ -33,5 +33,5 @@ export async function callback(client: NucleusClient, invite: Invite) {
guild: invite.guild!.id
}
};
log(data);
await log(data);
}

@ -7,9 +7,9 @@ import { doMemberChecks } from "../reflex/scanners.js";
export const event = "guildMemberAdd";
export async function callback(client: NucleusClient, member: GuildMember) {
welcome(member);
statsChannelAdd(member.user, member.guild);
doMemberChecks(member, member.guild);
await welcome(member);
await statsChannelAdd(member.user, member.guild);
await doMemberChecks(member, member.guild);
const { log, isLogging, NucleusColors, entry, renderUser, renderDelta } = client.logger;
if (!(await isLogging(member.guild.id, "guildMemberUpdate"))) return;
await client.database.history.create("join", member.guild.id, member.user, null, null);
@ -33,5 +33,5 @@ export async function callback(client: NucleusClient, member: GuildMember) {
guild: member.guild.id
}
};
log(data);
await log(data);
}

@ -8,7 +8,7 @@ export const event = "guildMemberRemove";
export async function callback(client: NucleusClient, member: GuildMember) {
const startTime = Date.now() - 10 * 1000;
purgeByUser(member.id, member.guild.id);
await purgeByUser(member.id, member.guild.id);
await statsChannelRemove(member.user, member.guild);
const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
if (!(await isLogging(member.guild.id, "guildMemberUpdate"))) return;
@ -95,5 +95,5 @@ export async function callback(client: NucleusClient, member: GuildMember) {
}
};
}
log(data);
await log(data);
}

@ -23,7 +23,11 @@ export async function callback(_client: NucleusClient, message: Message) {
if (message.channel.permissionsFor(message.guild.members.me!)!.has("ManageMessages")) {
await message.crosspost();
} else {
singleNotify(`Nucleus does not have Manage Messages in <#${message.channel.id}>`, message.guild.id, true);
await singleNotify(
`Nucleus does not have Manage Messages in <#${message.channel.id}>`,
message.guild.id,
true
);
}
}
@ -71,7 +75,7 @@ export async function callback(_client: NucleusClient, message: Message) {
if (!config.filters.invite.allowed.channels.includes(message.channel.id)) {
if (/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(content)) {
messageException(message.guild.id, message.channel.id, message.id);
message.delete();
await message.delete();
const data = {
meta: {
type: "messageDelete",

@ -68,5 +68,5 @@ export async function callback(client: NucleusClient, message: Message) {
guild: message.guild!.id
}
};
log(data);
await log(data);
}

@ -103,5 +103,5 @@ export async function callback(client: NucleusClient, oldMessage: Message, newMe
guild: newMessage.guild.id
}
};
log(data);
await log(data);
}

@ -30,5 +30,5 @@ export async function callback(client: NucleusClient, role: Role) {
guild: role.guild.id
}
};
log(data);
await log(data);
}

@ -42,5 +42,5 @@ export async function callback(client: NucleusClient, role: Role) {
guild: role.guild.id
}
};
log(data);
await log(data);
}

@ -74,5 +74,5 @@ export async function callback(client: NucleusClient, oldRole: Role, newRole: Ro
guild: newRole.guild.id
}
}; // TODO: make our own page for this
log(data);
await log(data);
}

@ -32,5 +32,5 @@ export async function callback(client: NucleusClient, sticker: Sticker) {
guild: sticker.guild!.id
}
};
log(data);
await log(data);
}

@ -30,5 +30,5 @@ export async function callback(client: NucleusClient, sticker: Sticker) {
guild: sticker.guild!.id
}
};
log(data);
await log(data);
}

@ -35,5 +35,5 @@ export async function callback(client: NucleusClient, oldSticker: Sticker, newSt
guild: newSticker.guild!.id
}
};
log(data);
await log(data);
}

@ -44,5 +44,5 @@ export async function callback(client: NucleusClient, thread: ThreadChannel) {
guild: thread.guild.id
}
};
log(data);
await log(data);
}

@ -46,5 +46,5 @@ export async function callback(client: NucleusClient, thread: ThreadChannel) {
guild: thread.guild.id
}
};
log(data);
await log(data);
}

@ -55,5 +55,5 @@ export async function callback(client: NucleusClient, oldThread: ThreadChannel,
guild: newThread.guild.id
}
};
log(data);
await log(data);
}

@ -130,7 +130,7 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
guild: channel.guild.id
}
};
log(data);
await log(data);
} catch (e) {
console.log(e);
}

@ -8,7 +8,7 @@ import { record as recordPerformance } from "./utils/performanceTesting/record.j
client.on("ready", async () => {
console.log(`Logged in as ${client.user!.tag}!`);
register();
await register();
runServer(client);
if (config.enableDevelopment) {
client.fetchedCommands = await client.guilds.cache.get(config.developmentGuildID)?.commands.fetch()!;

@ -36,7 +36,7 @@ export default async function logAttachment(message: Message): Promise<Attachmen
if (await client.database.premium.hasPremium(message.guild.id)) {
const channel = (await client.database.guilds.read(message.guild.id)).logging.attachments.channel;
if (!channel) {
singleNotify(
await singleNotify(
"noAttachmentLogChannel",
message.guild.id,
`No channel set for attachment logging. You can set one with ${getCommandMentionByName(
@ -48,7 +48,7 @@ export default async function logAttachment(message: Message): Promise<Attachmen
}
const channelObj = await message.guild.channels.fetch(channel);
if (!channelObj) {
singleNotify(
await singleNotify(
"attachmentLogChannelDeleted",
message.guild.id,
`Your attachment history channel was deleted or is not longer accessible. You can set a new one with ${getCommandMentionByName(
@ -75,7 +75,7 @@ export default async function logAttachment(message: Message): Promise<Attachmen
],
files: attachments.map((file) => file.local)
});
client.database.guilds.write(message.guild.id, {
await client.database.guilds.write(message.guild.id, {
[`logging.attachments.saved.${message.channel.id}${message.id}`]: m.url
});
return { files: attachments, jump: m.url };

@ -134,7 +134,7 @@ export default async function (interaction: CommandInteraction | MessageComponen
guild: interaction.guild!.id
}
};
log(data);
await log(data);
await interaction.channel.delete();
return;
}

@ -353,12 +353,12 @@ export default async (guild: Guild, interaction?: CommandInteraction) => {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
em.setFooter({ text: "Message closed" });
interaction.editReply({
await interaction.editReply({
embeds: [em],
components: []
});
} else {
m.delete();
await m.delete();
}
}
};

@ -55,7 +55,7 @@ export async function testMalware(link: string): Promise<MalwareSchema> {
} catch (e) {
return { safe: true };
}
client.database.scanCache.write(hash, "malware", malware);
await client.database.scanCache.write(hash, "malware", malware);
return { safe: !malware };
}
@ -75,7 +75,7 @@ export async function testLink(link: string): Promise<{ safe: boolean; tags: str
console.error(err);
return { safe: true, tags: [] };
});
client.database.scanCache.write(link, "bad_link", scanned.safe ?? true, scanned.tags ?? []);
await client.database.scanCache.write(link, "bad_link", scanned.safe ?? true, scanned.tags ?? []);
return {
safe: scanned.safe ?? true,
tags: scanned.tags ?? []
@ -90,7 +90,7 @@ export async function streamAttachment(link: string): Promise<[ArrayBuffer, stri
export async function saveAttachment(link: string): Promise<[string, string]> {
const image = await (await fetch(link)).arrayBuffer();
const fileName = generateFileName(link.split("/").pop()!.split(".").pop()!);
const fileName = await generateFileName(link.split("/").pop()!.split(".").pop()!);
const enc = new TextDecoder("utf-8");
writeFileSync(fileName, new DataView(image), "base64");
return [fileName, createHash("sha512").update(enc.decode(image), "base64").digest("base64")];

@ -12,7 +12,7 @@ interface PropSchema {
export async function callback(user: User, guild: Guild) {
guild = await client.guilds.fetch(guild.id);
const config = await client.database.guilds.read(guild.id);
Object.entries(config.stats).forEach(async ([channel, props]) => {
Object.entries(config.stats).forEach(([channel, props]) => void (async () => {
if ((props as PropSchema).enabled) {
let string = (props as PropSchema).name;
if (!string) return;
@ -41,5 +41,5 @@ export async function callback(user: User, guild: Guild) {
console.error(e);
}
}
});
})());
}

@ -208,7 +208,7 @@ export default async function (interaction: CommandInteraction | ButtonInteracti
.setEmoji("CONTROL.BLOCKCROSS")
]
});
singleNotify(
await singleNotify(
"verifyRoleDeleted",
interaction.guild!.id,
`The role given when a member is verified has been deleted. Use ${getCommandMentionByName(

@ -45,7 +45,7 @@ export async function callback(member: GuildMember) {
content: (config.welcome.ping ? `<@&${config.welcome.ping}>` : "") + `<@${member.id}>`
});
} catch (err) {
singleNotify(
await singleNotify(
"welcomeChannelDeleted",
member.guild.id,
`The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName(

@ -181,11 +181,11 @@ async function registerCommandHandler() {
client.on("interactionCreate", async (interaction: Interaction) => {
if (interaction.isUserContextMenuCommand()) {
const commandName = "contextCommands/user/" + interaction.commandName;
execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction);
await execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction);
return;
} else if (interaction.isMessageContextMenuCommand()) {
const commandName = "contextCommands/message/" + interaction.commandName;
execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction);
await execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction);
return;
} else if (interaction.isAutocomplete()) {
const commandName = interaction.commandName;
@ -203,7 +203,7 @@ async function registerCommandHandler() {
const formatted = (choices ?? []).map((choice) => {
return { name: choice, value: choice };
});
interaction.respond(formatted);
await interaction.respond(formatted);
} else if (interaction.isChatInputCommand()) {
const commandName = interaction.commandName;
const subcommandGroupName = interaction.options.getSubcommandGroup(false);
@ -219,7 +219,7 @@ async function registerCommandHandler() {
const command = client.commands[fullCommandName]![0];
const callback = command?.callback;
const check = command?.check;
execute(check, callback, interaction);
await execute(check, callback, interaction);
}
});
}

@ -228,7 +228,7 @@ class confirmationMessage {
break;
}
if (component.customId === "yes") {
component.deferUpdate();
await component.deferUpdate();
for (const v of Object.values(this.customButtons)) {
if (!v.active) continue;
try {
@ -241,7 +241,7 @@ class confirmationMessage {
returnComponents = true;
continue;
} else if (component.customId === "no") {
component.deferUpdate();
await component.deferUpdate();
success = false;
returnComponents = true;
continue;
@ -348,7 +348,7 @@ class confirmationMessage {
returnComponents = true;
continue;
} else {
component.deferUpdate();
await component.deferUpdate();
this.customButtons[component.customId]!.active = !this.customButtons[component.customId]!.active;
returnComponents = true;
continue;

@ -268,7 +268,7 @@ export class Transcript {
const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
if (doc.acknowledged) {
client.database.eventScheduler.schedule(
await client.database.eventScheduler.schedule(
"deleteTranscript",
(Date.now() + 1000 * 60 * 60 * 24 * 7).toString(),
{ guild: transcript.guild, code: code, iv: iv, key: key }

@ -32,11 +32,7 @@ export default async function (
time: 300000
})
.on("collect", (m) => {
try {
m.delete();
} catch (e) {
client.emit("error", e as Error);
}
void m.delete().catch();
resolve(m);
});
mes.on("end", () => {

@ -79,13 +79,13 @@ class EventScheduler {
guild: guild.id
}
};
log(data);
await log(data);
});
}
async start() {
await new Promise((resolve) => this.agenda.once("ready", resolve));
this.agenda.start();
await this.agenda.start();
return this;
}
@ -95,8 +95,8 @@ class EventScheduler {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cancel(name: string, data: any) {
this.agenda.cancel({ name, data });
async cancel(name: string, data: any) {
await this.agenda.cancel({ name, data });
}
}

@ -127,7 +127,7 @@ export const Logger = {
)
.setTimestamp(log.meta.timestamp)
.setColor(log.meta.color);
channel.send({ embeds: [embed] });
await channel.send({ embeds: [embed] });
}
}
},

@ -14,7 +14,7 @@ const databaseReadTime = async () => {
const user = guild.ownerId;
const currentYear = new Date().getFullYear();
const start = Date.now();
client.database.history.read(guild.id, user, currentYear - 1);
await client.database.history.read(guild.id, user, currentYear - 1);
const end = Date.now();
return end - start;
};
@ -35,7 +35,7 @@ const record = async () => {
resources: await resources()
};
if (results.discord > 1000 || results.databaseRead > 500 || results.resources.cpu > 100) {
singleNotify(
await singleNotify(
"performanceTest",
config.developmentGuildID,
`Discord ping time: \`${results.discord}ms\`\nDatabase read time: \`${
@ -47,12 +47,12 @@ const record = async () => {
config.owners
);
} else {
singleNotify("performanceTest", config.developmentGuildID, true);
await singleNotify("performanceTest", config.developmentGuildID, true);
}
client.database.performanceTest.record(results);
setTimeout(async () => {
await record();
await client.database.performanceTest.record(results);
setTimeout(() => {
void record();
}, 60 * 1000);
};

@ -6,13 +6,13 @@ import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function generateFileName(ending: string): string {
export default async function generateFileName(ending: string): Promise<string> {
let fileName = crypto.randomBytes(35).toString("hex");
fileName = fileName.replace(/([a-zA-Z0-9]{8})/g, "$1-");
if (fs.existsSync(`./${fileName}`)) {
fileName = generateFileName(ending);
}
client.database.eventScheduler.schedule("deleteFile", (Date.now() + 60 * 1000).toString(), {
await client.database.eventScheduler.schedule("deleteFile", (Date.now() + 60 * 1000).toString(), {
fileName: `${fileName}.${ending}`
});
return path.join(__dirname, fileName + "." + ending);

Loading…
Cancel
Save