Merge pull request #4 from Vylpes/feature/command-user-only
Limit commands to specific users
This commit is contained in:
commit
e2974e1a0d
6 changed files with 44 additions and 21 deletions
|
@ -67,6 +67,7 @@ class test extends command {
|
||||||
super.requiredConfigs = "link";
|
super.requiredConfigs = "link";
|
||||||
super.roles = "Moderator";
|
super.roles = "Moderator";
|
||||||
super.roles = "Admin";
|
super.roles = "Admin";
|
||||||
|
super.users = "<ID-HERE>";
|
||||||
}
|
}
|
||||||
|
|
||||||
test(context) {
|
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.
|
> **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.
|
> **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:
|
The `context` parameter will be a JSON object of:
|
||||||
|
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vylbot-core",
|
"name": "vylbot-core",
|
||||||
"version": "1.0.0",
|
"version": "1.0.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vylbot-core",
|
"name": "vylbot-core",
|
||||||
"version": "1.0.0",
|
"version": "1.0.4",
|
||||||
"description": "A discord client based upon discord.js",
|
"description": "A discord client based upon discord.js",
|
||||||
"main": "./src/index",
|
"main": "./src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -34,10 +34,7 @@ class client extends Client {
|
||||||
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 != "object") 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 (typeof config.events != "object") 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";
|
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ class util {
|
||||||
for (let c = 0; c < this._client.config.commands.length; c++) {
|
for (let c = 0; c < this._client.config.commands.length; c++) {
|
||||||
let folder = this._client.config.commands[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) {
|
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 command = new commandFile();
|
||||||
|
|
||||||
let requiredConfigs = command.requiredConfigs;
|
let requiredConfigs = command.requiredConfigs;
|
||||||
|
@ -31,6 +31,13 @@ class util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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[command.run]({
|
||||||
"command": name,
|
"command": name,
|
||||||
"arguments": args,
|
"arguments": args,
|
||||||
|
@ -46,11 +53,14 @@ class util {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadEvents() {
|
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];
|
||||||
|
|
||||||
|
let eventFiles = readdirSync(`${process.cwd()}/${folder}/`);
|
||||||
|
|
||||||
for (let i = 0; i < eventFiles.length; i++) {
|
for (let i = 0; i < eventFiles.length; i++) {
|
||||||
let eventName = eventFiles[i].split('.')[0];
|
let eventName = eventFiles[i].split('.')[0];
|
||||||
let file = require(`${process.cwd()}/${this._client.config.events}/${eventName}.js`);
|
let file = require(`${process.cwd()}/${folder}/${eventName}.js`);
|
||||||
|
|
||||||
let event = new file;
|
let event = new file;
|
||||||
|
|
||||||
|
@ -58,5 +68,6 @@ class util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = util;
|
module.exports = util;
|
||||||
|
|
|
@ -4,6 +4,7 @@ class command {
|
||||||
|
|
||||||
this._roles = [];
|
this._roles = [];
|
||||||
this._requiredConfigs = [];
|
this._requiredConfigs = [];
|
||||||
|
this._users = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
|
@ -50,6 +51,15 @@ class command {
|
||||||
set requiredConfigs(conf) {
|
set requiredConfigs(conf) {
|
||||||
this._requiredConfigs.push(conf);
|
this._requiredConfigs.push(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Users
|
||||||
|
get users() {
|
||||||
|
return this._users;
|
||||||
|
}
|
||||||
|
|
||||||
|
set users(userid) {
|
||||||
|
this._users.push(userid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = command;
|
module.exports = command;
|
||||||
|
|
Reference in a new issue