|
|
@ -25,6 +25,7 @@ exports.DJ = class {
|
|
|
|
this.volume = 0.5;
|
|
|
|
this.volume = 0.5;
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
this.voiceChannel = voiceChannel;
|
|
|
|
this.quality = 'lowest';
|
|
|
|
this.quality = 'lowest';
|
|
|
|
|
|
|
|
this.exitTimeout = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -41,7 +42,6 @@ exports.DJ = class {
|
|
|
|
let connection = await this.voiceChannel.join();
|
|
|
|
let connection = await this.voiceChannel.join();
|
|
|
|
logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`);
|
|
|
|
logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`);
|
|
|
|
this.conn = connection;
|
|
|
|
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.
|
|
|
|
* Plays a file for the given filename.
|
|
|
|
* TODO: Implement queue
|
|
|
|
* 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
|
|
|
|
* Checks if there are still members listening and sets an exit timeout (5 min)
|
|
|
|
* and exiting when noone is listening. Once this function is executed, it calls itself every 10 seconds (stops when
|
|
|
|
|
|
|
|
* not connected).
|
|
|
|
* not connected).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
checkListeners() {
|
|
|
|
checkListeners() {
|
|
|
|
if (this.connected && this.conn.channel.members.size === 1) {
|
|
|
|
if (this.exitTimeout) {
|
|
|
|
logger.verbose(`Set exit timout for ${this.voiceChannel.name}`);
|
|
|
|
clearTimeout(this.exitTimeout);
|
|
|
|
setTimeout(() => {
|
|
|
|
this.exitTimeout = null;
|
|
|
|
if (this.voiceChannel && this.voiceChannel.members.size === 1)
|
|
|
|
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}`);
|
|
|
|
logger.verbose(`Exiting ${this.voiceChannel.name}`);
|
|
|
|
this.stop();
|
|
|
|
this.stop();
|
|
|
|
}, config.music.timeout || 300000);
|
|
|
|
}, 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.current = ({'url': url, 'title': await this.getVideoName(url)});
|
|
|
|
|
|
|
|
|
|
|
|
this.disp = this.conn.playStream(ytdl(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});
|
|
|
|
{volume: this.volume});
|
|
|
|
|
|
|
|
|
|
|
|
this.disp.on('end', (reason) => { // end event triggers the next song to play when the reason is not stop
|
|
|
|
this.disp.on('end', (reason) => { // end event triggers the next song to play when the reason is not stop
|
|
|
|