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.OceanicManager = void 0; const Manager_1 = require("../structures/Manager"); const Enums_1 = require("../structures/Enums"); const MagmastreamError_1 = require("../structures/MagmastreamError"); const GUILD_VOICE_STATES_INTENT = 128; /** * Oceanic wrapper for Magmastream. */ class OceanicManager extends Manager_1.Manager { client; constructor(client, options) { super(options, true); this.client = client; const intents = this.client.shards.options.intents; const hasGuildVoiceStates = typeof intents === "number" ? (intents & GUILD_VOICE_STATES_INTENT) === GUILD_VOICE_STATES_INTENT : intents.includes("GUILD_VOICE_STATES"); if (!hasGuildVoiceStates) { throw new MagmastreamError_1.MagmaStreamError({ code: Enums_1.MagmaStreamErrorCode.INTENT_MISSING, message: "[Custom Wrapper] Your Oceanic client must have the GUILD_VOICE_STATES intent enabled.", }); } this.client.once("ready", () => { if (!this.options.clientId) this.options.clientId = this.client.user.id; }); this.client.on("packet", async (packet) => { await this.updateVoiceState(packet); }); } send(packet) { const guild = this.client.guilds.get(packet.d.guild_id); if (guild) guild.shard.send(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.OceanicManager = OceanicManager;