This commit is contained in:
Snowflake107 2021-06-25 15:55:03 +05:45
parent 4990252701
commit 574c163f5b
3 changed files with 31 additions and 22 deletions

View file

@ -69,28 +69,29 @@ class Player extends EventEmitter<PlayerEvents> {
const queue = this.getQueue(oldState.guild.id); const queue = this.getQueue(oldState.guild.id);
if (!queue) return; if (!queue) return;
// @todo
// update channel // update channel
if (oldState.channelID && newState.channelID && oldState.channelID !== newState.channelID) { // if (oldState.channelID && newState.channelID && oldState.channelID !== newState.channelID) {
queue.connection.channel = newState.channel; // queue.connection.channel = newState.channel;
} // }
if (!oldState.channelID && newState.channelID && newState.member.id === newState.guild.me.id) { // if (!oldState.channelID && newState.channelID && newState.member.id === newState.guild.me.id) {
if (newState.serverMute || !newState.serverMute) { // if (newState.serverMute || !newState.serverMute) {
queue.setPaused(newState.serverMute); // queue.setPaused(newState.serverMute);
} else if (newState.suppress || !newState.suppress) { // } else if (newState.suppress || !newState.suppress) {
if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); // if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop);
queue.setPaused(newState.suppress); // queue.setPaused(newState.suppress);
} // }
} // }
if (oldState.channelID === newState.channelID && oldState.member.id === newState.guild.me.id) { // if (oldState.channelID === newState.channelID && oldState.member.id === newState.guild.me.id) {
if (oldState.serverMute !== newState.serverMute) { // if (oldState.serverMute !== newState.serverMute) {
queue.setPaused(newState.serverMute); // queue.setPaused(newState.serverMute);
} else if (oldState.suppress !== newState.suppress) { // } else if (oldState.suppress !== newState.suppress) {
if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); // if (newState.suppress) newState.guild.me.voice.setRequestToSpeak(true).catch(Util.noop);
queue.setPaused(newState.suppress); // queue.setPaused(newState.suppress);
} // }
} // }
if (oldState.member.id === this.client.user.id && !newState.channelID) { if (oldState.member.id === this.client.user.id && !newState.channelID) {
queue.destroy(); queue.destroy();

View file

@ -288,6 +288,14 @@ class Queue<T = unknown> {
this.setVolume(amount); this.setVolume(amount);
} }
/**
* Mutes the playback
* @returns {void}
*/
mute() {
this.volume = 0;
}
/** /**
* The stream time of this queue * The stream time of this queue
* @type {number} * @type {number}

View file

@ -96,13 +96,13 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
}); });
this.audioPlayer.on("stateChange", (oldState, newState) => { 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) { if (!this.paused) {
void this.emit("finish", this.audioResource); void this.emit("finish", this.audioResource);
this.audioResource = null; this.audioResource = null;
} }
} else if (newState.status === AudioPlayerStatus.Playing) {
if (!this.paused) void this.emit("start", this.audioResource);
} }
}); });