Caching improvements

This commit is contained in:
yeongaori
2025-08-21 15:27:26 +09:00
parent 5c468d5d5c
commit 045b6c88f0
5 changed files with 170 additions and 98 deletions

View File

@@ -1,10 +1,11 @@
require('dotenv').config();
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const fs = require('fs');
const path = require('path');
const logger = require('./modules/colorfulLogger');
const { loadData } = require('./src/data/dataManager');
const { setupProcessHandlers } = require('./src/handlers/processHandlers');
const { loadCommands } = require('./src/handlers/commandHandler');
const client = new Client({
intents: [
@@ -16,39 +17,13 @@ const client = new Client({
partials: [Partials.Channel],
});
// Load data and setup process handlers
// Load data and commands
loadData();
loadCommands();
// Setup process handlers
setupProcessHandlers(client);
// Load commands
client.commands = new Collection();
client.legacyCommands = new Collection();
const commandFolders = fs.readdirSync(path.join(__dirname, 'src', 'commands'));
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(path.join(__dirname, 'src', 'commands', folder)).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(__dirname, 'src', 'commands', folder, file);
const command = require(filePath);
// Load slash command part
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
}
// Load legacy command part
if (command.legacy) {
client.legacyCommands.set(command.legacy.name, command.legacy);
if (command.legacy.aliases) {
command.legacy.aliases.forEach(alias => {
client.legacyCommands.set(alias, command.legacy);
});
}
}
}
}
// Load event handlers
const eventsPath = path.join(__dirname, 'src', 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
@@ -57,9 +32,9 @@ for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args));
client.on(event.name, (...args) => event.execute(...args, client));
}
}