Improved plugin manager and added to command manager

This commit is contained in:
Isaac
2021-02-19 21:26:02 +00:00
parent bdcff221db
commit 67e7d36c47
15 changed files with 238 additions and 79 deletions

View File

@@ -62,15 +62,10 @@ module.exports = class PluginManager {
description
};
this.plugins.set(id, about);
try {
let plugin = new Main(this.client, id);
plugin.load();
this.plugins.set(id, Object.assign(about, {
name: plugin.name || id,
}));
let plugin = new Main(this.client, about);
this.plugins.set(id, plugin);
plugin.preload();
} catch (e) {
if (npm) {

View File

@@ -17,7 +17,7 @@ module.exports = class Plugin {
* @param {String} options.name A human-friendly name (can be different to the name in package.json)
* @param {String[]} options.commands An array of command names the plugin registers
*/
constructor(client, id, options = {}) {
constructor(client, about, options = {}) {
/** The Discord Client */
this.client = client;
@@ -28,10 +28,11 @@ module.exports = class Plugin {
// make JSDoc happy
let {
id,
version,
author,
description
} = this.manager.plugins.get(id);
} = about;
/**
* The human-friendly name of the plugin
@@ -125,7 +126,15 @@ module.exports = class Plugin {
}
/**
* The main function where your code should go. Create functions and event listeners here
* The function where any code that needs to be executed before the client is ready should go.
* **This is executed _BEFORE_ the ready event**
* @abstract
*/
preload() { }
/**
* The main function where your code should go. Create commands and event listeners here.
* **This is executed _after_ the ready event**
* @abstract
*/
load() {}