Command Manager working
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
# Specification of command manager and modules
|
|
||||||
|
|
||||||
- Ability to
|
|
||||||
@@ -3,11 +3,15 @@ import fs from 'fs';
|
|||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
|
|
||||||
let modules = [];
|
let modules = [];
|
||||||
let commands = {};
|
let commands = [];
|
||||||
|
|
||||||
export class CommandManager {
|
export class CommandManager {
|
||||||
static async load() {
|
static get Modules() {return modules;}
|
||||||
console.log();
|
static get Commands() {return commands;}
|
||||||
|
|
||||||
|
static async load(log) {
|
||||||
|
if (log != 1) console.log();
|
||||||
|
|
||||||
Logger.info('Loading Commands and Modules');
|
Logger.info('Loading Commands and Modules');
|
||||||
if (!fs.existsSync('./src/commands/')) {
|
if (!fs.existsSync('./src/commands/')) {
|
||||||
Logger.panic('No commands folder at /src/commands');
|
Logger.panic('No commands folder at /src/commands');
|
||||||
@@ -32,7 +36,7 @@ export class CommandManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
modules.push({name: mod.Module.Name, module: mod, exports: modExports});
|
modules[mod.Module.Name] = {name: mod.Module.Name, module: mod, exports: modExports, file: file};
|
||||||
Logger.info(`Loaded ${mod.Module.Name} from ${file}`);
|
Logger.info(`Loaded ${mod.Module.Name} from ${file}`);
|
||||||
|
|
||||||
for (let command of modExports) {
|
for (let command of modExports) {
|
||||||
@@ -43,12 +47,16 @@ export class CommandManager {
|
|||||||
|| !current.Alias
|
|| !current.Alias
|
||||||
|| !current.Usage
|
|| !current.Usage
|
||||||
|| !current.Description
|
|| !current.Description
|
||||||
|| !current.Module) {
|
|| !current.Module
|
||||||
|
|| !current.Init
|
||||||
|
|| !current.Exec
|
||||||
|
|| !current.Dispose) {
|
||||||
Logger.warn(`Exported class ${command} in ${file} and module ${mod.Module.Name} is not a valid command`);
|
Logger.warn(`Exported class ${command} in ${file} and module ${mod.Module.Name} is not a valid command`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await current.Init();
|
||||||
|
commands[current.Command] = current; // Doesnt give support for alias commands
|
||||||
|
|
||||||
Logger.info(`Loaded ${current.Command} from module ${mod.Module.Name}`);
|
Logger.info(`Loaded ${current.Command} from module ${mod.Module.Name}`);
|
||||||
commandCount++;
|
commandCount++;
|
||||||
@@ -59,10 +67,23 @@ export class CommandManager {
|
|||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
static get Modules() {return modules;}
|
|
||||||
static get Commands() {return commands;}
|
|
||||||
|
|
||||||
static async reload() {
|
static async reload() {
|
||||||
|
console.log();
|
||||||
|
Logger.info('Reloading Modules and Commands');
|
||||||
|
|
||||||
|
// Does not call dispose function
|
||||||
|
for (let command of commands) {
|
||||||
|
await command.Dispose();
|
||||||
|
}
|
||||||
|
Logger.info('Disposed registerd commands');
|
||||||
|
|
||||||
|
for (let mod of modules) {
|
||||||
|
await mod.module.Dispose();
|
||||||
|
delete require.cache[require.resolve(mod.file)];
|
||||||
|
}
|
||||||
|
Logger.info('Disposed registerd modules');
|
||||||
|
|
||||||
|
CommandManager.load(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import {Logger} from "../logger";
|
||||||
|
|
||||||
export class Module {
|
export class Module {
|
||||||
static get Name() {return 'Generic module 1'}
|
static get Name() {return 'Generic module 1'}
|
||||||
static get Author() {return 'Ben (plane000)#8618'}
|
static get Author() {return 'Ben (plane000)#8618'}
|
||||||
@@ -7,7 +9,7 @@ export class Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Dispose() {
|
static Dispose() {
|
||||||
|
Logger.error('module disposed')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,16 +20,16 @@ export class Command1 {
|
|||||||
static get Description() {return 'Echos the users input'}
|
static get Description() {return 'Echos the users input'}
|
||||||
static get Module() {return Module;}
|
static get Module() {return Module;}
|
||||||
|
|
||||||
static Init() {
|
static async Init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exec(message, client, next) {
|
static async Exec(message, client, next) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dispose() {
|
static async Dispose() {
|
||||||
|
Logger.error('command disposed')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {Config} from './config';
|
|||||||
import {Database} from './database/database';
|
import {Database} from './database/database';
|
||||||
import {Events} from './events';
|
import {Events} from './events';
|
||||||
import {MessageManager} from './messagemanager';
|
import {MessageManager} from './messagemanager';
|
||||||
|
import {CommandManager} from './commandmanager';
|
||||||
|
|
||||||
let client;
|
let client;
|
||||||
|
|
||||||
@@ -16,7 +17,8 @@ export async function init() {
|
|||||||
Config.load();
|
Config.load();
|
||||||
|
|
||||||
await Database.init();
|
await Database.init();
|
||||||
|
|
||||||
|
console.log();
|
||||||
await MessageManager.init();
|
await MessageManager.init();
|
||||||
|
|
||||||
client = new Discord.Client();
|
client = new Discord.Client();
|
||||||
@@ -25,4 +27,5 @@ export async function init() {
|
|||||||
await eventHandler.init(client);
|
await eventHandler.init(client);
|
||||||
eventHandler.handleEvents();
|
eventHandler.handleEvents();
|
||||||
|
|
||||||
|
CommandManager.reload();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user