2021-06-11 15:32:22 +05:00
|
|
|
import { Client, Collection, Guild, Snowflake } from "discord.js";
|
|
|
|
import { TypedEmitter as EventEmitter } from "tiny-typed-emitter";
|
|
|
|
import { Queue } from "./Structures/Queue";
|
2021-06-11 16:50:43 +05:00
|
|
|
import { VoiceUtils } from "./VoiceInterface/VoiceUtils";
|
2021-06-11 15:32:22 +05:00
|
|
|
import { PlayerOptions } from "./types/types";
|
|
|
|
|
|
|
|
class DiscordPlayer extends EventEmitter {
|
|
|
|
public readonly client: Client;
|
|
|
|
public readonly queues = new Collection<Snowflake, Queue>();
|
2021-06-11 16:50:43 +05:00
|
|
|
public readonly voiceUtils = new VoiceUtils();
|
2021-06-11 15:32:22 +05:00
|
|
|
|
|
|
|
constructor(client: Client) {
|
|
|
|
super();
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
createQueue(guild: Guild, queueInitOptions?: PlayerOptions) {
|
|
|
|
if (this.queues.has(guild.id)) return this.queues.get(guild.id);
|
|
|
|
const queue = new Queue(this, guild, queueInitOptions);
|
|
|
|
this.queues.set(guild.id, queue);
|
|
|
|
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
getQueue(guild: Snowflake) {
|
|
|
|
return this.queues.get(guild);
|
|
|
|
}
|
2021-06-11 19:57:49 +05:00
|
|
|
|
|
|
|
*[Symbol.iterator]() {
|
|
|
|
yield* Array.from(this.queues.values());
|
|
|
|
}
|
2021-06-11 15:32:22 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
export { DiscordPlayer as Player };
|