Skip to content

Commit

Permalink
Add Eris option passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
exoRift committed Jul 26, 2020
1 parent 9629efd commit 7762b15
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- The `number` arg type now uses `parseFloat()` instead of `parseInt()`
- Massively improved argument parsing performance
- There is now a new Agent method to build an in-depth help menu for a specific command
- Added a passthrough in the Agent constructor to append Eris constructor options to the calculated intents

### **Important notes**
- Completely redid how initial guild data is supplied to the Agent. See documentation and method `Agent.compileGuildSQL`
Expand Down
7 changes: 5 additions & 2 deletions lib/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ class Agent {
* @prop {Object|StatusMessageFunction} [data.options.statusMessage] The status for the bot. It can be an object containing the data, or a callback function for each shard. By default, it's the bot's prefix
* @prop {Boolean} [data.options.fireOnEdit=false] Whether the command handler is called when a command is edited or not
* @prop {Boolean} [data.options.fireOnReactionRemove=false] Whether the reaction handler is triggered on the removal of reactions as well
* @prop {Object} [data.options.postEventFunctions={}] A collection of functions to run after an event is triggered.
* @prop {Object} [data.options.postEventFunctions={}] A collection of functions to run after an event is triggered
* @prop {PostMessageFunction} [data.options.postEventFunctions.message] A function that runs after every message whether it triggers a command or not
* @prop {PostReactionFunction} [data.options.postEventFunctions.reaction] A function that runs after every reaction whether it triggers a react command or not
* @prop {PostPermissionFunction} [data.options.postEventFunctions.permission] A function that runs after a permission is changed
* @prop {PostPrefixFunction} [data.options.postEventFunctions.prefix] A function that runs after a guild prefix is changed
* @prop {Object} [data.options.erisOptions={}] A passthrough for additional Eris options. (Does not override intents, supply additional intents to `options.intents`)
*/
constructor ({ Eris, token, handlerData = {}, options = {} }) {
const {
Expand All @@ -68,7 +69,8 @@ class Agent {
reaction: reactionEvent,
permission: permissionEvent,
prefix: prefixEvent
} = {}
} = {},
erisOptions = {}
} = options

const baseIntents = [
Expand Down Expand Up @@ -113,6 +115,7 @@ class Agent {
* @type {Eris.Client}
*/
this.client = new Eris(token, {
...erisOptions,
intents: baseIntents.concat(intents)
})

Expand Down
23 changes: 23 additions & 0 deletions lib/agent/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ test('statusEdited', async (t) => {
}
})

test('erisOptionsPassthrough', (t) => {
t.context.offlineInit(undefined, {
erisOptions: {
test: 'test option'
}
})

t.deepEqual(t.context.agent.client._intents, [
'MESSAGE_CREATE',
'MESSAGE_UPDATE',
'MESSAGE_DELETE'
], 'Intents not overrided')

t.deepEqual(t.context.agent.client._options, {
intents: [
'MESSAGE_CREATE',
'MESSAGE_UPDATE',
'MESSAGE_DELETE'
],
test: 'test option'
}, 'Intents not overrided')
})

test('messageEvent', async (t) => {
await t.context.init({
commands: [
Expand Down
10 changes: 9 additions & 1 deletion test/pdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ class PseudoClient extends EventEmitter {

/**
* Gateway intents
* @type {String[]}
* @private
* @type {String[]}
*/
this._intents = options.intents

/**
* Options
* @private
* @type {Object}
*/
this._options = options

/**
* The bot owner
* @private
Expand Down

0 comments on commit 7762b15

Please sign in to comment.