From 4076df2ffd8d21cec7df398f2e6561bd8e617502 Mon Sep 17 00:00:00 2001 From: Desvelao Date: Sun, 5 Apr 2020 17:32:12 +0200 Subject: [PATCH] Updates --- Aghanim.js.html | 2 +- Category.html | 2 +- Category.js.html | 2 +- Client.html | 256 +++++++++++++++++++++++--- Client.js.html | 275 ++++++++++++++-------------- Command.html | 30 +-- Command.js.html | 5 +- Component.html | 2 +- Component.js.html | 2 +- Logger.js.html | 2 +- global.html | 16 +- index.html | 2 +- module-aghanim.html | 2 +- tutorial-1getting-started.html | 2 +- tutorial-2create-bot.html | 2 +- tutorial-3command.html | 12 +- tutorial-4components.html | 9 +- tutorial-5categories.html | 2 +- tutorial-6command-requirements.html | 18 +- 19 files changed, 422 insertions(+), 221 deletions(-) diff --git a/Aghanim.js.html b/Aghanim.js.html index 06b399f..9f4bd73 100644 --- a/Aghanim.js.html +++ b/Aghanim.js.html @@ -66,7 +66,7 @@

Source: Aghanim.js


diff --git a/Category.html b/Category.html index 90cb2f3..c5197ad 100644 --- a/Category.html +++ b/Category.html @@ -367,7 +367,7 @@
Properties

diff --git a/Category.js.html b/Category.js.html index 41d1956..08cd21f 100644 --- a/Category.js.html +++ b/Category.js.html @@ -59,7 +59,7 @@

Source: Category.js


diff --git a/Client.html b/Client.html index 035ebd3..9d0c944 100644 --- a/Client.html +++ b/Client.html @@ -2293,7 +2293,7 @@
Properties
Source:
@@ -2433,7 +2433,7 @@
Parameters:
Source:
@@ -2592,7 +2592,7 @@
Parameters:
Source:
@@ -2729,7 +2729,7 @@
Parameters:
Source:
@@ -2891,7 +2891,7 @@
Parameters:
Source:
@@ -3028,7 +3028,7 @@
Parameters:
Source:
@@ -3165,7 +3165,7 @@
Parameters:
Source:
@@ -3327,7 +3327,7 @@
Parameters:
Source:
@@ -3486,7 +3486,7 @@
Parameters:
Source:
@@ -3623,7 +3623,7 @@
Parameters:
Source:
@@ -3782,7 +3782,7 @@
Parameters:
Source:
@@ -3987,7 +3987,7 @@
Parameters:
Source:
@@ -4147,7 +4147,7 @@
Parameters:
Source:
@@ -4308,7 +4308,7 @@
Parameters:
Source:
@@ -4470,7 +4470,7 @@
Parameters:
Source:
@@ -4580,7 +4580,7 @@

reloadC
Source:
@@ -4668,7 +4668,7 @@

reloa
Source:
@@ -4828,7 +4828,7 @@

Parameters:
Source:
@@ -5087,7 +5087,7 @@
Parameters:
Source:
@@ -5293,7 +5293,7 @@
Parameters:
Source:
@@ -5329,7 +5329,7 @@
Parameters:
-

aghanim:command:pre

+

aghanim:command:prereq

@@ -5337,7 +5337,7 @@

aghanim:command:pre

- Fired before a command is executed. Don't cant stop command of running + Fired before a command is executed. Can't stop command of running
@@ -5499,7 +5499,213 @@
Parameters:
Source:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

aghanim:command:prerun

+ + + + + + +
+ Fired before a command is executed. Can't stop command of running +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
msg + + +object + + + + Eris Message object
args + + +args + + + + Args object
client + + +Client + + + + Client instance
command + + +Command + + + + Command
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -5705,7 +5911,7 @@
Parameters:
Source:
@@ -5907,7 +6113,7 @@
Parameters:

diff --git a/Client.js.html b/Client.js.html index c18dfd8..1fe27e5 100644 --- a/Client.js.html +++ b/Client.js.html @@ -30,10 +30,10 @@

