2020-06-02 16:11:12 +05:00
|
|
|
const Discord = require('discord.js')
|
|
|
|
const { EventEmitter } = require('events')
|
|
|
|
const Track = require('./Track')
|
2020-01-12 00:01:18 +05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a guild queue.
|
|
|
|
*/
|
|
|
|
class Queue extends EventEmitter {
|
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* @param {Discord.Snowflake} guildID ID of the guild this queue is for.
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
constructor (guildID) {
|
|
|
|
super()
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* ID of the guild this queue is for.
|
|
|
|
* @type {Discord.Snowflake}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.guildID = guildID
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* The voice connection of this queue.
|
|
|
|
* @type {Discord.VoiceConnection}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.voiceConnection = null
|
|
|
|
/**
|
|
|
|
* The song currently played.
|
|
|
|
* @type {Track}
|
|
|
|
*/
|
|
|
|
this.playing = null
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* The tracks of this queue. The first one is currenlty playing and the others are going to be played.
|
|
|
|
* @type {Track[]}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.tracks = []
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
|
|
|
* Whether the stream is currently stopped.
|
2020-06-02 16:11:12 +05:00
|
|
|
* @type {boolean}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.stopped = false
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* Whether the last track was skipped.
|
|
|
|
* @type {boolean}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.lastSkipped = false
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* The stream volume of this queue. (0-100)
|
|
|
|
* @type {number}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.volume = 100
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-21 18:36:16 +05:00
|
|
|
* Whether the stream is currently paused.
|
2020-06-02 16:11:12 +05:00
|
|
|
* @type {boolean}
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.paused = true
|
2020-01-18 15:03:22 +05:00
|
|
|
/**
|
|
|
|
* Whether the repeat mode is enabled.
|
2020-06-02 16:11:12 +05:00
|
|
|
* @type {boolean}
|
2020-01-18 15:03:22 +05:00
|
|
|
*/
|
2020-06-21 18:36:16 +05:00
|
|
|
this.repeatMode = false
|
|
|
|
/**
|
|
|
|
* Filters status
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
this.filters = {}
|
2020-01-12 00:01:18 +05:00
|
|
|
}
|
2020-06-24 20:48:25 +05:00
|
|
|
|
|
|
|
get calculatedVolume () {
|
|
|
|
return this.filters.bassboost ? this.volume + 40 : this.volume
|
|
|
|
}
|
2020-06-21 18:36:16 +05:00
|
|
|
}
|
2020-01-12 00:01:18 +05:00
|
|
|
|
2020-06-21 18:36:16 +05:00
|
|
|
module.exports = Queue
|
2020-06-02 16:11:12 +05:00
|
|
|
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
|
|
|
* Emitted when the queue is empty.
|
|
|
|
* @event Queue#end
|
2020-06-22 00:06:54 +05:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* client.on('message', (message) => {
|
|
|
|
*
|
|
|
|
* const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
|
|
|
|
* const command = args.shift().toLowerCase();
|
|
|
|
*
|
|
|
|
* if(command === 'play'){
|
|
|
|
*
|
|
|
|
* let track = await client.player.play(message.member.voice.channel, args[0]);
|
|
|
|
*
|
|
|
|
* track.queue.on('end', () => {
|
|
|
|
* message.channel.send('The queue is empty, please add new tracks!');
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* });
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|
|
|
|
|
2020-01-12 22:55:56 +05:00
|
|
|
/**
|
|
|
|
* Emitted when the voice channel is empty.
|
|
|
|
* @event Queue#channelEmpty
|
|
|
|
*/
|
|
|
|
|
2020-01-12 00:01:18 +05:00
|
|
|
/**
|
2020-06-02 16:11:12 +05:00
|
|
|
* Emitted when the track changes.
|
|
|
|
* @event Queue#trackChanged
|
|
|
|
* @param {Track} oldTrack The old track (playing before)
|
|
|
|
* @param {Track} newTrack The new track (currently playing)
|
2020-01-12 00:01:18 +05:00
|
|
|
* @param {Boolean} skipped Whether the change is due to the skip() function
|
2020-06-22 00:06:54 +05:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* client.on('message', (message) => {
|
|
|
|
*
|
|
|
|
* const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
|
|
|
|
* const command = args.shift().toLowerCase();
|
|
|
|
*
|
|
|
|
* if(command === 'play'){
|
|
|
|
*
|
|
|
|
* let track = await client.player.play(message.member.voice.channel, args[0]);
|
|
|
|
*
|
|
|
|
* track.queue.on('trackChanged', (oldTrack, newTrack, skipped, repeatMode) => {
|
|
|
|
* if(repeatMode){
|
|
|
|
* message.channel.send(`Playing ${newTrack} again...`);
|
|
|
|
* } else {
|
|
|
|
* message.channel.send(`Now playing ${newTrack}...`);
|
|
|
|
* }
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* });
|
2020-01-12 00:01:18 +05:00
|
|
|
*/
|