Fix various issues pre-switching-to-bun
diff --git a/.eslintrc.json b/.eslintrc.json
index 873db2b..4b4e25d 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -4,7 +4,7 @@
"es2020": true,
"node": true
},
- "ignorePatterns": ["dist/"],
+ "ignorePatterns": ["dist/", "src/Unfinished/"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/strict", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
@@ -23,8 +23,6 @@
"caughtErrorsIgnorePattern": "^_"
}
],
- "@typescript-eslint/no-explicit-any": "error",
- "@typescript-eslint/no-unnecessary-condition": "off", // TODO: remove this rule
- "no-constant-condition": "off"
+ "@typescript-eslint/no-explicit-any": "error"
}
}
diff --git a/package.json b/package.json
index 6ab482d..b211473 100644
--- a/package.json
+++ b/package.json
@@ -28,11 +28,11 @@
"scripts": {
"build": "tsc",
"start": "node --experimental-json-modules --enable-source-maps dist/index.js",
- "dev": "rm -rf dist && eslint . --fix && tsc && node --experimental-json-modules --enable-source-maps dist/index.js",
- "force-dev": "rm -rf dist && eslint . --fix; tsc-suppress && node --experimental-json-modules --enable-source-maps dist/index.js",
- "lint": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To auto-fix everything possible, please run `yarn lint-fix`'; true",
- "lint-fix": "echo 'Fixing eslint issues...'; eslint . --fix; echo 'Reformatting...'; prettier --write --loglevel warn --cache .; true",
- "lint-list": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To view errors in more detail, please run `yarn lint`'; true",
+ "dev": "rm -rf dist && eslint src --fix && tsc && node --experimental-json-modules --enable-source-maps dist/index.js",
+ "force-dev": "rm -rf dist && eslint src --fix; 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-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",
"setup": "node Installer.js"
},
"repository": {
@@ -56,6 +56,7 @@
"@typescript-eslint/parser": "^5.32.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.7.1",
+ "prettier-eslint": "^15.0.1",
"tsc-suppress": "^1.0.7"
}
}
diff --git a/src/Unfinished/all.ts b/src/Unfinished/all.ts
index 758947b..cf2c9e4 100644
--- a/src/Unfinished/all.ts
+++ b/src/Unfinished/all.ts
@@ -176,11 +176,12 @@
if (all) {
members.forEach((member) => {
let applies = true;
- filters.forEach((filter) => {
+ for (const filter of filters) {
if (!filter.check(member)) {
applies = false;
+ break;
}
- });
+ }
if (applies) {
affected.push(member);
}
@@ -188,11 +189,12 @@
} else {
members.forEach((member) => {
let applies = false;
- filters.forEach((filter) => {
+ for (const filter of filters) {
if (filter.check(member)) {
applies = true;
+ break;
}
- });
+ }
if (applies) {
affected.push(member);
}
diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts
index 8b84770..ca170be 100644
--- a/src/commands/settings/tickets.ts
+++ b/src/commands/settings/tickets.ts
@@ -67,7 +67,7 @@
fetchReply: true
})) as Message;
const options = {
- enabled: interaction.options.getString("enabled") as string | boolean,
+ enabled: interaction.options.getString("enabled") as string | boolean | null,
category: interaction.options.getChannel("category"),
maxtickets: interaction.options.getNumber("maxticketsperuser"),
supportping: interaction.options.getRole("supportrole")
diff --git a/src/commands/tags/list.ts b/src/commands/tags/list.ts
index bf124bd..e9e8b41 100644
--- a/src/commands/tags/list.ts
+++ b/src/commands/tags/list.ts
@@ -82,7 +82,9 @@
})) as Message;
let page = 0;
let selectPaneOpen = false;
- while (true) {
+ let cancelled = false;
+ let timedOut = false;
+ while (!cancelled && !timedOut) {
let selectPane: MessageActionRow[] = [];
if (selectPaneOpen) {
@@ -136,7 +138,8 @@
try {
i = await m.awaitMessageComponent({ time: 300000 });
} catch (e) {
- break;
+ timedOut = true;
+ continue;
}
i.deferUpdate();
if ((i.component as MessageActionRowComponent).customId === "left") {
@@ -151,66 +154,18 @@
page = parseInt((i as SelectMenuInteraction).values[0]!);
selectPaneOpen = false;
} else {
- const em = new Discord.MessageEmbed(pages[page]!.embed);
- em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message closed");
- await interaction.editReply({
- embeds: [em],
- components: [
- new MessageActionRow().addComponents([
- new MessageButton()
- .setCustomId("left")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("select")
- .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
- .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("right")
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("close")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- .setStyle("DANGER")
- .setDisabled(true)
- ])
- ]
- });
- return;
+ cancelled = true;
}
}
const em = new Discord.MessageEmbed(pages[page]!.embed);
- em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out");
+ if (timedOut) {
+ em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out");
+ } else {
+ em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message closed");
+ }
await interaction.editReply({
embeds: [em],
- components: [
- new MessageActionRow().addComponents([
- new MessageButton()
- .setCustomId("left")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("select")
- .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("right")
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("close")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- .setStyle("DANGER")
- .setDisabled(true)
- ])
- ]
+ components: []
});
};
diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts
index a05389f..9f4c47a 100644
--- a/src/events/guildBanAdd.ts
+++ b/src/events/guildBanAdd.ts
@@ -1,4 +1,4 @@
-import type { GuildAuditLogsEntry, GuildBan } from 'discord.js';
+import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
import { purgeByUser } from "../actions/tickets/delete.js";
import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
// @ts-expect-error
diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts
index 86d6efe..5f1499d 100644
--- a/src/events/guildBanRemove.ts
+++ b/src/events/guildBanRemove.ts
@@ -1,4 +1,4 @@
-import type { GuildAuditLogsEntry, GuildBan } from 'discord.js';
+import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
import { purgeByUser } from "../actions/tickets/delete.js";
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
diff --git a/src/events/guildUpdate.ts b/src/events/guildUpdate.ts
index ea9008d..3274727 100644
--- a/src/events/guildUpdate.ts
+++ b/src/events/guildUpdate.ts
@@ -1,6 +1,6 @@
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
-import type { Guild, GuildAuditLogsEntry } from 'discord.js';
+import type { Guild, GuildAuditLogsEntry } from "discord.js";
import { callback as statsChannelUpdate } from "../reflex/statsChannelUpdate.js";
export const event = "guildUpdate";
@@ -31,8 +31,8 @@
NONE: "None",
ELEVATED: "Enabled"
};
- const beforeOwner = await before.fetchOwner()
- const afterOwner = await after.fetchOwner()
+ const beforeOwner = await before.fetchOwner();
+ const afterOwner = await after.fetchOwner();
if (before.name !== after.name) list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
if (before.icon !== after.icon)
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 9ee7bee..a00baf8 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -11,7 +11,7 @@
export const event = "interactionCreate";
-function getAutocomplete(typed: string, options: string[]): {name: string, value: string}[] {
+function getAutocomplete(typed: string, options: string[]): { name: string; value: string }[] {
options = options.filter((option) => option.length <= 100); // thanks discord. 6000 character limit on slash command inputs but only 100 for autocomplete.
if (!typed)
return options
@@ -65,8 +65,11 @@
}
async function interactionCreate(interaction: Interaction) {
- if (interaction.type === "MESSAGE_COMPONENT" && (interaction as MessageComponentInteraction).componentType === "BUTTON") {
- const int = (interaction as MessageComponentInteraction)
+ if (
+ interaction.type === "MESSAGE_COMPONENT" &&
+ (interaction as MessageComponentInteraction).componentType === "BUTTON"
+ ) {
+ const int = interaction as MessageComponentInteraction;
switch (int.customId) {
case "rolemenu": {
return await roleMenu(interaction);
@@ -85,24 +88,16 @@
}
}
} else if (interaction.type === "APPLICATION_COMMAND_AUTOCOMPLETE") {
- const int = (interaction as AutocompleteInteraction)
- switch (
- `${int.commandName} ${int.options.getSubcommandGroup(
- false
- )} ${int.options.getSubcommand(false)}`
- ) {
+ const int = interaction as AutocompleteInteraction;
+ switch (`${int.commandName} ${int.options.getSubcommandGroup(false)} ${int.options.getSubcommand(false)}`) {
case "tag null null": {
- return int.respond(
- getAutocomplete(int.options.getString("tag") ?? "", await tagAutocomplete(int))
- );
+ return int.respond(getAutocomplete(int.options.getString("tag") ?? "", await tagAutocomplete(int)));
}
case "settings null stats": {
return int.respond(generateStatsChannelAutocomplete(int.options.getString("name") ?? ""));
}
case "settings null welcome": {
- return int.respond(
- generateWelcomeMessageAutocomplete(int.options.getString("message") ?? "")
- );
+ return int.respond(generateWelcomeMessageAutocomplete(int.options.getString("message") ?? ""));
}
}
}
diff --git a/src/events/inviteCreate.ts b/src/events/inviteCreate.ts
index fb35b7e..735ec21 100644
--- a/src/events/inviteCreate.ts
+++ b/src/events/inviteCreate.ts
@@ -9,7 +9,9 @@
export async function callback(client: HaikuClient, invite: Invite) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId).first();
+ const audit = auditLog.entries
+ .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
+ .first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
diff --git a/src/events/inviteDelete.ts b/src/events/inviteDelete.ts
index b07893a..375a693 100644
--- a/src/events/inviteDelete.ts
+++ b/src/events/inviteDelete.ts
@@ -9,7 +9,9 @@
export async function callback(client: HaikuClient, invite: Invite) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId).first();
+ const audit = auditLog.entries
+ .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
+ .first();
if (audit.executor.id === client.user.id) return;
const data = {
meta: {
diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index f2301e0..0527a60 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -10,7 +10,9 @@
if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === message.author.id).first();
+ const audit = auditLog.entries
+ .filter((entry: GuildAuditLogsEntry) => entry.target!.id === message.author.id)
+ .first();
if (audit) {
if (audit.createdAt - 100 < new Date().getTime()) return;
}
@@ -54,7 +56,9 @@
repliedTo: entry(
replyTo,
replyTo
- ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
+ ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${
+ message.channel.id
+ }/${replyTo.messageId})`
: "None"
)
},
diff --git a/src/events/stickerCreate.ts b/src/events/stickerCreate.ts
index 01d6c2c..76bb6f1 100644
--- a/src/events/stickerCreate.ts
+++ b/src/events/stickerCreate.ts
@@ -1,5 +1,5 @@
// @ts-expect-error
-import type { HaikuClient } from "jshaiku"
+import type { HaikuClient } from "jshaiku";
import type { GuildAuditLogsEntry, Sticker } from "discord.js";
export const event = "stickerDelete";
diff --git a/src/events/stickerDelete.ts b/src/events/stickerDelete.ts
index c9b3fab..18dcc80 100644
--- a/src/events/stickerDelete.ts
+++ b/src/events/stickerDelete.ts
@@ -1,5 +1,5 @@
// @ts-expect-error
-import type { HaikuClient } from "jshaiku"
+import type { HaikuClient } from "jshaiku";
import type { GuildAuditLogsEntry, Sticker } from "discord.js";
export const event = "stickerDelete";
diff --git a/src/events/stickerUpdate.ts b/src/events/stickerUpdate.ts
index c6e3b6e..e2ed1f9 100644
--- a/src/events/stickerUpdate.ts
+++ b/src/events/stickerUpdate.ts
@@ -1,5 +1,5 @@
// @ts-expect-error
-import type { HaikuClient } from "jshaiku"
+import type { HaikuClient } from "jshaiku";
import type { Sticker } from "discord.js";
export const event = "stickerUpdate";
diff --git a/src/events/threadCreate.ts b/src/events/threadCreate.ts
index e8849c9..5d0be0b 100644
--- a/src/events/threadCreate.ts
+++ b/src/events/threadCreate.ts
@@ -2,7 +2,7 @@
// @ts-expect-error
import humanizeDuration from "humanize-duration";
// @ts-expect-error
-import type { HaikuClient } from "jshaiku"
+import type { HaikuClient } from "jshaiku";
export const event = "threadCreate";
export async function callback(client: HaikuClient, thread: ThreadChannel) {
@@ -10,10 +10,12 @@
const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE");
const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first();
if (audit.executor.id === client.user.id) return;
- const category = thread.parent ? entry(
- thread.parent.parent ? thread.parent.parent.name : "None",
- thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
- ) : entry(null, "Uncategorised")
+ const category = thread.parent
+ ? entry(
+ thread.parent.parent ? thread.parent.parent.name : "None",
+ thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
+ )
+ : entry(null, "Uncategorised");
const data = {
meta: {
type: "channelCreate",
diff --git a/src/events/threadDelete.ts b/src/events/threadDelete.ts
index 1908b7f..fba3007 100644
--- a/src/events/threadDelete.ts
+++ b/src/events/threadDelete.ts
@@ -2,7 +2,7 @@
// @ts-expect-error
import humanizeDuration from "humanize-duration";
// @ts-expect-error
-import type { HaikuClient } from "jshaiku"
+import type { HaikuClient } from "jshaiku";
export const event = "threadDelete";
export async function callback(client: HaikuClient, thread: ThreadChannel) {
@@ -10,10 +10,12 @@
const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first();
if (audit.executor.id === client.user.id) return;
- const category = thread.parent ? entry(
- thread.parent.parent ? thread.parent.parent.name : "None",
- thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
- ) : entry(null, "Uncategorised")
+ const category = thread.parent
+ ? entry(
+ thread.parent.parent ? thread.parent.parent.name : "None",
+ thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
+ )
+ : entry(null, "Uncategorised");
const data = {
meta: {
type: "channelDelete",
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index 4df2587..0077330 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -32,7 +32,9 @@
if (before.rateLimitPerUser !== after.rateLimitPerUser) {
list["slowmode"] = entry(
[before.rateLimitPerUser, after.rateLimitPerUser],
- `${humanizeDuration((before.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration((after.rateLimitPerUser ?? 0) * 1000)}`
+ `${humanizeDuration((before.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration(
+ (after.rateLimitPerUser ?? 0) * 1000
+ )}`
);
}
if (!(Object.keys(list).length - 3)) return;
diff --git a/src/events/webhookUpdate.ts b/src/events/webhookUpdate.ts
index c58a340..6187253 100644
--- a/src/events/webhookUpdate.ts
+++ b/src/events/webhookUpdate.ts
@@ -15,25 +15,34 @@
auditLogUpdate,
auditLogDelete
]);
- const auditCreate = auditLogCreate.entries.filter((entry: GuildAuditLogsEntry | null) => {
- if (entry === null) return false
- return (entry.target! as Webhook).channelId === channel.id}
- ).first();
- const auditUpdate = auditLogUpdate.entries.filter((entry: GuildAuditLogsEntry | null) => {
- if (entry === null) return false
- return (entry.target! as Webhook).channelId === channel.id}
- ).first();
- const auditDelete = auditLogDelete.entries.filter((entry: GuildAuditLogsEntry | null) => {
- if (entry === null) return false
- return (entry.target! as Webhook).channelId === channel.id}
- ).first();
+ const auditCreate = auditLogCreate.entries
+ .filter((entry: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false;
+ return (entry.target! as Webhook).channelId === channel.id;
+ })
+ .first();
+ const auditUpdate = auditLogUpdate.entries
+ .filter((entry: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false;
+ return (entry.target! as Webhook).channelId === channel.id;
+ })
+ .first();
+ const auditDelete = auditLogDelete.entries
+ .filter((entry: GuildAuditLogsEntry | null) => {
+ if (entry === null) return false;
+ return (entry.target! as Webhook).channelId === channel.id;
+ })
+ .first();
if (!auditCreate && !auditUpdate && !auditDelete) return;
let audit = auditCreate;
let action: "Create" | "Update" | "Delete" = "Create";
let list: Record<string, ReturnType<typeof entry> | string> = {};
if (auditUpdate && auditUpdate.createdTimestamp > audit.createdTimestamp) {
const { before, after } = auditUpdate.changes.reduce(
- (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
+ (
+ acc: { before: Record<string, string>; after: Record<string, string> },
+ change: { key: string; new: string; old: string }
+ ) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;
@@ -50,14 +59,20 @@
renderChannel(await client.channels.fetch(after.channel_id))
);
if (!Object.keys(list).length) return;
- list["created"] = entry(auditUpdate.target.createdTimestamp, renderDelta(auditUpdate.target.createdTimestamp));
+ list["created"] = entry(
+ auditUpdate.target.createdTimestamp,
+ renderDelta(auditUpdate.target.createdTimestamp)
+ );
list["edited"] = entry(after.editedTimestamp, renderDelta(new Date().getTime()));
list["editedBy"] = entry(auditUpdate.executor.id, renderUser(auditUpdate.executor));
audit = auditUpdate;
action = "Update";
} else if (auditDelete && auditDelete.createdTimestamp > audit.createdTimestamp) {
const { before } = auditDelete.changes.reduce(
- (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
+ (
+ acc: { before: Record<string, string>; after: Record<string, string> },
+ change: { key: string; new: string; old: string }
+ ) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;
@@ -78,7 +93,10 @@
action = "Delete";
} else {
const { before } = auditDelete.changes.reduce(
- (acc: {before: Record<string, string>, after: Record<string, string>}, change: {key: string, new: string, old: string}) => {
+ (
+ acc: { before: Record<string, string>; after: Record<string, string> },
+ change: { key: string; new: string; old: string }
+ ) => {
acc.before[change.key] = change.old;
acc.after[change.key] = change.new;
return acc;
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index 57720bf..97d0d28 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -1,4 +1,12 @@
-import { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton, MessageComponentInteraction, TextChannel } from "discord.js";
+import {
+ CommandInteraction,
+ GuildMember,
+ Message,
+ MessageActionRow,
+ MessageButton,
+ MessageComponentInteraction,
+ TextChannel
+} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import { PasteClient, Publicity, ExpireDate } from "pastebin-api";
diff --git a/src/reflex/guide.ts b/src/reflex/guide.ts
index ef7b255..4e7703c 100644
--- a/src/reflex/guide.ts
+++ b/src/reflex/guide.ts
@@ -230,7 +230,9 @@
let selectPaneOpen = false;
- while (true) {
+ let cancelled = false;
+ let timedOut = false;
+ while (!cancelled && !timedOut) {
let selectPane: MessageActionRow[] = [];
if (selectPaneOpen) {
@@ -297,7 +299,8 @@
time: 300000
});
} catch (e) {
- break;
+ timedOut = true;
+ continue;
}
i.deferUpdate();
if (!("customId" in i.component)) {
@@ -314,91 +317,40 @@
page = parseInt((i as SelectMenuInteraction).values[0]!);
selectPaneOpen = false;
} else {
- if (interaction) {
- const em = new Discord.MessageEmbed(pages[page]!.embed);
- em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
- em.setFooter({ text: "Message closed" });
- interaction.editReply({
- embeds: [em],
- components: [
- new MessageActionRow().addComponents([
- new MessageButton()
- .setCustomId("left")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("select")
- .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
- .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("right")
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true)
- ])
- ]
- });
- } else {
- m.delete();
- }
- return;
+ cancelled = true;
}
}
- if (interaction) {
- const em = new Discord.MessageEmbed(pages[page]!.embed);
- em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
- text: "Message timed out"
- });
- await interaction.editReply({
- embeds: [em],
- components: [
- new MessageActionRow().addComponents([
- new MessageButton()
- .setCustomId("left")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("select")
- .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("right")
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true)
- ])
- ]
- });
+ if (timedOut) {
+ if (interaction) {
+ const em = new Discord.MessageEmbed(pages[page]!.embed);
+ em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
+ text: "Message timed out"
+ });
+ await interaction.editReply({
+ embeds: [em],
+ components: []
+ });
+ } else {
+ const em = new Discord.MessageEmbed(pages[page]!.embed);
+ em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
+ text: "Message timed out"
+ });
+ await m.edit({
+ embeds: [em],
+ components: []
+ });
+ }
} else {
- const em = new Discord.MessageEmbed(pages[page]!.embed);
- em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
- text: "Message timed out"
- });
- await m.edit({
- embeds: [em],
- components: [
- new MessageActionRow().addComponents([
- new MessageButton()
- .setCustomId("left")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("select")
- .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true),
- new MessageButton()
- .setCustomId("right")
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle("SECONDARY")
- .setDisabled(true)
- ])
- ]
- });
+ if (interaction) {
+ const em = new Discord.MessageEmbed(pages[page]!.embed);
+ em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
+ em.setFooter({ text: "Message closed" });
+ interaction.editReply({
+ embeds: [em],
+ components: []
+ });
+ } else {
+ m.delete();
+ }
}
};
diff --git a/src/reflex/statsChannelUpdate.ts b/src/reflex/statsChannelUpdate.ts
index 657e90d..850e826 100644
--- a/src/reflex/statsChannelUpdate.ts
+++ b/src/reflex/statsChannelUpdate.ts
@@ -1,4 +1,4 @@
-import type { Guild, User } from 'discord.js';
+import type { Guild, User } from "discord.js";
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
import type { GuildMember } from "discord.js";
@@ -14,7 +14,7 @@
if (!member && !guild) return;
guild = await client.guilds.fetch(member ? member.guild.id : guild!.id);
if (!guild) return;
- user = user ?? member!.user
+ user = user ?? member!.user;
const config = await client.database.guilds.read(guild.id);
Object.entries(config.getKey("stats")).forEach(async ([channel, props]) => {
if ((props as PropSchema).enabled) {
diff --git a/src/reflex/verify.ts b/src/reflex/verify.ts
index f28b291..8aba46d 100644
--- a/src/reflex/verify.ts
+++ b/src/reflex/verify.ts
@@ -1,5 +1,12 @@
import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
-import Discord, { CommandInteraction, GuildMember, Interaction, MessageComponentInteraction, Permissions, Role } from "discord.js";
+import Discord, {
+ CommandInteraction,
+ GuildMember,
+ Interaction,
+ MessageComponentInteraction,
+ Permissions,
+ Role
+} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import fetch from "node-fetch";
import { TestString, NSFWCheck } from "./scanners.js";
@@ -175,20 +182,17 @@
let length = 5;
let itt = 0;
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- while (true) {
+ do {
itt += 1;
code = "";
for (let i = 0; i < length; i++) {
code += chars.charAt(Math.floor(Math.random() * chars.length));
}
- if (code in verify) continue;
if (itt > 1000) {
itt = 0;
length += 1;
- continue;
}
- break;
- }
+ } while (code in verify);
const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
if (!role) {
await interaction.editReply({
diff --git a/src/utils/specialTypes.ts b/src/utils/specialTypes.ts
deleted file mode 100644
index 93264d6..0000000
--- a/src/utils/specialTypes.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-export type AsyncReturnType<T extends (...args: any[]) => Promise<any>> = T extends (...args: any[]) => Promise<infer X>
- ? X
- : unknown;