UNPKG

magmastream

Version:

A user-friendly Lavalink client designed for NodeJS.

81 lines (80 loc) 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CloudstormManager = 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; function hasCloudstormGuildVoiceStates(intents) { if (typeof intents === "number") { return (intents & GUILD_VOICE_STATES_INTENT) === GUILD_VOICE_STATES_INTENT; } if (typeof intents === "string") { return intents === "GUILD_VOICE_STATES"; } if (Array.isArray(intents)) { return intents.some((intent) => (typeof intent === "number" ? (intent & GUILD_VOICE_STATES_INTENT) === GUILD_VOICE_STATES_INTENT : intent === "GUILD_VOICE_STATES")); } return false; } /** * Cloudstorm wrapper for Magmastream. * * @note Unlike other wrappers, CloudStorm is a gateway-only library with no cache. * You must manually call `manager.init({ clientId: "your-bot-id" })` inside your `ready` event. * * @example * ```typescript * const client = new Client("token", { intents: ["GUILDS", "GUILD_VOICE_STATES"] }); * const manager = new CloudstormManager(client, options); * * client.once("ready", async () => { * await manager.init({ clientId: "your-bot-id" }); * }); * ``` */ class CloudstormManager extends Manager_1.Manager { client; constructor(client, options) { super(options, true); this.client = client; // Ensure GUILD_VOICE_STATES intent is enabled if (!hasCloudstormGuildVoiceStates(client.options.intents)) { throw new MagmastreamError_1.MagmaStreamError({ code: Enums_1.MagmaStreamErrorCode.INTENT_MISSING, message: "[CloudstormManager] Your Cloudstorm client must have the GUILD_VOICE_STATES intent enabled.", }); } // Chain incoming gateway events into updateVoiceState client.on("event", async (data) => { if (data.t === "VOICE_STATE_UPDATE" || data.t === "VOICE_SERVER_UPDATE") { await this.updateVoiceState(data); } }); } send(packet) { const totalShards = this.client.options.totalShards; if (!totalShards) return; const shardId = Number((BigInt(packet.d.guild_id) >> BigInt(22)) % BigInt(totalShards)); const shard = this.client.shardManager.shards[shardId]; if (shard) shard.connector.sendMessage(packet); } // CloudStorm has no user/guild cache — return minimal portable info only. async resolveUser(user) { const id = typeof user === "string" ? user : String(user.id); const cached = this.getUserFromCache(id); if (cached) return cached; return { id, username: typeof user === "string" ? undefined : user.username, }; } resolveGuild(guildId) { // Try user-provided cache getter return this.getGuildFromCache(guildId); } } exports.CloudstormManager = CloudstormManager;