UNPKG

magmastream

Version:

A user-friendly Lavalink client designed for NodeJS.

55 lines (54 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErisManager = void 0; const v10_1 = require("discord-api-types/v10"); const Manager_1 = require("../structures/Manager"); const Enums_1 = require("../structures/Enums"); const MagmastreamError_1 = require("../structures/MagmastreamError"); /** * Eris wrapper for Magmastream. */ class ErisManager extends Manager_1.Manager { client; constructor(client, options) { super(options, true); this.client = client; const intents = this.client.options.intents; const hasGuildVoiceStates = typeof intents === "number" ? (intents & v10_1.GatewayIntentBits.GuildVoiceStates) === v10_1.GatewayIntentBits.GuildVoiceStates : intents.includes("guildVoiceStates"); if (!hasGuildVoiceStates) { throw new MagmastreamError_1.MagmaStreamError({ code: Enums_1.MagmaStreamErrorCode.INTENT_MISSING, message: "[Custom Wrapper] Your Eris client must have the guildVoiceStates intent enabled.", }); } this.client.once("ready", () => { if (!this.options.clientId) this.options.clientId = client.user.id; }); this.client.on("rawWS", async (packet) => { await this.updateVoiceState(packet); }); } send(packet) { const guild = this.client.guilds.get(packet.d.guild_id); if (guild) guild.shard.sendWS(packet.op, packet.d); } async resolveUser(user) { const id = typeof user === "string" ? user : String(user.id); const cached = this.client.users.get(id); if (cached) return cached; return { id, username: typeof user === "string" ? undefined : user.username, }; } resolveGuild(guildId) { const cached = this.client.guilds.get(guildId); if (cached) return cached; return null; } } exports.ErisManager = ErisManager;