UNPKG

damonjs

Version:

A modified Shoukaku wrapper with enhanced queue support.

56 lines (55 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DamonJsPlugin = void 0; const Index_1 = require("../../Index"); const Interfaces_1 = require("../Modules/Interfaces"); class DamonJsPlugin extends Interfaces_1.DamonJsPlugin { /** * Initialize the plugin. * @param client Discord.Client */ constructor(client) { super(); this.client = client; /** * DamonJs instance. */ this.damonjs = null; } /** * Load the plugin. * @param damonjs DamonJs */ load(damonjs) { this.damonjs = damonjs; this.client.on('voiceStateUpdate', this.onVoiceStateUpdate.bind(this)); } /** * Unload the plugin. */ unload() { this.client.removeListener('voiceStateUpdate', this.onVoiceStateUpdate.bind(this)); this.damonjs = null; } onVoiceStateUpdate(oldState, newState) { if (!this.damonjs || 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.damonjs.players.get(guildId); if (!player) return; let state = Interfaces_1.PlayerMovedState.Unknown; if (!oldChannelId && newChannelId) state = Interfaces_1.PlayerMovedState.Joined; else if (oldChannelId && !newChannelId) state = Interfaces_1.PlayerMovedState.Left; else if (oldChannelId && newChannelId && oldChannelId !== newChannelId) state = Interfaces_1.PlayerMovedState.Moved; if (state === Interfaces_1.PlayerMovedState.Unknown) return; this.damonjs.emit(Index_1.Events.PlayerMoved, player, state, { oldChannelId, newChannelId }); } } exports.DamonJsPlugin = DamonJsPlugin;