#169 : Re-enabled command manager, created extrudeTiles command for testing
This commit is contained in:
@ -2,6 +2,7 @@ import * as readline from 'readline'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { Server } from 'socket.io'
|
||||
import { commandLogger } from '../utilities/logger'
|
||||
|
||||
class CommandManager {
|
||||
private commands: Map<string, Function> = new Map()
|
||||
@ -23,7 +24,7 @@ class CommandManager {
|
||||
public async boot(io: Server) {
|
||||
this.io = io
|
||||
await this.loadCommands()
|
||||
console.log('[✅] Command manager loaded')
|
||||
commandLogger.info('Command manager loaded')
|
||||
this.startPrompt()
|
||||
}
|
||||
|
||||
@ -48,7 +49,6 @@ class CommandManager {
|
||||
private handleUnknownCommand(command: string) {
|
||||
switch (command) {
|
||||
case 'exit':
|
||||
console.log('Goodbye!')
|
||||
this.rl.close()
|
||||
break
|
||||
default:
|
||||
@ -58,7 +58,7 @@ class CommandManager {
|
||||
}
|
||||
|
||||
private async loadCommands() {
|
||||
const commandsDir = path.resolve(__dirname, 'commands')
|
||||
const commandsDir = path.resolve(process.cwd(), 'src', 'commands')
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(commandsDir)
|
||||
|
||||
@ -66,7 +66,7 @@ class CommandManager {
|
||||
await this.loadCommand(commandsDir, file)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[❌] Failed to read commands directory:', error)
|
||||
commandLogger.error(`Failed to read commands directory: ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,16 +79,16 @@ class CommandManager {
|
||||
|
||||
this.registerCommand(commandName, module.default)
|
||||
} catch (error) {
|
||||
console.error('[❌] Failed to load command:', file, error)
|
||||
commandLogger.error(`Failed to load command: ${file}: ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
private registerCommand(name: string, command: (args: string[], io: Server) => void) {
|
||||
if (this.commands.has(name)) {
|
||||
console.warn(`Command '${name}' is already registered. Overwriting...`)
|
||||
commandLogger.warn(`Command '${name}' is already registered. Overwriting...`)
|
||||
}
|
||||
this.commands.set(name, command)
|
||||
console.log(`Registered command: ${name}`)
|
||||
commandLogger.info(`Registered command: ${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user