discord-player-play-dl/src/Queue.js

98 lines
2.6 KiB
JavaScript
Raw Normal View History

const Discord = require('discord.js')
const { EventEmitter } = require('events')
const Track = require('./Track')
2020-08-13 18:21:42 +05:00
const Player = require('./Player')
2020-08-14 02:07:54 +05:00
const { Stream } = require('stream')
2020-01-12 00:01:18 +05:00
/**
* Represents a guild queue.
*/
class Queue extends EventEmitter {
/**
* @param {Discord.Snowflake} guildID ID of the guild this queue is for.
2020-08-13 18:21:42 +05:00
* @param {Discord.Message} message Message that initialized the queue
2020-11-01 20:38:29 +05:00
* @param {Filters} filters Filters the queue should be initialized with.
2020-01-12 00:01:18 +05:00
*/
2020-08-13 18:21:42 +05:00
constructor (guildID, message, filters) {
super()
2020-01-12 00:01:18 +05:00
/**
* ID of the guild this queue is for.
* @type {Discord.Snowflake}
2020-01-12 00:01:18 +05:00
*/
this.guildID = guildID
2020-01-12 00:01:18 +05:00
/**
* The voice connection of this queue.
* @type {Discord.VoiceConnection}
2020-01-12 00:01:18 +05:00
*/
this.voiceConnection = null
2020-01-12 00:01:18 +05:00
/**
2020-08-14 02:07:54 +05:00
* The ytdl stream.
* @type {any}
*/
this.stream = null
/**
* 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
*/
this.tracks = []
2020-01-12 00:01:18 +05:00
/**
* Whether the stream is currently stopped.
* @type {boolean}
2020-01-12 00:01:18 +05:00
*/
this.stopped = false
2020-01-12 00:01:18 +05:00
/**
* Whether the last track was skipped.
* @type {boolean}
2020-01-12 00:01:18 +05:00
*/
this.lastSkipped = false
2020-01-12 00:01:18 +05:00
/**
* The stream volume of this queue. (0-100)
* @type {number}
2020-01-12 00:01:18 +05:00
*/
this.volume = 100
2020-01-12 00:01:18 +05:00
/**
* Whether the stream is currently paused.
* @type {boolean}
2020-01-12 00:01:18 +05:00
*/
2020-11-01 20:19:41 +05:00
this.paused = this.voiceConnection && this.voiceConnection.dispatcher && this.voiceConnection.dispatcher.paused
2020-01-18 15:03:22 +05:00
/**
* Whether the repeat mode is enabled.
* @type {boolean}
*/
this.repeatMode = false
2020-12-27 04:02:23 +05:00
/**
* Whether the loop mode is enabled.
* @type {boolean}
*/
this.loopMode = false
/**
* Filters status
* @type {Filters}
*/
this.filters = {}
2020-08-13 18:21:42 +05:00
Object.keys(filters).forEach((f) => {
this.filters[f] = false
})
/**
* Additional stream time
* @type {Number}
2020-01-18 15:03:22 +05:00
*/
this.additionalStreamTime = 0
2020-08-13 18:21:42 +05:00
/**
* Message that initialized the queue
* @type {Discord.Message}
*/
this.firstMessage = message
}
get playing () {
return this.tracks[0]
2020-01-12 00:01:18 +05:00
}
get calculatedVolume () {
return this.filters.bassboost ? this.volume + 50 : this.volume
}
}
module.exports = Queue