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);
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
let playlist: any = await fetch(radio.station.playlist.address)
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,9 +27,9 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
default:
radio.station.track = "-";
}
} catch(TypeError) {
}
} catch(TypeError) {
}
const embed = new EmbedBuilder()
@ -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;
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
let playlist: any = await fetch(radio.station.playlist.address)
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,45 +128,54 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
default:
radio.station.track = "-";
}
} catch(TypeError) {
}
} catch(TypeError) {
}
if(changed == true){
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, '')))
.setColor(client.config.embedColor)
.addFields({
name: client.messages.playTitle1,
value: client.messages.replace(client.messages.playDescription1, {
"%radio.station.name%": radio.station.name,
"%radio.station.owner%": radio.station.name != radio.station.owner ? radio.station.owner + "\n" : ""
})
},
{
name: client.messages.playTitle2,
value: client.messages.replace(client.messages.playDescription2, {
"%radio.station.track%": radio.station.track != undefined ? "\n\n" + radio.station.track : "-"
})
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, '')))
.setColor(client.config.embedColor)
.addFields({
name: client.messages.playTitle1,
value: client.messages.replace(client.messages.playDescription1, {
"%radio.station.name%": radio.station.name,
"%radio.station.owner%": radio.station.name != radio.station.owner ? radio.station.owner + "\n" : ""
})
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter({
text: client.messages.footerText,
iconURL: "https://cdn.discordapp.com/emojis/" + client.messages.emojis["eximiabots"].replace(/[^0-9]+/g, '')
});
},
{
name: client.messages.playTitle2,
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({
text: client.messages.footerText,
iconURL: "https://cdn.discordapp.com/emojis/" + client.messages.emojis["eximiabots"].replace(/[^0-9]+/g, '')
});
if(!radio.message){
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
if(!radio.message){
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
} else {
if(radio.textChannel.id == radio.message.channel.id){
radio.message.edit({ embeds: [embed], components: [buttons] });
} else {
if(radio.textChannel.id == radio.message.channel.id){
radio.message.edit({ embeds: [embed], components: [buttons] });
} else {
radio.message?.delete();
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
}
radio.message?.delete();
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
}
}
},15000);

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.",