| onReady | method | none | called on the bot ready event |
| onReady | method | bot | called on the bot ready event |
| onDisconnect | method | none | called when the bot disconnects |
| onMessage | method | bot, user, userID, channelID, message | called when the bot receives a message - identical to the 'action' property of a command, but triggered on every message (see below) |
| commands | array | N/A | commands a user can invoke - like the onMessage event, but only triggered on expected commands (see below) |
@ -25,13 +26,22 @@ Interfacing with each bot module is done by the properties in its module.exports
A command object contains a command, and an action to invoke if the message contains that command. Each command object needs a certain set of properties:
| command | required | string | Command to look for in the message |
| type | required | "equals" or "startsWith" | Describes whether we are looking for the message to be the exact command, or just to start with it |
| action | required | function | Callback to invoke if the command is matched (see below) |
| channelIDs | optional | array of strings | If this property is present, the command will only be triggered if sent in one of these channels |
| roleIDs | optional | array of strings | If this property is present, the command will only be triggered if send by a user with one of these roles |
| userIDs | optional | array of strings | If this property is present, the command will only be triggered if sent by one of these users |
**Permission heirarchy**
channelIDs > roleIDs > userIDs
Examples of commands that *won't* be triggered:
- channelIDs *contains* the channel, but userIDs *doesn't* - channelID check will pass, userID check subsequently won't
- channelIDs *doesn't contain* the channel, roleIDs or userIDs *contain* the user - channelID check will block the command, regardless of other permissions
- channelIDs *contains* the channel, roleIDs *doesn't* contain the user's roles, userIDs *contains* the user - channelID check will pass, roleID check will block
#### Actions
@ -80,4 +90,4 @@ Example 2:
```
The above example expects the user to type '!define something', ie only checking for the message to start with '!define'. You are still passed the full message, so can split it up and read it however you want.
*action* will only be called if the message begins with '!define', but has no restrictions on which channel(s) or user(s) use it
*action* will only be called if the message begins with '!define', but has no restrictions on which channel(s) or user(s) use it
if((!messageTrigger.channelIDs&&!messageTrigger.userIDs)//if we have neither channel nor user restraint, pass
||(messageTrigger.channelIDs&&messageTrigger.channelIDs.includes(channelID))//otherwise, if we have a channel constraint, pass if we're allowed to respond in this channel
||(messageTrigger.userIDs&&messageTrigger.userIDs.includes(userID)))//otherwise, if we have a user constraint, pass if we're allowed to respond to this user