From ac63d40cb34dc19f6e0d84b53732f33d9d35cb2f Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sat, 19 Nov 2022 17:59:25 +0700 Subject: [PATCH] chore: clean code --- src/client/Client.js | 12 +++++++----- src/structures/MessageButton.js | 2 +- src/structures/MessageSelectMenu.js | 2 +- src/util/Constants.js | 29 ++++++++++++++++++----------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index 8a3a443..796896c 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -32,7 +32,7 @@ const StickerPack = require('../structures/StickerPack'); const VoiceRegion = require('../structures/VoiceRegion'); const Webhook = require('../structures/Webhook'); const Widget = require('../structures/Widget'); -const { Events, InviteScopes, Status } = require('../util/Constants'); +const { Events, InviteScopes, Status, captchaServices } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); const Intents = require('../util/Intents'); const Options = require('../util/Options'); @@ -992,7 +992,6 @@ class Client extends BaseClient { * @private */ _validateOptions(options = this.options) { - const captchaService = ['2captcha']; if (typeof options.intents === 'undefined') { throw new TypeError('CLIENT_MISSING_INTENTS'); } else { @@ -1010,10 +1009,10 @@ class Client extends BaseClient { if (options && typeof options.autoRedeemNitro !== 'boolean') { throw new TypeError('CLIENT_INVALID_OPTION', 'autoRedeemNitro', 'a boolean'); } - if (options && options.captchaService && !captchaService.includes(options.captchaService)) { - throw new TypeError('CLIENT_INVALID_OPTION', 'captchaService', captchaService.join(', ')); + if (options && options.captchaService && !captchaServices.includes(options.captchaService)) { + throw new TypeError('CLIENT_INVALID_OPTION', 'captchaService', captchaServices.join(', ')); } - if (options && captchaService.includes(options.captchaService) && typeof options.captchaKey !== 'string') { + if (options && captchaServices.includes(options.captchaService) && typeof options.captchaKey !== 'string') { throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a string'); } if (options && typeof options.DMSync !== 'boolean') { @@ -1025,6 +1024,9 @@ class Client extends BaseClient { if (options && options.password && typeof options.password !== 'string') { throw new TypeError('CLIENT_INVALID_OPTION', 'password', 'a string'); } + if (options && options.interactionTimeout && typeof options.interactionTimeout !== 'number') { + throw new TypeError('CLIENT_INVALID_OPTION', 'interactionTimeout', 'a number'); + } if (options && typeof options.proxy !== 'string') { throw new TypeError('CLIENT_INVALID_OPTION', 'proxy', 'a string'); } diff --git a/src/structures/MessageButton.js b/src/structures/MessageButton.js index 325a33c..8033ffa 100644 --- a/src/structures/MessageButton.js +++ b/src/structures/MessageButton.js @@ -217,7 +217,7 @@ class MessageButton extends BaseMessageComponent { message.client.removeListener('interactionResponse', handler); message.client.decrementMaxListeners(); reject(new Error('INTERACTION_TIMEOUT')); - }, 15_000).unref(); + }, message.client.options.interactionTimeout).unref(); message.client.incrementMaxListeners(); message.client.on('interactionResponse', handler); }); diff --git a/src/structures/MessageSelectMenu.js b/src/structures/MessageSelectMenu.js index ea3e851..55ab28e 100644 --- a/src/structures/MessageSelectMenu.js +++ b/src/structures/MessageSelectMenu.js @@ -396,7 +396,7 @@ class MessageSelectMenu extends BaseMessageComponent { message.client.removeListener('interactionResponse', handler); message.client.decrementMaxListeners(); reject(new Error('INTERACTION_TIMEOUT')); - }, 15_000).unref(); + }, message.client.options.interactionTimeout).unref(); message.client.incrementMaxListeners(); message.client.on('interactionResponse', handler); }); diff --git a/src/util/Constants.js b/src/util/Constants.js index e3519b8..8083f97 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -9,15 +9,15 @@ const listUserAgent = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13.0; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (X11; Linux i686; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0', - 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13.0; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (X11; Linux i686; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0', + 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13.0; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (X11; Linux i686; rv:102.0) Gecko/20100101 Firefox/102.0', @@ -25,11 +25,18 @@ const listUserAgent = [ 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0', 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52', ]; +/** + * API captcha solver + * * `2captcha` - 2captcha.com + * @typedef {string[]} captchaServices + */ +exports.captchaServices = ['2captcha']; + /** * Automatically scan and delete direct messages you receive that contain explicit media content. * * `NOT_SCAN` - Direct messages will not be scanned for explicit content.