Source: Client.js

const glob = require('glob') const path = require('path') const Logger = require('another-logger') +const reload = require('require-reload')(require) const Command = require('./Command') const Category = require('./Category') const Component = require('./Component') -const reload = require('require-reload')(require) const builtinCommandRequirements = require('./requirements') const DEFAULT_CATEGORY = 'Default' @@ -42,7 +42,7 @@

Source: Client.js

const logger = new Logger({ label: 'Aghanim', timestamps: true, - levels: { + levels: { dev: { style: 'magenta' }, commandrunerror: { text: 'command:run:error', style: 'red' }, componentrunerror: { text: 'component:run:error', style: 'red' }, @@ -101,7 +101,7 @@

Source: Client.js

this.setup = {} // /** @prop {Object} - Context Extension */ // this.contextExtension = {} - + this._ready = false this._commandsRequirements = {} @@ -158,13 +158,13 @@

Source: Client.js

* @param {string|EmbedMessageObject} content - Message content to send * @param {object} file - File to send */ - this.owner.send = function(content, file) { + this.owner.send = function sendOwner(content, file) { channel.createMessage(content, file) } }) this.handleEvent('ready')() - }) + }) }).on('error', (err) => { logger.error(err) /** @@ -201,24 +201,21 @@

Source: Client.js

helpMessage += cmds.filter(c => !c.hide).map(c => `\`${client.prefix}${c.name}${c.args ? ' ' + c.args : ''}\` - ${c.help}${c.childs.length ? '\n' + c.childs.filter(s => !s.hide).map(s => ` · \`${s.name}${s.args ? ' ' + s.args : ''}\` - ${s.help}`).join('\n') : ''}`) .join('\n') } + } else if (categories.length) { + helpMessage += client.categories.filter(c => !c.hide).map(c => `**${c.name}** \`${client.prefix}help ${c.name.toLowerCase()}\` - ${c.help}`).join('\n') + '\n\n' + client.setup.helpMessageAfterCategories } else { - if(categories.length){ - helpMessage += client.categories.filter(c => !c.hide).map(c => `**${c.name}** \`${client.prefix}help ${c.name.toLowerCase()}\` - ${c.help}`).join('\n') + '\n\n' + client.setup.helpMessageAfterCategories - }else{ - const cmds = client.getCommandsOfCategories("Default") - if (!cmds) { - helpMessage += "No commands" - } else { - helpMessage += cmds.filter(c => !c.hide).map(c => `\`${client.prefix}${c.name}${c.args ? ' ' + c.args : ''}\` - ${c.help}${c.childs.length ? '\n' + c.childs.filter(s => !s.hide).map(s => ` · \`${s.name}${s.args ? ' ' + s.args : ''}\` - ${s.help}`).join('\n') : ''}`) - .join('\n') - } + const cmds = client.getCommandsOfCategories('Default') + if (!cmds) { + helpMessage += 'No commands' + } else { + helpMessage += cmds.filter(c => !c.hide).map(c => `\`${client.prefix}${c.name}${c.args ? ' ' + c.args : ''}\` - ${c.help}${c.childs.length ? '\n' + c.childs.filter(s => !s.hide).map(s => ` · \`${s.name}${s.args ? ' ' + s.args : ''}\` - ${s.help}`).join('\n') : ''}`) + .join('\n') } } if (!client.setup.helpDM) { return msg.channel.createMessage(helpMessage) - } else { - return msg.author.getDMChannel().then(channel => channel.createMessage(helpMessage)) } + return msg.author.getDMChannel().then(channel => channel.createMessage(helpMessage)) })) } } @@ -244,65 +241,65 @@

Source: Client.js

// command, // client: this // }, this.contextExtension) - - try { - if (!command || !args ) return + /** + * Fired before a command is executed. Can't stop command of running + * @event Client#aghanim:command:prereq + * @param {object} msg - Eris Message object + * @param {args} args - Args object + * @param {Client} client - Client instance + * @param {Command} command - Command + */ + this.emit('aghanim:command:prereq', msg, args, this, command) + await command.runHook('prereq', msg, args, this, command) const notpass = !(await this.checkRequirements(msg, args, this, command)) - if(notpass) return - + if (notpass) return /** - * Fired before a command is executed. Don't cant stop command of running - * @event Client#aghanim:command:pre + * Fired before a command is executed. Can't stop command of running + * @event Client#aghanim:command:prerun * @param {object} msg - Eris Message object * @param {args} args - Args object * @param {Client} client - Client instance * @param {Command} command - Command */ - this.emit('aghanim:command:pre', msg, args, this, command) - await command.runHook('pre', msg, args, this, command) - if(command.response){ - switch(typeof(command.response)){ - case "string":{ - await msg.channel.createMessage(command.response) - break - } - case "function":{ - const response = command.response(msg, args, this, command) - await msg.channel.createMessage(response) - break - } - case "object":{ - await msg.channel.createMessage(command.response) - break - } - default:{ - - } + this.emit('aghanim:command:prerun', msg, args, this, command) + await command.runHook('prerun', msg, args, this, command) + if (command.response) { + switch (typeof command.response) { + case 'string': { + await msg.channel.createMessage(command.response) + break } - }else if(command.responseDM){ - switch(typeof(command.responseDM)){ - case "string":{ - await msg.channel.createMessage(command.responseDM) - break - } - case "function":{ - const responseDM = command.responseDM(msg, args, this, command) - await msg.channel.createMessage(responseDM) - break - } - case "object":{ - await msg.channel.createMessage(command.responseDM) - break - } - default:{ - - } + case 'function': { + const response = command.response(msg, args, this, command) + await msg.channel.createMessage(response) + break } - }else{ - const value = await command.run(msg, args, this, command) - // if (val === undefined) { logger.warn(`${command.name} returned a promise with undefined value`) } - + case 'object': { + await msg.channel.createMessage(command.response) + break + } + default: {} + } + } else if (command.responseDM) { + switch (typeof command.responseDM) { + case 'string': { + await msg.channel.createMessage(command.responseDM) + break + } + case 'function': { + const responseDM = command.responseDM(msg, args, this, command) + await msg.channel.createMessage(responseDM) + break + } + case 'object': { + await msg.channel.createMessage(command.responseDM) + break + } + default: {} + } + } else { + await command.run(msg, args, this, command) } /** * Fired after a command is executed. Don't cant stop command of running @@ -314,7 +311,7 @@

Source: Client.js

*/ this.emit('aghanim:command:executed', msg, args, this, command) await command.runHook('executed', msg, args, this, command) - }catch(err) { + } catch (err) { /** * Fired when a command got an error executing the run function * @event Client#aghanim:command:error @@ -326,14 +323,13 @@

Source: Client.js

*/ logger.commandrunerror(`${command.name} - ${err} - ${err.stack}`) this.emit('aghanim:command:error', err, msg, args, this, command) - try{ + try { await command.runHook('error', msg, args, this, command, err) - }catch(errhook){ + } catch (errhook) { logger.commandrunerror(`${command.name} - ${errhook} - ${errhook.stack}`) this.emit('aghanim:command:error', errhook, msg, args, this, command) } } - } handleEvent(eventname) { @@ -366,9 +362,7 @@

Source: Client.js

* @param {msg} msg - Eris Message. * @param {Client} client - Client instance. */ - extendCommandArgs(args, msg, client) { - - } + extendCommandArgs(args, msg, client) { } /* eslint class-methods-use-this: "off" */ _addFromDirectory(dirname, func) { if (!dirname.endsWith('/')) dirname += '/' @@ -382,8 +376,8 @@

Source: Client.js

* @param {Command | object} command - The command to add to the bot. * @returns {Command} - Command added */ - addCommand(command) { - if (!(command instanceof Command) && typeof(command) === 'object') { // allow command as object and create it + addCommand(command) { /* eslint consistent-return:"off" */ + if (!(command instanceof Command) && typeof command === 'object') { // allow command as object and create it command = new Command(command) } if (!(command instanceof Command)) throw new TypeError('Not a command') // throw error if not a Command instance or class extending of command @@ -392,9 +386,9 @@

Source: Client.js

logger.warn(`Category not found for ${command.name}. Established as ${DEFAULT_CATEGORY}`) } command.client = this // inject client on command - const requirements = command.requirements + const { requirements } = command command.requirements = [] // reset command.requirements - mapCommandRequirement(this, command, requirements) + mapCommandRequirement(this, command, requirements) /* eslint no-use-before-define: "off" */ // Check if command exists already and throw error or add to client if (!command.childOf) { @@ -403,13 +397,13 @@

Source: Client.js

logger.commandadderror(`Command exists: ${command.name}`) } else { this.commands.push(command) - logger.dev(`Command added: ${command.name}`) + logger.dev(`Command added: ${command.name}`) return command } } else { // Find parent command and add to client const parent = this.commands.find(c => c.names.includes(command.childOf)) - if (!parent) { - throw new Error(`Parent command ${command.childOf} not found for ${command.name}`) + if (!parent) { + throw new Error(`Parent command ${command.childOf} not found for ${command.name}`) } else { if (command.category !== parent.category) { // Set category as parent category if is different command.category = parent.category @@ -428,7 +422,7 @@

Source: Client.js

* @param {string} dirname - The location of the directory. */ addCommandDir(dirname) { - this._addFromDirectory(dirname, (filename) => this.addCommandFile(filename)) + this._addFromDirectory(dirname, filename => this.addCommandFile(filename)) } /** @@ -440,8 +434,8 @@

Source: Client.js

try { const commandLoaded = reload(filename) const command = this.addCommand(commandLoaded) - if(command){ - command. filename = filename + if (command) { + command.filename = filename } return command } catch (err) { @@ -473,13 +467,13 @@

Source: Client.js

* @returns {Component} - Component added */ addComponent(component, options) { - if (!(component instanceof Component) && typeof(component) === 'object') { // allow load components as object + if (!(component instanceof Component) && typeof component === 'object') { // allow load components as object const componentObject = component - if(!componentObject.name) throw new TypeError(`Component as object require an name => ${JSON.stringify(componentObject)}`) - component = class extends Component{ - constructor(client, options){ + if (!componentObject.name) throw new TypeError(`Component as object require an name => ${JSON.stringify(componentObject)}`) + component = class extends Component { + constructor(client, options) { super(client, options) - if(typeof(componentObject.constructor) === 'function'){ + if (typeof componentObject.constructor === 'function'){ componentObject.constructor(client, options) } } @@ -513,7 +507,7 @@

Source: Client.js

try { const componentClass = reload(filename) const component = this.addComponent(componentClass) - if(component){ + if (component) { component.filename = filename } return component @@ -527,21 +521,21 @@

Source: Client.js

* @param {string} dirname Path to load components */ addComponentDir(dirname) { - this._addFromDirectory(dirname, (filename) => this.addComponentFile(filename)) + this._addFromDirectory(dirname, filename => this.addComponentFile(filename)) } /** * Define a requirement that can be added by commands * @param {(CommandRequirementObject|CommandRequirementFunction)} requirement - Requirement to define */ - addCommandRequirement(requirement){ - if(typeof(requirement) === 'object' && requirement.type){ + addCommandRequirement(requirement) { + if (typeof requirement === 'object' && requirement.type) { this._commandsRequirements[requirement.type] = requirement return requirement - }else if(typeof(requirement) === 'function'){ + } else if (typeof requirement === 'function') { this._commandsRequirements[requirement.name] = requirement return requirement - }else{ + } else { logger.error('Error adding command requirement') } } @@ -554,7 +548,7 @@

Source: Client.js

addCommandRequirementFile(filename) { try { const requirementLoaded = reload(filename) - if (typeof(requirementLoaded) === "function") Object.defineProperty(requirementLoaded, 'name', {value: path.basename(filename, '.js')}) + if (typeof requirementLoaded === 'function') Object.defineProperty(requirementLoaded, 'name', { value: path.basename(filename, '.js') }) const requirement = this.addCommandRequirement(requirementLoaded) if (requirement) { requirement.filename = filename @@ -570,7 +564,7 @@

Source: Client.js

* @param {string} dirname Path to load command requirements */ addCommandRequirementDir(dirname) { - this._addFromDirectory(dirname, (filename) => this.addCommandRequirementFile(filename)) + this._addFromDirectory(dirname, filename => this.addCommandRequirementFile(filename)) } /** @@ -583,14 +577,14 @@

Source: Client.js

const commands = this.commands.reduce((filenames, command) => { filenames.push(command.filename ? command.filename : command) if (command.childs.length > 0) { - command.childs.forEach(subcommand => { + command.childs.forEach((subcommand) => { filenames.push(subcommand.filename ? subcommand.filename : subcommand) }) } return filenames }, []) this.commands = [] - commands.forEach(command => typeof(command) === "string" ? this.addCommandFile(command) : this.addCommand(command)) + commands.forEach(command => typeof command === 'string' ? this.addCommandFile(command) : this.addCommand(command)) /* eslint no-confusing-arrow: 'off' */ } /** @@ -602,28 +596,28 @@

Source: Client.js

logger.dev('Reloading components...') const components = Object.keys(this.components).map(key => this.components[key]).reduce((filenames, component) => { if (component.filename) { - filenames.push([component.filename, component.name || component.constructor.name]) - } - return filenames - }, []) - //this.components = {} + filenames.push([component.filename, component.name || component.constructor.name]) + } + return filenames + }, []) + components.forEach(([filename, name]) => { delete this.components[name] this.addComponentFile(filename) }) this.handleEvent('ready')() - } + } - reloadCommandRequirements() { + reloadCommandRequirements() { logger.dev('Reloading command requirements...') - const filenames = Object.keys(this._commandsRequirements).map(key => this._commandsRequirements[key]).reduce((filenames, requirement) => { + const filenamesRequirement = Object.keys(this._commandsRequirements).map(key => this._commandsRequirements[key]).reduce((filenames, requirement) => { if (requirement.filename) { filenames.push(requirement.filename) } return filenames }, []) // this._commandsRequirements = {} - filenames.forEach(filename => this.addCommandRequirementFile(filename)) + filenamesRequirement.forEach(filename => this.addCommandRequirementFile(filename)) } /** @@ -664,15 +658,15 @@

Source: Client.js

// Traditional prefix handling - if there is no prefix, skip this rule const prefix = this.getPrefixForMessage(msg) // TODO: guild config if (prefix !== undefined && msg.content.startsWith(prefix)) { - return {prefix, content: msg.content.substr(prefix.length)} + return { prefix, content: msg.content.substr(prefix.length) } } // Allow mentions to be used as prefixes according to config const match = msg.content.match(this.mentionPrefixRegExp) if (this.allowMention && match) { // TODO: guild config - return {prefix: match[0], content: msg.content.substr(match[0].length)} + return { prefix: match[0], content: msg.content.substr(match[0].length) } } // we got nothing - return {prefix: undefined, content: msg.content} + return { prefix: undefined, content: msg.content } } /** @@ -698,9 +692,8 @@

Source: Client.js

triggerMessageCreate(msg, client) { return true } - + /** - * * @typedef EmbedMessageObject * @see {@link https://abal.moe/Eris/docs/TextChannel#function-createMessage EmbedMessageObject} */ @@ -726,11 +719,11 @@

Source: Client.js

* @returns {parseCommand} - */ createCommandArgs(msg) { - const {prefix, content} = this.splitPrefixFromContent(msg) - if( typeof prefix !== 'string' || typeof content !== 'string') return + const { prefix, content } = this.splitPrefixFromContent(msg) + if (typeof prefix !== 'string' || typeof content !== 'string') return const args = content.split(' ').map(word => word.trim()) - + /** * Message is spit for spaces (' ') * @typedef args @@ -756,26 +749,26 @@

Source: Client.js

return args } - async checkRequirements(msg, args, client, command){ - if(!command.enable){ return false} + async checkRequirements(msg, args, client, command) { + if (!command.enable) { return false } return command.requirements.reduce(async (result, requirement) => { - if(!(await result)){ return Promise.resolve(false) } - if(typeof(requirement) === 'object'){ - const pass = await requirement.condition(msg, args, client, command, requirement) - if(pass === null){ // ignore response/responseDM/run methods + if (!(await result)) { return Promise.resolve(false) } + if (typeof requirement === 'object') { + const pass = await requirement.validate(msg, args, client, command, requirement) + if (pass === null) { // ignore response/responseDM/run methods return Promise.resolve(false) - }else if(!pass){ // false/undefined do response/responseDM/run methods - if(["string", "object"].includes(typeof(requirement.response))){ + } else if (!pass) { // false/undefined do response/responseDM/run methods + if (["string", "object"].includes(typeof(requirement.response))) { await msg.channel.createMessage(requirement.response) // Response to message - }else if(typeof(requirement.response) === "function"){ + } else if (typeof requirement.response === "function") { const res = await requirement.response(msg, args, client, command, requirement) await msg.channel.createMessage(res) // Response to message - }else if(["string", "object"].includes(typeof(requirement.responseDM))){ + } else if (["string", "object"].includes(typeof(requirement.responseDM))) { await msg.author.getDMChannel().then(channel => channel.createMessage(requirement.responseDM)) // Response with a dm - }else if(typeof(requirement.responseDM) === "function"){ + } else if (typeof requirement.responseDM === "function") { const res = await requirement.responseDM(msg, args, client, command, requirement) await msg.author.getDMChannel().then(channel => channel.createMessage(res)) // Response with a dm - }else if(typeof(requirement.run) === "function"){ + } else if (typeof requirement.run === "function") { await requirement.run(msg, args, client, command, requirement) // Custom } return Promise.resolve(false) @@ -821,30 +814,30 @@

Source: Client.js

} -function getCommandRequirement(client, command, req){ - if(typeof(req) === 'string'){ - if(builtinCommandRequirements[req]){ +function getCommandRequirement(client, command, req) { + if (typeof req === 'string') { + if (builtinCommandRequirements[req]) { const requirement = builtinCommandRequirements[req]({command, client}) requirement.type = req return requirement - }else if(client._commandsRequirements[req]){ - if(typeof(client._commandsRequirements[req]) === "object"){ + } else if (client._commandsRequirements[req]) { + if (typeof client._commandsRequirements[req] === "object") { return client._commandsRequirements[req] - }else if(typeof(client._commandsRequirements[req]) === "function"){ - return client._commandsRequirements[req]({command, client}) + }else if(typeof client._commandsRequirements[req] === "function"){ + return client._commandsRequirements[req]({ command, client }) } - }else{ + } else { throw new Error(`String command requirement not found: ${req}`) } - }else if(typeof(req) === 'object'){ - if(builtinCommandRequirements[req.type]){ - const requirement = builtinCommandRequirements[req.type]({...req, command, client}) + } else if (typeof req === 'object') { + if (builtinCommandRequirements[req.type]) { + const requirement = builtinCommandRequirements[req.type]({ ...req, command, client }) requirement.type = req.type return requirement - }else{ + } else { return req } - }else{ + } else { throw new TypeError(`Requirement: ${req} on ${command.name}`) } } @@ -871,7 +864,7 @@

Source: Client.js


diff --git a/Command.html b/Command.html index 0d28ce5..8f286e2 100644 --- a/Command.html +++ b/Command.html @@ -1023,7 +1023,7 @@
Properties:
Source:
@@ -1129,7 +1129,7 @@
Properties:
Source:
@@ -1238,7 +1238,7 @@
Properties:
Source:
@@ -1450,7 +1450,7 @@
Properties:
Source:
@@ -1559,7 +1559,7 @@
Properties:
Source:
@@ -1665,7 +1665,7 @@
Properties:
Source:
@@ -1877,7 +1877,7 @@
Properties:
Source:
@@ -2045,7 +2045,7 @@

namesSource:
@@ -2742,7 +2742,7 @@
Parameters:
Source:
@@ -2879,7 +2879,7 @@
Parameters:
Source:
@@ -2967,7 +2967,7 @@

errorSource:
@@ -3127,7 +3127,7 @@
Parameters:
Source:
@@ -3264,7 +3264,7 @@
Parameters:
Source:
@@ -3472,7 +3472,7 @@
Parameters:
Source:
@@ -3516,7 +3516,7 @@
Parameters:

diff --git a/Command.js.html b/Command.js.html index 4fcc8a6..73242fa 100644 --- a/Command.js.html +++ b/Command.js.html @@ -88,7 +88,8 @@

Source: Command.js

this.requirements = Array.isArray(options.requirements) ? options.requirements : [] // These requirements are mapped in client.addCommand /** @prop {object} - Command Hooks */ this.hooks = { - pre: [], // Fired before run command + prereq: [], // Fired before check reqiurements + prerun: [], // Fired before run command executed: [], // Fired after command is run error: [] // Fired when there is an error running pre/executed hooks and response/run methods } @@ -226,7 +227,7 @@

Source: Command.js


diff --git a/Component.html b/Component.html index ff6ef90..6b50142 100644 --- a/Component.html +++ b/Component.html @@ -447,7 +447,7 @@
Properties:

diff --git a/Component.js.html b/Component.js.html index a11fff7..bbe9ed8 100644 --- a/Component.js.html +++ b/Component.js.html @@ -56,7 +56,7 @@

Source: Component.js


diff --git a/Logger.js.html b/Logger.js.html index f75e3dd..024a666 100644 --- a/Logger.js.html +++ b/Logger.js.html @@ -42,7 +42,7 @@

Source: Logger.js


diff --git a/global.html b/global.html index a8af072..f13d472 100644 --- a/global.html +++ b/global.html @@ -451,7 +451,7 @@
Properties:
Source:
@@ -643,7 +643,7 @@
Parameters:
Source:
@@ -848,7 +848,7 @@
Properties
Source:
@@ -1126,7 +1126,7 @@
Properties:
Source:
@@ -1249,7 +1249,7 @@
Parameters:
Source:
@@ -1346,7 +1346,7 @@

EmbedMessageObject

Source:
@@ -1728,7 +1728,7 @@
Properties:
Source:
@@ -1758,7 +1758,7 @@
Properties:

diff --git a/index.html b/index.html index cfba63c..4143d79 100644 --- a/index.html +++ b/index.html @@ -121,7 +121,7 @@

Usage


diff --git a/module-aghanim.html b/module-aghanim.html index a12f737..c8b6d5b 100644 --- a/module-aghanim.html +++ b/module-aghanim.html @@ -946,7 +946,7 @@
Properties:

diff --git a/tutorial-1getting-started.html b/tutorial-1getting-started.html index c65be57..227ad4d 100644 --- a/tutorial-1getting-started.html +++ b/tutorial-1getting-started.html @@ -95,7 +95,7 @@

Fast Example


diff --git a/tutorial-2create-bot.html b/tutorial-2create-bot.html index bba9103..ca69e35 100644 --- a/tutorial-2create-bot.html +++ b/tutorial-2create-bot.html @@ -56,7 +56,7 @@

Example


diff --git a/tutorial-3command.html b/tutorial-3command.html index ce2f2d4..7f5825b 100644 --- a/tutorial-3command.html +++ b/tutorial-3command.html @@ -39,10 +39,11 @@

Create a Command

args : '', requirements: [], // Define requirements for this command. See command requirements tutorial hooks : { // Add hooks to commnand - pre : [], // Array of hooks fired before command execution. function(msg, args, client, command) + prereq : [], // Array of hooks fired before command requirement execution. function(msg, args, client, command) + prerun : [], // Array of hooks fired before command execution. function(msg, args, client, command) executed : [], // Array of hooks fired after command execution. function(msg, args, client, command) error: [] // Array of hooks fired if the command has some error. function(msg, args, client, command, error) - } + }, response: "Pong!", // String or function(msg, args, client, commnad) that returns a string or EmbedMessageObject responseDM: "Pong by DM!", // String or function(msg, args, client, commnad) that returns a string or EmbedMessageObject }, @@ -91,10 +92,11 @@

Command Object

args: '', requirements: [], hooks : { - pre : [], + prereq : [], + prerun : [], executed : [], error: [] - } + }, response: "Pong!", responseDM: "Pong by DM!", run: async (msg, args, client, command){ @@ -109,7 +111,7 @@

Command Object


diff --git a/tutorial-4components.html b/tutorial-4components.html index f447fda..107b57a 100644 --- a/tutorial-4components.html +++ b/tutorial-4components.html @@ -73,14 +73,13 @@

Component Object

name: 'ping', constructor: (client, options) => { // do something when create component instance - } + }, ready: () => { console.log('My component is ready') - } - help: 'Get Pong!', + }, messageCreate(msg, args, client, command){ console.log(`Message: ${msg.content}`) - } + }, messageReactionAdd(msg, emoji, userID, client){ // do something when a reactions is added to one message } @@ -117,7 +116,7 @@

Methods of events in components


diff --git a/tutorial-5categories.html b/tutorial-5categories.html index 7f46cc2..d6995ce 100644 --- a/tutorial-5categories.html +++ b/tutorial-5categories.html @@ -44,7 +44,7 @@

Add a category


diff --git a/tutorial-6command-requirements.html b/tutorial-6command-requirements.html index 1916b05..06b2d56 100644 --- a/tutorial-6command-requirements.html +++ b/tutorial-6command-requirements.html @@ -41,7 +41,7 @@

Add a requirement

requirements: [ { type: "onlyme" // set a type/name - condition: (msg, args, client, command, requirement) => { // function to evaluate. if returns false do first of response/responseDM/run methods + validate: (msg, args, client, command, requirement) => { // function to evaluate. if returns false do first of response/responseDM/run methods return msg.author.id === "mydiscordid" // return null to ignore response/responseDM/run methods if some these aren't undefined // you can return a context of this function if you return an array as [passCondition, conditionReqContext] @@ -69,12 +69,12 @@

Add a requirement

Define user builtin requirements

Define a custom requirement or set of them to import easily from a command definition

-
client.defineCommandRequirement(requirement) // requirement can be a object or a function
+
client.addCommandRequirement(requirement) // requirement can be a object or a function
 
 // Requiment object
-client.defineCommandRequirement({
+client.addCommandRequirement({
 	type: 'my.requirement', // name to inject in commands if these have it as requirement
-	condition: (msg, args, client, command, requirement) => { // Returns false to run first of response/responseDM/run actions
+	validate: (msg, args, client, command, requirement) => { // Returns false to run first of response/responseDM/run actions
 		return msg.author.id === "mydiscordID"
 		// return null to ignore response/responseDM/run methods if some of these are defined
 		// return [true/false, conditionReqContext] to fail requirement and pass a context to response/responseDM/run actions
@@ -83,11 +83,11 @@ 

Define user builtin requirements

{ // Returns false to run first of response/responseDM/run actions + validate: (msg, args, client, command, requirement) => { // Returns false to run first of response/responseDM/run actions return msg.author.id === "mydiscordID" // return null to ignore response/responseDM/run methods if some of these are defined // return [true/false, conditionReqContext] to fail requirement and pass a context to response/responseDM/run actions @@ -98,14 +98,14 @@

Define user builtin requirements

{ + validate: (msg, args, client, command, requirement) => { return msg.channel.guild && true // remember return true/false/null/[true/false, context] } response: "Sorry this command is only avaliable in guilds" }, { type: 'member.with.role', - condition: (msg, args, client, command, requirement) => { + validate: (msg, args, client, command, requirement) => { const member = msg.channel.guild.members.get(msg.author.id) if(!member){return false} let { role } = req @@ -268,7 +268,7 @@

Command requirements creators: