Command configs are now in their own file

This commit is contained in:
Vylpes 2020-12-23 22:05:23 +00:00
parent a7fc0e2013
commit 005de0302e
4 changed files with 67 additions and 9 deletions

View file

@ -46,10 +46,15 @@ class client extends Client {
if (typeof config.token != "string") throw "Token is not a string";
if (typeof config.prefix != "string") throw "Prefix is not a string";
// Make sure the command config string is set and the file exists
if (typeof config.cmdconfig != "string") throw "Cmdconfig is not a string";
if (!existsSync(config.cmdconfig)) throw `The file '${config.cmdconfig}' does not exist`;
// Make sure commands and events are arrays, each item inside will be validated later
if (typeof config.commands != "object") throw "Commands is not a string";
if (typeof config.events != "object") throw "Events is not a string";
this._config = config;
}
}

View file

@ -1,6 +1,5 @@
// Required Components
const { stat, readdirSync } = require('fs');
const { config } = require('process');
// Util Class
class util {
@ -25,14 +24,19 @@ class util {
let commandFile = require(`${process.cwd()}/${folder}/${name}.js`);
let command = new commandFile();
// Require the command config file and get the config for the current command
let configString = this._client.config.cmdconfig
let configFile = require(`${process.cwd()}/${configString}`);
let config = configFile[name];
// Get the list of required configurations the command needs
let commandConfigs = command.configs;
// Loop through all the required configs of the command
for (let i = 0; i < commandConfigs.length; i++) {
// If the command doesn't have the configs in the config string, throw an error
if (!this._client.config[name]) throw `${commandFile.name} requires ${commandConfigs[i]} in it's configuration`;
if (!this._client.config[name][commandConfigs[i]]) throw `${commandFile.name} requires ${commandConfigs[i]} in it's configuration`;
if (!config) throw `${commandFile.name} requires ${commandConfigs[i]} in it's configuration`;
if (!config[commandConfigs[i]]) throw `${commandFile.name} requires ${commandConfigs[i]} in it's configuration`;
}
// Get the roles required for this command to run