Add duration to Play command

This commit is contained in:
Christer Warén 2023-11-28 13:28:17 +02:00
parent d904d65eed
commit c21082c67b
2 changed files with 61 additions and 44 deletions

View File

@ -10,13 +10,13 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
radio.connection.subscribe(audioPlayer);
client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name);
try {
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
let playlist: any = await fetch(radio.station.playlist.address)
.then((response: Response) => response.json())
.catch(error => {
});
try {
switch(radio.station?.playlist.type){
case "supla":
radio.station.track = "__" + playlist.items[0]?.artist + "__" + "\n" + playlist.items[0]?.song;
@ -27,10 +27,10 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
default:
radio.station.track = "-";
}
}
} catch(TypeError) {
}
}
const embed = new EmbedBuilder()
.setTitle(client.user?.username || "-")
@ -48,7 +48,14 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
value: client.messages.replace(client.messages.playDescription2, {
"%radio.station.track%": radio.station.track != undefined ? "\n\n" + radio.station.track : "-"
})
},
{
name: client.messages.playTitle3,
value: client.messages.replace(client.messages.playDescription3, {
"%client.funcs.msToTime(completed)%": "-"
})
})
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter({
text: client.messages.footerText,
@ -99,18 +106,19 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
}
setInterval(async function(){
const radio = client.radio?.get(guild.id);
let changed = false;
try {
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
let playlist: any = await fetch(radio.station.playlist.address)
.then((response: Response) => response.json())
.catch(error => {
});
try {
switch(radio.station?.playlist.type){
case "supla":
if(radio.station.track != playlist.items[0].artist + "\n" + playlist.items[0].song){
changed = true;
if(radio.station.track != "__" + playlist.items[0]?.artist + "__" + "\n" + playlist.items[0].song){
radio.station.track = "__" + playlist.items[0].artist + "__" + "\n" + playlist.items[0].song;
}
break;
@ -120,12 +128,16 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
default:
radio.station.track = "-";
}
}
} catch(TypeError) {
}
}
if(changed == true){
let date = new Date();
radio.currentTime = date.getTime();
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
const completed = (radio.playTime);
const embed = new EmbedBuilder()
.setTitle(client.user?.username || "-")
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messages.emojis["play"].replace(/[^0-9]+/g, '')))
@ -142,6 +154,12 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
value: client.messages.replace(client.messages.playDescription2, {
"%radio.station.track%": radio.station.track != undefined ? "\n\n" + radio.station.track : "-"
})
},
{
name: client.messages.playTitle3,
value: client.messages.replace(client.messages.playDescription3, {
"%client.funcs.msToTime(completed)%": client.funcs.msToTime(completed)
})
})
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter({
@ -160,7 +178,6 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
}
}
}
},15000);
interaction?.reply({

View File

@ -26,8 +26,8 @@ export const messages = {
playDescription1: "__%radio.station.name%__" + "\n" + "%radio.station.owner%",
playTitle2: ":musical_note: Track",
playDescription2: "%radio.station.track%",
nowplayingTitle: "Now Playing",
nowplayingDescription: "**%radio.station.name%**" + "\n" + "%radio.station.owner%" + "\n" + "%client.funcs.msToTime(completed)%" + "\n\n" + "%radio.station.track%",
playTitle3: ":stopwatch: Duration",
playDescription3: "%client.funcs.msToTime(completed)%",
noVoiceChannel: "You need to be in a voice channel to play radio!",
noQuery: "You need to use a number or search for a supported station!",
noPermsConnect: "I cannot connect to your voice channel.",