UNPKG

larakazagumo

Version:

A shoukaku wrapper with built-in queue support.

56 lines (55 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KazagumoPlugin = void 0; const Index_1 = require("../Index"); const Interfaces_1 = require("../Modules/Interfaces"); class KazagumoPlugin extends Interfaces_1.KazagumoPlugin { /** * Initialize the plugin. * @param client Discord.Client */ constructor(client) { super(); this.client = client; /** * Kazagumo instance. */ this.kazagumo = null; } /** * Load the plugin. * @param kazagumo Kazagumo */ load(kazagumo) { this.kazagumo = kazagumo; this.client.on('voiceStateUpdate', this.onVoiceStateUpdate.bind(this)); } /** * Unload the plugin. */ unload() { this.client.removeListener('voiceStateUpdate', this.onVoiceStateUpdate.bind(this)); this.kazagumo = null; } onVoiceStateUpdate(oldState, newState) { if (!this.kazagumo || oldState.id !== this.client.user.id) return; const newChannelId = newState.channelID || newState.channelId; const oldChannelId = oldState.channelID || oldState.channelId; const guildId = newState.guild.id; const player = this.kazagumo.players.get(guildId); if (!player) return; let state = 'UNKNOWN'; if (!oldChannelId && newChannelId) state = 'JOINED'; else if (oldChannelId && !newChannelId) state = 'LEFT'; else if (oldChannelId && newChannelId && oldChannelId !== newChannelId) state = 'MOVED'; if (state === 'UNKNOWN') return; this.kazagumo.emit(Index_1.Events.PlayerMoved, player, state, { oldChannelId, newChannelId }); } } exports.KazagumoPlugin = KazagumoPlugin;