feat: remove shards
This commit is contained in:
		@@ -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');
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user