Command handler stuff, presences, other stuff

This commit is contained in:
Isaac
2021-02-18 18:41:35 +00:00
parent 7c0b1311dc
commit bdcff221db
15 changed files with 435 additions and 109 deletions

View File

@@ -7,7 +7,9 @@ const fs = require('fs');
const { join } = require('path');
const { path } = require('../../utils/fs');
/** Manages the loading of plugins */
/**
* Manages the loading of plugins
*/
module.exports = class PluginManager {
/**
* Create a PluginManager instance
@@ -16,6 +18,7 @@ module.exports = class PluginManager {
constructor(client) {
/** The Discord Client */
this.client = client;
/** A discord.js Collection (Map) of loaded plugins */
this.plugins = new Collection();

View File

@@ -5,7 +5,9 @@ const fs = require('fs');
const { join } = require('path');
const { path } = require('../../utils/fs');
/** A plugin */
/**
* A plugin
*/
module.exports = class Plugin {
/**
* Create a new Plugin
@@ -13,11 +15,9 @@ module.exports = class Plugin {
* @param {String} id The plugin ID
* @param {Object} options Plugin options
* @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 = {}) {
/** The human-friendly name of the plugin */
this.name = options.name || id;
/** The Discord Client */
this.client = client;
@@ -33,25 +33,53 @@ module.exports = class Plugin {
description
} = this.manager.plugins.get(id);
/** The unique ID of the plugin (NPM package name) */
/**
* The human-friendly name of the plugin
* @type {string}
*/
this.name = options.name || id;
/**
* An array of commands from this plugin
* @type {string[]}
*/
this.commands = options.commands;
/**
* The unique ID of the plugin (NPM package name)
* @type {string}
*/
this.id = id;
/** The version of the plugin (NPM package version) */
/**
* The version of the plugin (NPM package version)
* @type {string}
*/
this.version = version;
/** The plugin author's name (NPM package author) */
/**
* The plugin author's name (NPM package author)
* @type {(undefined|string)}
*/
this.author = author;
/** The plugin description (NPM package description) */
/**
* The plugin description (NPM package description)
* @type {string}
*/
this.description = description;
this.directory = {};
/** A cleaned version of the plugin's ID suitable for use in the directory name */
this.directory.name = this.id.replace(/@[-_a-zA-Z0-9]+\//, '');
let clean = this.id.replace(/@[-_a-zA-Z0-9]+\//, '');
/** The absolute path of the plugin directory */
this.directory.path = path(`./user/plugins/${this.directory.name}`);
/**
* Information about the plugin directory
* @property {string} name - A cleaned version of the plugin's ID suitable for use in the directory name
* @property {string} path - The absolute path of the plugin directory
*/
this.directory = {
name: clean,
path: path(`./user/plugins/${clean}`)
};
}
/**
@@ -85,8 +113,20 @@ module.exports = class Plugin {
}
}
/**
* Reset the plugin config file to the defaults
* @param {Object} template The default config template
*/
resetConfig(template) {
this.createDirectory();
let file = join(this.directory.path, 'config.json');
this.client.log.plugins(`Resetting plugin config file for "${this.name}"`);
fs.writeFileSync(file, JSON.stringify(template, null, 2));
}
/**
* The main function where your code should go. Create functions and event listeners here
* @abstract
*/
load() {}
};