From 574c163f5b4a5710f775fbcfbfa02b8e636809d4 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Fri, 25 Jun 2021 15:55:03 +0545 Subject: [PATCH] events --- src/Player.ts | 39 +++++++++++++------------- src/Structures/Queue.ts | 8 ++++++ src/VoiceInterface/StreamDispatcher.ts | 6 ++-- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 1f1b10e..1a718eb 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -69,28 +69,29 @@ class Player extends EventEmitter { const queue = this.getQueue(oldState.guild.id); if (!queue) return; + // @todo // update channel - if (oldState.channelID && newState.channelID && oldState.channelID !== newState.channelID) { - queue.connection.channel = newState.channel; - } + // if (oldState.channelID && newState.channelID && oldState.channelID !== newState.channelID) { + // queue.connection.channel = newState.channel; + // } - if (!oldState.channelID && newState.channelID && newState.member.id === newState.guild.me.id) { - if (newState.serverMute || !newState.serverMute) { - queue.setPaused(newState.serverMute); - } else if (newState.suppress || !newState.suppress) { - if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); - queue.setPaused(newState.suppress); - } - } + // if (!oldState.channelID && newState.channelID && newState.member.id === newState.guild.me.id) { + // if (newState.serverMute || !newState.serverMute) { + // queue.setPaused(newState.serverMute); + // } else if (newState.suppress || !newState.suppress) { + // if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); + // queue.setPaused(newState.suppress); + // } + // } - if (oldState.channelID === newState.channelID && oldState.member.id === newState.guild.me.id) { - if (oldState.serverMute !== newState.serverMute) { - queue.setPaused(newState.serverMute); - } else if (oldState.suppress !== newState.suppress) { - if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); - queue.setPaused(newState.suppress); - } - } + // if (oldState.channelID === newState.channelID && oldState.member.id === newState.guild.me.id) { + // if (oldState.serverMute !== newState.serverMute) { + // queue.setPaused(newState.serverMute); + // } else if (oldState.suppress !== newState.suppress) { + // if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); + // queue.setPaused(newState.suppress); + // } + // } if (oldState.member.id === this.client.user.id && !newState.channelID) { queue.destroy(); diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index 1bae87d..7e356d4 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -288,6 +288,14 @@ class Queue { this.setVolume(amount); } + /** + * Mutes the playback + * @returns {void} + */ + mute() { + this.volume = 0; + } + /** * The stream time of this queue * @type {number} diff --git a/src/VoiceInterface/StreamDispatcher.ts b/src/VoiceInterface/StreamDispatcher.ts index e89619f..311d40a 100644 --- a/src/VoiceInterface/StreamDispatcher.ts +++ b/src/VoiceInterface/StreamDispatcher.ts @@ -96,13 +96,13 @@ class StreamDispatcher extends EventEmitter { }); this.audioPlayer.on("stateChange", (oldState, newState) => { - if (newState.status === AudioPlayerStatus.Idle && oldState.status !== AudioPlayerStatus.Idle) { + if (newState.status === AudioPlayerStatus.Playing) { + if (!this.paused) return void this.emit("start", this.audioResource); + } else if (newState.status === AudioPlayerStatus.Idle && oldState.status !== AudioPlayerStatus.Idle) { if (!this.paused) { void this.emit("finish", this.audioResource); this.audioResource = null; } - } else if (newState.status === AudioPlayerStatus.Playing) { - if (!this.paused) void this.emit("start", this.audioResource); } });