UNPKG

@evolvejs/core

Version:

An advanced Discord API wrapper with TS and JS support

52 lines (51 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShardManager = void 0; const objex_1 = require("@evolvejs/objex"); const util_1 = require("util"); const EventListener_1 = require("../../Utils/EventListener"); const Websocket_1 = require("./Websocket"); class ShardManager extends EventListener_1.EventListener { constructor(builder) { super(); this.connections = new objex_1.Objex(); Object.defineProperty(this, "builder", { value: builder, enumerable: false, writable: false, }); } spawnAll() { for (let i = 0; i < this.builder.shards; i++) { util_1.promisify(setTimeout)(5000).then(() => { const socket = new Websocket_1.EvolveSocket(this, i); this.connections.set(i, socket); }); } } destroy(id) { var _a; (_a = this.connections.get(id)) === null || _a === void 0 ? void 0 : _a.gateway.destroy(); } respawn(id) { var _a; (_a = this.connections.get(id)) === null || _a === void 0 ? void 0 : _a.gateway.reconnect(); } destroyAll(code = 0) { const initialLastShardConnection = this.connections.size - 1; for (const [k, v] of this.connections) { v.gateway.destroy(); if (k === initialLastShardConnection) { process.exit(code); } } } get ping() { return (this.connections.reduce((a, b) => a + b.shardPing) / this.connections.size); } getguildShardId(guildID) { return (Number(guildID) >> 22) % this.connections.size; } } exports.ShardManager = ShardManager;