|
|
|
@ -25,6 +25,7 @@ exports.DJ = class {
|
|
|
|
|
this.volume = 0.5;
|
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
|
this.quality = 'lowest';
|
|
|
|
|
this.exitTimeout = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -41,7 +42,6 @@ exports.DJ = class {
|
|
|
|
|
let connection = await this.voiceChannel.join();
|
|
|
|
|
logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`);
|
|
|
|
|
this.conn = connection;
|
|
|
|
|
this.checkListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -67,6 +67,15 @@ exports.DJ = class {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the channel e.g. when the bot is moved to another channel.
|
|
|
|
|
* @param voiceChannel
|
|
|
|
|
*/
|
|
|
|
|
updateChannel(voiceChannel) {
|
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
|
logger.debug(`Updated voiceChannel to ${this.voiceChannel.name}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Plays a file for the given filename.
|
|
|
|
|
* TODO: Implement queue
|
|
|
|
@ -86,20 +95,22 @@ exports.DJ = class {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if there are still members listening and sets an exit timeout (5 min) before checking again
|
|
|
|
|
* and exiting when noone is listening. Once this function is executed, it calls itself every 10 seconds (stops when
|
|
|
|
|
* Checks if there are still members listening and sets an exit timeout (5 min)
|
|
|
|
|
* not connected).
|
|
|
|
|
*/
|
|
|
|
|
checkListeners() {
|
|
|
|
|
if (this.connected && this.conn.channel.members.size === 1) {
|
|
|
|
|
logger.verbose(`Set exit timout for ${this.voiceChannel.name}`);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (this.voiceChannel && this.voiceChannel.members.size === 1)
|
|
|
|
|
if (this.exitTimeout) {
|
|
|
|
|
clearTimeout(this.exitTimeout);
|
|
|
|
|
this.exitTimeout = null;
|
|
|
|
|
logger.debug(`Cleared exit timout for ${this.voiceChannel.name}`);
|
|
|
|
|
}
|
|
|
|
|
if (this.connected && this.voiceChannel.members.size === 1) {
|
|
|
|
|
logger.debug(`Set exit timout for ${this.voiceChannel.name}`);
|
|
|
|
|
this.exitTimeout = setTimeout(() => {
|
|
|
|
|
if (this.connected && this.voiceChannel.members.size === 1)
|
|
|
|
|
logger.verbose(`Exiting ${this.voiceChannel.name}`);
|
|
|
|
|
this.stop();
|
|
|
|
|
}, config.music.timeout || 300000);
|
|
|
|
|
} else if (this.connected) {
|
|
|
|
|
setTimeout(() => this.checkListeners(), 10000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -147,7 +158,7 @@ exports.DJ = class {
|
|
|
|
|
this.current = ({'url': url, 'title': await this.getVideoName(url)});
|
|
|
|
|
|
|
|
|
|
this.disp = this.conn.playStream(ytdl(url,
|
|
|
|
|
{filter: 'audioonly', quality: this.quality, liveBuffer: 40000}),
|
|
|
|
|
{filter: 'audioonly', quality: this.quality, liveBuffer: config.music.livePuffer || 20000}),
|
|
|
|
|
{volume: this.volume});
|
|
|
|
|
|
|
|
|
|
this.disp.on('end', (reason) => { // end event triggers the next song to play when the reason is not stop
|
|
|
|
|