diff --git a/docs/index.md b/docs/index.md index 46e98ab..95fbb79 100644 --- a/docs/index.md +++ b/docs/index.md @@ -67,6 +67,7 @@ class test extends command { super.requiredConfigs = "link"; super.roles = "Moderator"; super.roles = "Admin"; + super.users = ""; } test(context) { @@ -84,11 +85,15 @@ module.exports = test; > **Note:** You can set more than one role to be required by setting `super.roles` again. -5. If you want the command to require a variable in the config, set the name in `super.requiredConfigs` +5. If you want the command to only be ran by specific users, set their ID in `super.users` + +> **Note:** You can set more than one user to be required by settubg `super.users` again. + +6. If you want the command to require a variable in the config, set the name in `super.requiredConfigs` > **Note:** You can set more than one role to be required by setting `super.requiredConfigs` again. -6. Create a method using the name you set in `super(run)`, with the `context` as its parameter. +7. Create a method using the name you set in `super(run)`, with the `context` as its parameter. The `context` parameter will be a JSON object of: diff --git a/package-lock.json b/package-lock.json index 7e1c9a7..d232b75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vylbot-core", - "version": "1.0.0", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2eb919c..cea4d1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vylbot-core", - "version": "1.0.0", + "version": "1.0.4", "description": "A discord client based upon discord.js", "main": "./src/index", "scripts": { diff --git a/src/client/client.js b/src/client/client.js index 74e75f4..150e5c3 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -34,10 +34,7 @@ class client extends Client { if (typeof config.prefix != "string") throw "Prefix 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 (typeof config.events != "object") throw "Events is not a string"; - if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist"; this._config = config; } diff --git a/src/client/util.js b/src/client/util.js index 25d0540..ec42570 100644 --- a/src/client/util.js +++ b/src/client/util.js @@ -9,14 +9,14 @@ class util { loadCommand(name, args, message) { for (let c = 0; c < this._client.config.commands.length; c++) { let folder = this._client.config.commands[c]; - - stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => { + + stat(`${process.cwd()}/${folder}/${name}.js`, err => { if (err == null) { - let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`); + let commandFile = require(`${process.cwd()}/${folder}/${name}.js`); let command = new commandFile(); - + let requiredConfigs = command.requiredConfigs; - + 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`; @@ -30,7 +30,14 @@ class util { return; } } - + + let users = command.users; + + if (!users.includes(message.member.id)) { + message.reply(`You do not have permission to run this command`); + return; + } + command[command.run]({ "command": name, "arguments": args, @@ -46,15 +53,19 @@ class util { } loadEvents() { - let eventFiles = readdirSync(`${process.cwd()}/${this._client.config.events}/`); + for (let e = 0; e < this._client.config.events.length; e++) { + let folder = this._client.config.events[e]; - for (let i = 0; i < eventFiles.length; i++) { - let eventName = eventFiles[i].split('.')[0]; - let file = require(`${process.cwd()}/${this._client.config.events}/${eventName}.js`); - - let event = new file; - - this._client.on(eventName, event[event.run]); + let eventFiles = readdirSync(`${process.cwd()}/${folder}/`); + + for (let i = 0; i < eventFiles.length; i++) { + let eventName = eventFiles[i].split('.')[0]; + let file = require(`${process.cwd()}/${folder}/${eventName}.js`); + + let event = new file; + + this._client.on(eventName, event[event.run]); + } } } } diff --git a/src/type/command.js b/src/type/command.js index 17f2c75..e3f1885 100644 --- a/src/type/command.js +++ b/src/type/command.js @@ -4,6 +4,7 @@ class command { this._roles = []; this._requiredConfigs = []; + this._users = []; } // Description @@ -50,6 +51,15 @@ class command { set requiredConfigs(conf) { this._requiredConfigs.push(conf); } + + // Users + get users() { + return this._users; + } + + set users(userid) { + this._users.push(userid); + } } module.exports = command;