More commands fixed and purge to here
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 53267f2..a57c639 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -1,11 +1,10 @@
-import Discord, { Client, Interaction } from 'discord.js';
+import Discord, { Client, Interaction, AutocompleteInteraction } from 'discord.js';
import { Logger } from "../utils/log.js";
import Memory from "../utils/memory.js";
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" };
@@ -28,9 +27,9 @@
((builder: Discord.SlashCommandBuilder) => Discord.SlashCommandBuilder) |
Discord.SlashCommandSubcommandBuilder | ((builder: Discord.SlashCommandSubcommandBuilder) => Discord.SlashCommandSubcommandBuilder) | Discord.SlashCommandSubcommandGroupBuilder | ((builder: Discord.SlashCommandSubcommandGroupBuilder) => Discord.SlashCommandSubcommandGroupBuilder),
callback: (interaction: Interaction) => Promise<void>,
- check: (interaction: Interaction) => Promise<boolean> | boolean
+ check: (interaction: Interaction) => Promise<boolean> | boolean,
+ autocomplete: (interaction: AutocompleteInteraction) => Promise<string[]>
}> = {};
- // commands: Discord.Collection<string, [Function, Function]> = new Discord.Collection();
constructor(database: typeof NucleusClient.prototype.database) {
super({ intents: 32767 });
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 0193f6c..a4c57c4 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -1,5 +1,4 @@
import Discord, { Interaction, SlashCommandBuilder, ApplicationCommandType } from 'discord.js';
-// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import client from "../client.js";
import fs from "fs";
@@ -140,19 +139,31 @@
const commandName = "contextCommands/message/" + interaction.commandName;
execute(client.commands[commandName]?.check, client.commands[commandName]?.callback, interaction)
return;
+ } else if (interaction.isAutocomplete()) {
+ const commandName = interaction.commandName;
+ const subcommandGroupName = interaction.options.getSubcommandGroup(false);
+ const subcommandName = interaction.options.getSubcommand(false);
+
+ const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
+
+ const choices = await client.commands[fullCommandName]?.autocomplete(interaction);
+
+ const formatted = (choices ?? []).map(choice => {
+ return { name: choice, value: choice }
+ })
+ interaction.respond(formatted)
+ } else if (interaction.isChatInputCommand()) {
+ const commandName = interaction.commandName;
+ const subcommandGroupName = interaction.options.getSubcommandGroup(false);
+ const subcommandName = interaction.options.getSubcommand(false);
+
+ const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
+
+ const command = client.commands[fullCommandName];
+ const callback = command?.callback;
+ const check = command?.check;
+ execute(check, callback, interaction);
}
- if (!interaction.isChatInputCommand()) return;
-
- const commandName = interaction.commandName;
- const subcommandGroupName = interaction.options.getSubcommandGroup(false);
- const subcommandName = interaction.options.getSubcommand(false);
-
- const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
-
- const command = client.commands[fullCommandName];
- const callback = command?.callback;
- const check = command?.check;
- execute(check, callback, interaction);
});
}
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index 45cb8f1..76ecabe 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -1,6 +1,5 @@
import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
import type { SlashCommandBuilder } from "discord.js";
-// @ts-expect-error
import config from "../../config/main.json" assert { type: "json" };
import getSubcommandsInFolder from "./getFilesInFolder.js";
import client from "../client.js";
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 87724f3..6682be0 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -18,6 +18,7 @@
title: string;
disabled: boolean;
value: string | null;
+ notValue: string | null;
emoji: string | undefined;
active: boolean;
onClick: () => Promise<T>;
@@ -68,6 +69,7 @@
disabled: boolean,
callback: (() => Promise<unknown>) | null = async () => null,
callbackClicked: string | null,
+ callbackNotClicked: string | null,
emoji?: string,
initial?: boolean
) {
@@ -75,6 +77,7 @@
title: title,
disabled: disabled,
value: callbackClicked,
+ notValue: callbackNotClicked,
emoji: emoji,
active: initial ?? false,
onClick: callback ?? (async () => null),
@@ -145,10 +148,12 @@
"\n\n" +
Object.values(this.customButtons)
.map((v) => {
- if (v.value === null) return "";
- return v.active ? `*${v.value}*\n` : "";
- })
- .join("")
+ if (v.active) {
+ return v.value ? `*${v.value}*\n` : "";
+ } else {
+ return v.notValue ? `*${v.notValue}*\n` : "";
+ }
+ }).join("")
)
.setStatus(this.color)
],
@@ -163,7 +168,8 @@
} else {
m = (await this.interaction.reply(object)) as unknown as Message;
}
- } catch {
+ } catch (e) {
+ console.log(e);
cancelled = true;
continue;
}
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 2624fc9..b14c5c4 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,6 +1,5 @@
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);
@@ -17,7 +16,6 @@
}
async setup(): Promise<Guilds> {
- // @ts-expect-error
this.defaultData = (await import("../config/default.json", { assert: { type: "json" } }))
.default as unknown as GuildConfig;
return this;
diff --git a/src/utils/defaultEmbeds.ts b/src/utils/defaultEmbeds.ts
index 39a6080..a027c76 100644
--- a/src/utils/defaultEmbeds.ts
+++ b/src/utils/defaultEmbeds.ts
@@ -8,4 +8,30 @@
export const LinkWarningFooter = {
text: "The button below will take you to a website set by the server moderators. Do not enter any passwords unless it is from a trusted website.",
iconURL: "https://cdn.discordapp.com/emojis/952295894370369587.webp?size=128&quality=lossless"
-}
\ No newline at end of file
+}
+
+class Embed {
+ embed: EmojiEmbed = new EmojiEmbed();
+ title: string = "";
+ description = "";
+ pageId = 0;
+
+ setEmbed(embed: EmojiEmbed) {
+ this.embed = embed;
+ return this;
+ }
+ setTitle(title: string) {
+ this.title = title;
+ return this;
+ }
+ setDescription(description: string) {
+ this.description = description;
+ return this;
+ }
+ setPageId(pageId: number) {
+ this.pageId = pageId;
+ return this;
+ }
+}
+
+export { Embed };
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index 0a32a1e..3c9d6ca 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -2,7 +2,6 @@
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 {
diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts
index 7824982..3fa2b53 100644
--- a/src/utils/getEmojiByName.ts
+++ b/src/utils/getEmojiByName.ts
@@ -1,4 +1,3 @@
-// @ts-expect-error
import emojis from "../config/emojis.json" assert { type: "json" };
interface EmojisIndex {
diff --git a/src/utils/memory.ts b/src/utils/memory.ts
index a397d09..870ffaf 100644
--- a/src/utils/memory.ts
+++ b/src/utils/memory.ts
@@ -6,6 +6,7 @@
filters: GuildConfig["filters"];
logging: GuildConfig["logging"];
tickets: GuildConfig["tickets"];
+ tags: GuildConfig["tags"];
}
class Memory {
@@ -20,7 +21,7 @@
}
}
}, 1000 * 60 * 30);
- }
+ };
async readGuildInfo(guild: string): Promise<GuildData> {
if (!this.memory.has(guild)) {
@@ -29,10 +30,15 @@
lastUpdated: Date.now(),
filters: guildData.filters,
logging: guildData.logging,
- tickets: guildData.tickets
+ tickets: guildData.tickets,
+ tags: guildData.tags
});
}
return this.memory.get(guild)!;
+ };
+
+ async forceUpdate(guild: string) {
+ if (this.memory.has(guild)) this.memory.delete(guild);
}
}
diff --git a/src/utils/search.ts b/src/utils/search.ts
new file mode 100644
index 0000000..310dbf8
--- /dev/null
+++ b/src/utils/search.ts
@@ -0,0 +1,18 @@
+import Fuse from "fuse.js";
+
+function getResults(typed: string, options: string[]): 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
+ .slice(0, 25)
+ .sort()
+ // @ts-expect-error
+ const fuse = new Fuse(options, {
+ useExtendedSearch: true,
+ findAllMatches: true,
+ minMatchCharLength: typed.length > 3 ? 3 : typed.length,
+ }).search(typed);
+ return fuse.slice(0, 25).map((option: {item: string }) => option.item );
+}
+
+export { getResults }
\ No newline at end of file