Merge pull request #1 from Vylpes/develop

VylBot Core 1.0.1
This commit is contained in:
Vylpes 2020-10-23 18:30:10 +01:00 committed by GitHub
commit 91b9764d03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 44 deletions

3
.gitignore vendored
View file

@ -108,3 +108,6 @@ commands/
events/ events/
bot.js bot.js
config.json config.json
# Linux Environment Files
*.swp

View file

@ -12,15 +12,19 @@ Copy the config template file and fill in the strings.
{ {
"token": "", "token": "",
"prefix": "", "prefix": "",
"commands": "", "commands": [
"events": "" ""
],
"events": [
""
]
} }
``` ```
* **Token:** Your bot's token * **Token:** Your bot's token
* **Prefix** The command prefix * **Prefix** The command prefix
* **Commands:** The folder name containing your commands * **Commands:** An array of the folders which contain your commands
* **Events:** The folder name containing your events * **Events:** An array of the folders which contain your events
## Usage ## Usage

View file

@ -40,8 +40,12 @@ An example configuration:
{ {
"token": "<YOUR-BOT-TOKEN>", "token": "<YOUR-BOT-TOKEN>",
"prefix": "!", "prefix": "!",
"commands": "commands", "commands": [
"events": "events" "commands"
],
"events": [
"events"
]
} }
``` ```

View file

@ -33,10 +33,10 @@ class client extends Client {
if (typeof config.token != "string") throw "Token is not a string"; if (typeof config.token != "string") throw "Token is not a string";
if (typeof config.prefix != "string") throw "Prefix is not a string"; if (typeof config.prefix != "string") throw "Prefix is not a string";
if (typeof config.commands != "string") throw "Commands is not a string"; if (typeof config.commands != "object") throw "Commands is not a string";
if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist"; if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist";
if (typeof config.events != "string") throw "Events is not a string"; if (typeof config.events != "object") throw "Events is not a string";
if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist"; if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist";
this._config = config; this._config = config;

View file

@ -7,38 +7,42 @@ class util {
} }
loadCommand(name, args, message) { loadCommand(name, args, message) {
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => { for (let c = 0; c < this._client.config.commands.length; c++) {
if (err == null) { let folder = this._client.config.commands[c];
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
let command = new commandFile();
let requiredConfigs = command.requiredConfigs; stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
if (err == null) {
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
let command = new commandFile();
for (let i = 0; i < requiredConfigs.length; i++) { let requiredConfigs = command.requiredConfigs;
if (!this._client.config[name]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
}
let requiredRoles = command.roles; for (let i = 0; i < requiredConfigs.length; i++) {
if (!this._client.config[name]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
}
for (let i = 0; i < requiredRoles.length; i++) { let requiredRoles = command.roles;
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
return;
}
}
command[command.run]({ for (let i = 0; i < requiredRoles.length; i++) {
"command": name, if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
"arguments": args, message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
"client": this._client, return;
"message": message, }
"config": config }
});
} else if (err.code === 'ENOENT') { command[command.run]({
// FILE DOESN'T EXIST "command": name,
} "arguments": args,
}); "client": this._client,
"message": message,
"config": config
});
} else if (err.code === 'ENOENT') {
// FILE DOESN'T EXIST
}
});
}
} }
loadEvents() { loadEvents() {

View file

@ -1,6 +1,9 @@
class command { class command {
constructor(run) { constructor(run) {
this.run = run; this.run = run;
this._roles = [];
this._requiredConfigs = [];
} }
// Description // Description
@ -31,8 +34,6 @@ class command {
} }
// Roles // Roles
_roles = [];
get roles() { get roles() {
return this._roles; return this._roles;
} }
@ -42,8 +43,6 @@ class command {
} }
// Config // Config
_requiredConfigs = [];
get requiredConfigs() { get requiredConfigs() {
return this._requiredConfigs; return this._requiredConfigs;
} }