Updated code

This commit is contained in:
Christer Warén 2021-08-22 18:48:40 +03:00
parent 606dcc0ab3
commit 2fec81e84d
4 changed files with 20 additions and 11 deletions

View File

@ -18,7 +18,7 @@ module.exports = {
(async () => { (async () => {
try { try {
console.log('Started refreshing application (/) commands.'); console.log('[Slash Commands] Started refreshing application (/) commands.');
if(version.includes("-dev")){ if(version.includes("-dev")){
await rest.put( await rest.put(
@ -44,8 +44,9 @@ module.exports = {
); );
} }
console.log('Successfully reloaded application (/) commands.'); console.log('[Slash Commands] Successfully reloaded application (/) commands.' + "\n");
} catch (error) { } catch (error) {
console.log('[Slash Commands] Reloading application (/) commands failed.' + "\n");
console.error(error); console.error(error);
} }
})(); })();

View File

@ -88,7 +88,7 @@ module.exports = {
radio.station = station; radio.station = station;
radio.textChannel = interaction.channel; radio.textChannel = interaction.channel;
play(interaction.guild, client, url); play(interaction, interaction.guild, client, url);
return; return;
} }
@ -131,6 +131,7 @@ module.exports = {
} }
} }
}; };
function play(interaction, guild, client, url) { function play(interaction, guild, client, url) {
let message = {}; let message = {};
const radio = client.radio.get(guild.id); const radio = client.radio.get(guild.id);
@ -139,18 +140,21 @@ function play(interaction, guild, client, url) {
radio.audioPlayer.play(resource); radio.audioPlayer.play(resource);
resource.playStream resource.playStream
.on("readable", () => { .on("readable", () => {
console.log("Stream started"); console.log("[Radio] Stream started" + " / " + guild.id + " / " + radio.station.name);
}) })
.on("finish", () => { .on("finish", () => {
console.log("Stream finished"); console.log("[Radio] Stream finished" + " / " + guild.id);
client.funcs.statisticsUpdate(client, guild, radio); client.funcs.statisticsUpdate(client, guild, radio);
radio.connection.destroy(); radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id); client.radio.delete(guild.id);
return; return;
}) })
.on("error", error => { .on("error", error => {
console.log("[Radio] Stream errored");
console.error(error); console.error(error);
radio.connection.destroy(); radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id); client.radio.delete(guild.id);
return interaction.reply(client.messages.errorPlaying); return interaction.reply(client.messages.errorPlaying);
}); });

View File

@ -7,6 +7,7 @@ module.exports = {
console.log('RadioX ' + client.config.version); console.log('RadioX ' + client.config.version);
console.log('Internet Radio to your Discord guild'); console.log('Internet Radio to your Discord guild');
console.log('(c)2020-2021 EximiaBots by Warén Group'); console.log('(c)2020-2021 EximiaBots by Warén Group');
console.log('');
client.developers = ""; client.developers = "";
let user = ""; let user = "";
@ -24,7 +25,7 @@ module.exports = {
.then(client.funcs.checkFetchStatus) .then(client.funcs.checkFetchStatus)
.then(response => response.json()); .then(response => response.json());
} catch (error) { } catch (error) {
console.error(error); //console.error(error);
} }
setInterval(async () => { setInterval(async () => {
@ -33,7 +34,7 @@ module.exports = {
.then(client.funcs.checkFetchStatus) .then(client.funcs.checkFetchStatus)
.then(response => response.json()); .then(response => response.json());
} catch (error) { } catch (error) {
console.error(error); //console.error(error);
} }
}, 3600000); }, 3600000);

View File

@ -16,8 +16,9 @@ module.exports = {
if (newState.channel === null) { if (newState.channel === null) {
client.funcs.statisticsUpdate(client, newState.guild, radio); client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection = null; radio.connection?.destroy();
radio.audioPlayer?.stop(); radio.audioPlayer?.stop();
console.log("[Radio] Stream stopped" + " / " + newState.guild.id);
return client.radio.delete(newState.guild.id); return client.radio.delete(newState.guild.id);
} }
@ -39,6 +40,7 @@ module.exports = {
client.funcs.statisticsUpdate(client, newState.guild, radio); client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection?.destroy(); radio.connection?.destroy();
radio.audioPlayer?.stop(); radio.audioPlayer?.stop();
console.log("[Radio] Stream stopped" + " / " + newState.guild.id);
client.radio.delete(oldState.guild.id); client.radio.delete(oldState.guild.id);
} }
return; return;
@ -57,9 +59,10 @@ module.exports = {
client.funcs.statisticsUpdate(client, newState.guild, radio); client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection?.destroy(); radio.connection?.destroy();
radio.audioPlayer?.stop(); radio.audioPlayer?.stop();
console.log("[Radio] Stream stopped" + " / " + newState.guild.id);
client.radio.delete(newState.guild.id); client.radio.delete(newState.guild.id);
} }
}, 120000); }, 60000);
} }
}, },
}; };