UNPKG

magmastream

Version:

A user-friendly Lavalink client designed for NodeJS.

77 lines (76 loc) 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiscordenoManager = 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; const VOICE_STATE_UPDATE_OPCODE = 4; /** * Discordeno wrapper for Magmastream. */ class DiscordenoManager extends Manager_1.Manager { client; constructor(client, options) { super(options, true); this.client = client; // Ensure GuildVoiceStates intent is enabled const intents = this.client.gateway.intents; if (!(intents & GUILD_VOICE_STATES_INTENT)) { throw new MagmastreamError_1.MagmaStreamError({ code: Enums_1.MagmaStreamErrorCode.INTENT_MISSING, message: "[Custom Wrapper] Your Discordeno client must have the GuildVoiceStates intent enabled.", }); } // Chain READY event const oldReady = this.client.handlers.READY; this.client.handlers.READY = (bot, payload, shardId) => { if (oldReady) oldReady(bot, payload, shardId); if (!this.options?.clientId) this.options.clientId = this.client.applicationId.toString(); }; // Chain VOICE_STATE_UPDATE event const oldVoiceState = this.client.handlers.VOICE_STATE_UPDATE; this.client.handlers.VOICE_STATE_UPDATE = (bot, payload, shardId) => { if (oldVoiceState) oldVoiceState(bot, payload, shardId); this.updateVoiceState(payload); }; // Chain VOICE_SERVER_UPDATE event const oldVoiceServer = this.client.handlers.VOICE_SERVER_UPDATE; this.client.handlers.VOICE_SERVER_UPDATE = (bot, payload, shardId) => { if (oldVoiceServer) oldVoiceServer(bot, payload, shardId); this.updateVoiceState(payload); }; } // Send voice state updates to the guild shard send(packet) { this.client.gateway.sendPayload(this.client.gateway.calculateShardId(packet.d.guild_id), { op: VOICE_STATE_UPDATE_OPCODE, d: packet.d, }); } /** * Resolve a user by ID or partial info. * Uses user-provided cache getter if available, otherwise falls back to minimal info. */ async resolveUser(user) { const id = typeof user === "string" ? user : String(user.id); // Try user-provided cache getter const cached = this.getUserFromCache(id); if (cached) return cached; // Fallback: return minimal info return { id, username: typeof user === "string" ? undefined : user.username, }; } resolveGuild(guildId) { // Try user-provided cache getter return this.getGuildFromCache(guildId); } } exports.DiscordenoManager = DiscordenoManager;