From 2ec2e818539906c9db506067883a16839ced8b38 Mon Sep 17 00:00:00 2001 From: vylpes Date: Fri, 30 Oct 2020 18:34:51 +0000 Subject: [PATCH] Commented util.js --- src/client/util.js | 47 +++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/client/util.js b/src/client/util.js index 448bcf6..030877b 100644 --- a/src/client/util.js +++ b/src/client/util.js @@ -30,32 +30,39 @@ class util { // Loop through all the required configs of the command 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`; - } + // If the command doesn't have the configs in the config string, throw an error + 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; + // Get the roles required for this command to run + let requiredRoles = command.roles; - for (let i = 0; i < requiredRoles.length; i++) { - if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) { - message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`); - return; - } + // Loop through all roles required + for (let i = 0; i < requiredRoles.length; i++) { + // If the user doesn't have a required role, don't run the command and let the user know + if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) { + message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`); + return; } + } + // Get the ids of the users that are only permitted to run this command let users = command.users; + // If the user isn't in the list, don't run the command 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, - "client": this._client, - "message": message, - "config": config + // Run the command and pass the command context with it + command[command.run]({ + "command": name, + "arguments": args, + "client": this._client, + "message": message, + "config": config }); } else if (err.code === 'ENOENT') { // FILE DOESN'T EXIST @@ -64,18 +71,28 @@ class util { } } + // Load the events loadEvents() { + // Loop through all the event folders for (let e = 0; e < this._client.config.events.length; e++) { + // Get the current folder to check let folder = this._client.config.events[e]; + // Get the files inside of this folder let eventFiles = readdirSync(`${process.cwd()}/${folder}/`); + // Loop through all the files in the folder for (let i = 0; i < eventFiles.length; i++) { + // Get the event name, by taking the command file and removing the ".js" from the end let eventName = eventFiles[i].split('.')[0]; + + // Get the file of the event let file = require(`${process.cwd()}/${folder}/${eventName}.js`); + // Initialise the event class let event = new file; + // Set the client to emit to this event this._client.on(eventName, event[event.run]); } }