From 0386b5b1d760485f5186dccce6573c9762dd1ab9 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:14:25 +0700 Subject: [PATCH] feat: remove shards --- src/client/Client.js | 49 +------------------------- src/client/websocket/WebSocketShard.js | 2 +- src/util/Options.js | 1 + 3 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index e1239f8..876ecfb 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -8,7 +8,7 @@ const BaseClient = require('./BaseClient'); const ActionsManager = require('./actions/ActionsManager'); const ClientVoiceManager = require('./voice/ClientVoiceManager'); const WebSocketManager = require('./websocket/WebSocketManager'); -const { Error, TypeError, RangeError } = require('../errors'); +const { Error, TypeError } = require('../errors'); const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager'); const BillingManager = require('../managers/BillingManager'); const ChannelManager = require('../managers/ChannelManager'); @@ -31,8 +31,6 @@ const Webhook = require('../structures/Webhook'); const Widget = require('../structures/Widget'); const { Events, Status } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); -const Intents = require('../util/Intents'); -const Options = require('../util/Options'); const Permissions = require('../util/Permissions'); const DiscordAuthWebsocket = require('../util/RemoteAuth'); const Sweepers = require('../util/Sweepers'); @@ -48,39 +46,6 @@ class Client extends BaseClient { constructor(options) { super(options); - const data = require('node:worker_threads').workerData ?? process.env; - const defaults = Options.createDefault(); - - if (this.options.shards === defaults.shards) { - if ('SHARDS' in data) { - this.options.shards = JSON.parse(data.SHARDS); - } - } - - if (this.options.shardCount === defaults.shardCount) { - if ('SHARD_COUNT' in data) { - this.options.shardCount = Number(data.SHARD_COUNT); - } else if (Array.isArray(this.options.shards)) { - this.options.shardCount = this.options.shards.length; - } - } - - const typeofShards = typeof this.options.shards; - - if (typeofShards === 'undefined' && typeof this.options.shardCount === 'number') { - this.options.shards = Array.from({ length: this.options.shardCount }, (_, i) => i); - } - - if (typeofShards === 'number') this.options.shards = [this.options.shards]; - - if (Array.isArray(this.options.shards)) { - this.options.shards = [ - ...new Set( - this.options.shards.filter(item => !isNaN(item) && item >= 0 && item < Infinity && item === (item | 0)), - ), - ]; - } - this._validateOptions(); /** @@ -647,18 +612,6 @@ class Client extends BaseClient { * @private */ _validateOptions(options = this.options) { - if (typeof options.intents === 'undefined') { - throw new TypeError('CLIENT_MISSING_INTENTS'); - } else { - options.intents = Intents.resolve(options.intents); - } - if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount !== 1) { - throw new TypeError('CLIENT_INVALID_OPTION', 'shardCount', 'a number equal to 1'); - } - if (options.shards && !(options.shards === 'auto' || Array.isArray(options.shards))) { - throw new TypeError('CLIENT_INVALID_OPTION', 'shards', "'auto', a number or array of numbers"); - } - if (options.shards && !options.shards.length) throw new RangeError('CLIENT_INVALID_PROVIDED_SHARDS'); if (typeof options.makeCache !== 'function') { throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function'); } diff --git a/src/client/websocket/WebSocketShard.js b/src/client/websocket/WebSocketShard.js index 27fb046..9d589aa 100644 --- a/src/client/websocket/WebSocketShard.js +++ b/src/client/websocket/WebSocketShard.js @@ -718,7 +718,7 @@ class WebSocketShard extends EventEmitter { delete d.version; delete d.agent; - this.debug(`[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${d.intents}`); + this.debug(`[IDENTIFY] Shard ${this.id}`); this.send({ op: Opcodes.IDENTIFY, d }, true); } diff --git a/src/util/Options.js b/src/util/Options.js index 13c940b..984ba77 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -159,6 +159,7 @@ class Options extends null { closeTimeout: 5_000, waitGuildTimeout: 15_000, shardCount: 1, + shards: [0], makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings), messageCacheLifetime: 0, messageSweepInterval: 0,