eximiabots-radiox/struct/funcs/play.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-08 23:26:24 +00:00
module.exports = async function (guild, client, station) {
2020-03-02 19:38:42 +00:00
const radio = client.radio.get(guild.id);
2020-03-08 23:26:24 +00:00
let url = "";
2020-03-08 23:31:24 +00:00
if (isNaN(station)) {
2020-03-08 23:26:24 +00:00
radio.voiceChannel.leave();
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
}
2020-03-08 23:31:24 +00:00
if (station - 1 > client.stations.length - 1) {
2020-03-08 23:26:24 +00:00
radio.voiceChannel.leave();
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
}
2020-03-08 23:31:24 +00:00
url = client.stations[station - 1].stream[client.stations[station - 1].stream.default];
if (!url) {
2020-03-08 23:26:24 +00:00
radio.voiceChannel.leave();
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
}
2020-03-02 19:38:42 +00:00
const dispatcher = radio.connection
.play(url, { bitrate: 1024, passes: 10, volume: 1, highWaterMark: 1 << 25 })
2020-03-02 20:54:01 +00:00
.on("finish", () => {
2020-03-08 09:41:25 +00:00
radio.voiceChannel.leave();
2020-03-08 14:54:57 +00:00
client.radio.delete(guild.id);
2020-03-08 09:41:25 +00:00
return;
2020-03-02 19:38:42 +00:00
});
2020-03-08 23:26:24 +00:00
2020-03-02 19:38:42 +00:00
dispatcher.on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
});
2020-03-08 23:31:24 +00:00
2020-03-02 19:38:42 +00:00
dispatcher.on('error', error => {
console.error(error);
radio.voiceChannel.leave();
client.radio.delete(guild.id);
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
});
2020-03-08 23:31:24 +00:00
2020-03-02 19:38:42 +00:00
dispatcher.setVolume(radio.volume / 10);
2020-03-08 23:31:24 +00:00
2020-03-02 19:38:42 +00:00
radio.textChannel.send('Start playing');
radio.playing = true;
2020-03-08 23:26:24 +00:00
2020-03-02 19:38:42 +00:00
}