Merge pull request #852 from EwoX07/patch-3

fix(Player): voice states
This commit is contained in:
and 2021-11-05 11:14:42 +05:45 committed by GitHub
commit f3a101e894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,9 +76,18 @@ 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;
if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId && newState.member.id === newState.guild.me.id) { if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId) {
if (queue?.connection) queue.connection.channel = newState.channel; if (queue?.connection && newState.member.id === newState.guild.me.id) queue.connection.channel = newState.channel;
} if (newState.member.id === newState.guild.me.id || newState.member.id !== newState.guild.me.id && oldState.channelId === queue.connection.channel.id) {
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
const timeout = setTimeout(() => {
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
if (!this.queues.has(queue.guild.id)) return;
if (queue.options.leaveOnEmpty) queue.destroy();
this.emit("channelEmpty", queue);
}, queue.options.leaveOnEmptyCooldown || 0).unref();
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
}
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) {
@ -109,19 +118,23 @@ class Player extends EventEmitter<PlayerEvents> {
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`); const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel); const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
if (!channelEmpty && emptyTimeout) { if (newState.channelId === queue.connection.channel.id) {
clearTimeout(emptyTimeout); if (!channelEmpty && emptyTimeout) {
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`); clearTimeout(emptyTimeout);
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
}
} }
} else { } else {
if (!Util.isVoiceEmpty(queue.connection.channel)) return; if (oldState.channelId === queue.connection.channel.id) {
const timeout = setTimeout(() => {
if (!Util.isVoiceEmpty(queue.connection.channel)) return; if (!Util.isVoiceEmpty(queue.connection.channel)) return;
if (!this.queues.has(queue.guild.id)) return; const timeout = setTimeout(() => {
if (queue.options.leaveOnEmpty) queue.destroy(); if (!Util.isVoiceEmpty(queue.connection.channel)) return;
this.emit("channelEmpty", queue); if (!this.queues.has(queue.guild.id)) return;
}, queue.options.leaveOnEmptyCooldown || 0).unref(); if (queue.options.leaveOnEmpty) queue.destroy();
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout); this.emit("channelEmpty", queue);
}, queue.options.leaveOnEmptyCooldown || 0).unref();
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
}
} }
} }