fix: typings errors
This commit is contained in:
parent
62ca21baf0
commit
cb0fd060a1
2 changed files with 72 additions and 43 deletions
|
@ -78,7 +78,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
|
||||
if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId) {
|
||||
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 (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;
|
||||
|
@ -89,51 +89,52 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
||||
}
|
||||
|
||||
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.member.id === this.client.user.id && !newState.channelId) {
|
||||
queue.destroy();
|
||||
return void this.emit("botDisconnect", queue);
|
||||
}
|
||||
|
||||
if (!queue.connection || !queue.connection.channel) return;
|
||||
|
||||
if (!oldState.channelId || newState.channelId) {
|
||||
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
|
||||
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
|
||||
|
||||
if (newState.channelId === queue.connection.channel.id) {
|
||||
if (!channelEmpty && emptyTimeout) {
|
||||
clearTimeout(emptyTimeout);
|
||||
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (oldState.channelId === queue.connection.channel.id) {
|
||||
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||
const timeout = setTimeout(() => {
|
||||
|
||||
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();
|
||||
return void this.emit("botDisconnect", queue);
|
||||
}
|
||||
|
||||
if (!queue.connection || !queue.connection.channel) return;
|
||||
|
||||
if (!oldState.channelId || newState.channelId) {
|
||||
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
|
||||
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
|
||||
|
||||
if (newState.channelId === queue.connection.channel.id) {
|
||||
if (!channelEmpty && emptyTimeout) {
|
||||
clearTimeout(emptyTimeout);
|
||||
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (oldState.channelId === queue.connection.channel.id) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
28
src/types/EventEmitter.d.ts
vendored
Normal file
28
src/types/EventEmitter.d.ts
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
declare module "tiny-typed-emitter" {
|
||||
export type ListenerSignature<L> = {
|
||||
[E in keyof L]: (...args: any[]) => any;
|
||||
};
|
||||
|
||||
export type DefaultListener = {
|
||||
[k: string]: (...args: any[]) => any;
|
||||
};
|
||||
|
||||
export class TypedEmitter<L extends ListenerSignature<L> = DefaultListener> {
|
||||
static defaultMaxListeners: number;
|
||||
addListener<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
prependListener<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
prependOnceListener<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
removeListener<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
removeAllListeners(event?: keyof L): this;
|
||||
once<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
on<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
off<U extends keyof L>(event: U, listener: L[U]): this;
|
||||
emit<U extends keyof L>(event: U, ...args: Parameters<L[U]>): boolean;
|
||||
eventNames<U extends keyof L>(): U[];
|
||||
listenerCount(type: keyof L): number;
|
||||
listeners<U extends keyof L>(type: U): L[U][];
|
||||
rawListeners<U extends keyof L>(type: U): L[U][];
|
||||
getMaxListeners(): number;
|
||||
setMaxListeners(n: number): this;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue