Performance testing
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index a4c57c4..d96ca90 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -16,7 +16,7 @@
async function registerCommands() {
const commands = [];
- const files = fs.readdirSync(config.commandsFolder, { withFileTypes: true }).filter(
+ const files: fs.Dirent[] = fs.readdirSync(config.commandsFolder, { withFileTypes: true }).filter(
file => !file.name.endsWith(".ts") && !file.name.endsWith(".map")
);
console.log(`Registering ${files.length} commands`)
@@ -25,10 +25,15 @@
const last = i === files.length - 1 ? "└" : "├";
if (file.isDirectory()) {
console.log(`${last}─ ${colours.yellow}Loading subcommands of ${file.name}${colours.none}`)
- commands.push((await import(`../../../${config.commandsFolder}/${file.name}/_meta.js`)).command);
+ const fetched = (await import(`../../../${config.commandsFolder}/${file.name}/_meta.js`)).command;
+ commands.push(fetched);
} else if (file.name.endsWith(".js")) {
console.log(`${last}─ ${colours.yellow}Loading command ${file.name}${colours.none}`)
const fetched = (await import(`../../../${config.commandsFolder}/${file.name}`));
+ fetched.command.setDMPermission(fetched.allowedInDMs ?? false)
+ fetched.command.setNameLocalizations(fetched.nameLocalizations ?? {})
+ fetched.command.setDescriptionLocalizations(fetched.descriptionLocalizations ?? {})
+ if (fetched.nameLocalizations || fetched.descriptionLocalizations) console.log("AAAAA")
commands.push(fetched.command);
client.commands["commands/" + fetched.command.name] = fetched;
}
@@ -97,6 +102,8 @@
console.log(`${last}─ ${colours.yellow}Loading message context menu ${file.name}${colours.none}`)
const context = (await import(`../../../${config.messageContextFolder}/${file.name}`));
context.command.setType(ApplicationCommandType.Message);
+ context.command.setDMPermission(context.allowedInDMs ?? false)
+ context.command.setNameLocalizations(context.nameLocalizations ?? {})
commands.push(context.command);
client.commands["contextCommands/message/" + context.command.name] = context;
@@ -182,6 +189,7 @@
callback(data);
}
+
export default async function register() {
let commandList: ( Discord.SlashCommandBuilder | Discord.ContextMenuCommandBuilder )[] = [];
commandList = commandList.concat(await registerCommands());
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index 76ecabe..b2927d6 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -13,7 +13,13 @@
}
-export async function group(name: string, description: string, path: string) {
+export async function group(
+ name: string,
+ description: string,
+ path: string,
+ nameLocalizations?: Record<string, string>,
+ descriptionLocalizations?: Record<string, string>
+) {
// If the name of the command does not match the path (e.g. attachment.ts has /attachments), use commandString
console.log(`│ ├─ Loading group ${name}`)
const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path, "│ ")
@@ -22,6 +28,8 @@
subcommandGroup
.setName(name)
.setDescription(description)
+ if (nameLocalizations) { subcommandGroup.setNameLocalizations(nameLocalizations) }
+ if (descriptionLocalizations) { subcommandGroup.setDescriptionLocalizations(descriptionLocalizations) }
for (const subcommand of fetched.subcommands) {
subcommandGroup.addSubcommand(subcommand.command);
@@ -31,7 +39,16 @@
};
}
-export async function command(name: string, description: string, path: string, commandString: string | undefined = undefined) {
+export async function command(
+ name: string,
+ description: string,
+ path: string,
+ commandString: string | undefined = undefined,
+ nameLocalizations?: Record<string, string>,
+ descriptionLocalizations?: Record<string, string>,
+ userPermissions?: Discord.PermissionsString[],
+ allowedInDMs?: boolean
+) {
// If the name of the command does not match the path (e.g. attachment.ts has /attachments), use commandString
commandString = "commands/" + (commandString ?? path);
const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path);
@@ -39,6 +56,14 @@
return (command: SlashCommandBuilder) => {
command.setName(name)
command.setDescription(description)
+ command.setNameLocalizations(nameLocalizations ?? {})
+ command.setDescriptionLocalizations(descriptionLocalizations ?? {})
+ command.setDMPermission(allowedInDMs ?? false)
+ if (userPermissions) {
+ const bitfield = new Discord.PermissionsBitField()
+ bitfield.add(userPermissions)
+ command.setDefaultMemberPermissions(bitfield.bitfield)
+ }
for (const subcommand of fetched.subcommands) {
let fetchedCommand;