@evolvejs/evolava
Version:
a lavalink client for evolvejs
57 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EvolavaClient = void 0;
const events_1 = require("events");
const objex_1 = require("@evolvejs/objex");
const EvoLavaNode_1 = require("./EvoLavaNode");
const EvoLavaPlayer_1 = require("./EvoLavaPlayer");
class EvolavaClient extends events_1.EventEmitter {
constructor(client, node) {
super();
this.client = client;
this.node = node;
this.nodes = new objex_1.Objex();
this.players = new objex_1.Objex();
if (!this.node)
client.logger.error("No nodes provided!");
for (const n of this.node) {
if (this.nodes.has(n.host))
return;
this.nodes.set(n.host, new EvoLavaNode_1.EvoLavaNode(this, n));
}
const connection = client.shardConnections.get(0);
connection === null || connection === void 0 ? void 0 : connection.gateway.voice.on("packetReady", (pk1, pk2) => this.handle(pk1, pk2));
}
spawn(options, queueOption) {
if (!options.guild)
throw new TypeError(`LavaClient#spawnPlayer() Could not resolve PlayerOptions.guild.`);
if (!options.voiceChannel)
throw new TypeError(`LavaClient#spawnPlayer() Could not resolve PlayerOptions.voiceChannel.`);
if (!options.textChannel)
throw new TypeError(`LavaClient#spawnPlayer() Could not resolve PlayerOptions.textChannel.`);
const oldPlayer = this.players.get(options.guild.id);
if (oldPlayer)
return oldPlayer;
return new EvoLavaPlayer_1.EvolavaPlayer(this, options, queueOption, this.nodes.get(this.node[0].host));
}
handle(pk1, pk2) {
const player = this.players.get(pk2.d.guild_id);
if (!player)
return;
const voiceState = {
op: "voiceUpdate",
sessionId: pk1.sessionID,
guildId: pk1.guild.id,
event: pk2.d
};
const { op, guildId, sessionId, event } = voiceState;
if (op && guildId && sessionId && event) {
player.node.wsSend(voiceState).catch((err) => {
if (err)
throw new Error(err);
});
}
}
}
exports.EvolavaClient = EvolavaClient;
//# sourceMappingURL=EvolavaClient.js.map