1
0
forked from noxious/server

Path fixes for all environments, npm run format, removed redundant imports

This commit is contained in:
2024-10-01 00:10:30 +02:00
parent 4cbd62cbb0
commit ce1708a55e
24 changed files with 82 additions and 87 deletions

View File

@ -3,7 +3,7 @@ import * as fs from 'fs'
import * as path from 'path'
import { Server } from 'socket.io'
import { commandLogger } from '../utilities/logger'
import config from '../utilities/config'
import { getAppPath } from '../utilities/utilities'
class CommandManager {
private commands: Map<string, any> = new Map()
@ -20,8 +20,6 @@ class CommandManager {
this.rl.on('close', () => {
this.rlClosed = true
})
console.log(process.cwd())
}
public async boot(io: Server) {
@ -63,34 +61,34 @@ class CommandManager {
}
private async loadCommands() {
const commandsDir = path.join(process.cwd(), 'commands');
commandLogger.info(`Loading commands from: ${commandsDir}`);
const directory = getAppPath('commands')
commandLogger.info(`Loading commands from: ${directory}`)
try {
const files = await fs.promises.readdir(commandsDir, { withFileTypes: true });
const files = await fs.promises.readdir(directory, { withFileTypes: true })
for (const file of files) {
if (!file.isFile() || (!file.name.endsWith('.ts') && !file.name.endsWith('.js'))) {
continue;
continue
}
const fullPath = path.join(commandsDir, file.name);
const commandName = path.basename(file.name, path.extname(file.name));
const fullPath = getAppPath('commands', file.name)
const commandName = path.basename(file.name, path.extname(file.name))
try {
const module = await import(fullPath);
const module = await import(fullPath)
if (typeof module.default !== 'function') {
commandLogger.warn(`Unrecognized export in ${file.name}`);
continue;
commandLogger.warn(`Unrecognized export in ${file.name}`)
continue
}
this.registerCommand(commandName, module.default);
this.registerCommand(commandName, module.default)
} catch (error) {
commandLogger.error(`Error loading command ${file.name}: ${error instanceof Error ? error.message : String(error)}`);
commandLogger.error(`Error loading command ${file.name}: ${error instanceof Error ? error.message : String(error)}`)
}
}
} catch (error) {
commandLogger.error(`Failed to read commands directory: ${error instanceof Error ? error.message : String(error)}`);
commandLogger.error(`Failed to read commands directory: ${error instanceof Error ? error.message : String(error)}`)
}
}