Squashed commit of the following:

commit e8a57468de
Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com>
Date:   Sat May 31 11:10:56 2025 -0400

    Add record command

commit 5a8ca6bb54
Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com>
Date:   Sat May 31 11:10:30 2025 -0400

    Move context menus to their own folder

commit 2d7c14ed7a
Merge: 33a6ba8 5107759
Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com>
Date:   Sat May 31 10:54:27 2025 -0400

    Merge branch 'alt-data' into records

commit 5107759923
Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com>
Date:   Fri May 30 15:26:21 2025 -0400

    Recursive alt lookup data
This commit is contained in:
Tarrgon
2025-05-31 11:11:37 -04:00
parent 33a6ba893b
commit f5268ace77
11 changed files with 306 additions and 50 deletions
+29 -16
View File
@@ -13,27 +13,40 @@ export async function refreshCommands(client: Client) {
try {
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];
const guildCommands: { [id: string]: RESTPostAPIApplicationCommandsJSONBody[] } = {};
const commandFiles = fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
const commandFiles = {
commands: fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
'context-menus': fs.readdirSync(`${ROOT_DIR}/context-menus`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
};
for (const file of commandFiles) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const command: Command = require(`${ROOT_DIR}/commands/${file}`).default;
let data: RESTPostAPIApplicationCommandsJSONBody;
if (typeof (command.data) == 'function') {
data = (await command.data(client)).toJSON();
} else {
data = command.data.toJSON();
}
for (const [folderName, files] of Object.entries(commandFiles)) {
for (const file of files) {
const p = `${ROOT_DIR}/${folderName}/${file}`;
// eslint-disable-next-line @typescript-eslint/no-require-imports
const command: Command = require(p).default;
if (!command.guilds) {
commands.push(data);
} else {
for (const id of command.guilds) {
if (!guildCommands[id]) guildCommands[id] = [];
guildCommands[id].push(data);
if (!command) {
console.warn(`File at ${p} has no export. Skipping registering.`);
continue;
}
let data: RESTPostAPIApplicationCommandsJSONBody;
if (typeof (command.data) == 'function') {
data = (await command.data(client)).toJSON();
} else {
data = command.data.toJSON();
}
if (!command.guilds) {
commands.push(data);
} else {
for (const id of command.guilds) {
if (!guildCommands[id]) guildCommands[id] = [];
guildCommands[id].push(data);
}
}
}
}
console.log('Started refreshing application (/) commands.');
console.log('Global commands: ' + commands.length);