From 7762b152c061a130d4b1ada6e63fb7394b2d0538 Mon Sep 17 00:00:00 2001 From: Arthur Neuman Date: Sun, 26 Jul 2020 13:17:51 -0400 Subject: [PATCH] Add Eris option passthrough --- CHANGELOG.md | 1 + lib/agent/index.js | 7 +++++-- lib/agent/index.test.js | 23 +++++++++++++++++++++++ test/pdc.js | 10 +++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2915541..6e59f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/lib/agent/index.js b/lib/agent/index.js index d47d597..e41d61b 100644 --- a/lib/agent/index.js +++ b/lib/agent/index.js @@ -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 { @@ -68,7 +69,8 @@ class Agent { reaction: reactionEvent, permission: permissionEvent, prefix: prefixEvent - } = {} + } = {}, + erisOptions = {} } = options const baseIntents = [ @@ -113,6 +115,7 @@ class Agent { * @type {Eris.Client} */ this.client = new Eris(token, { + ...erisOptions, intents: baseIntents.concat(intents) }) diff --git a/lib/agent/index.test.js b/lib/agent/index.test.js index ceb08dc..ee4ea5b 100644 --- a/lib/agent/index.test.js +++ b/lib/agent/index.test.js @@ -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: [ diff --git a/test/pdc.js b/test/pdc.js index c6cf002..7753e87 100644 --- a/test/pdc.js +++ b/test/pdc.js @@ -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