mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-23 02:33:18 +00:00
Add duration to Play command
This commit is contained in:
parent
d904d65eed
commit
c21082c67b
@ -10,13 +10,13 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
|
|||||||
radio.connection.subscribe(audioPlayer);
|
radio.connection.subscribe(audioPlayer);
|
||||||
client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name);
|
client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name);
|
||||||
|
|
||||||
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
|
try {
|
||||||
let playlist: any = await fetch(radio.station.playlist.address)
|
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())
|
.then((response: Response) => response.json())
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
switch(radio.station?.playlist.type){
|
switch(radio.station?.playlist.type){
|
||||||
case "supla":
|
case "supla":
|
||||||
radio.station.track = "__" + playlist.items[0]?.artist + "__" + "\n" + playlist.items[0]?.song;
|
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:
|
default:
|
||||||
radio.station.track = "-";
|
radio.station.track = "-";
|
||||||
}
|
}
|
||||||
} catch(TypeError) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch(TypeError) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@ -48,7 +48,14 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
|
|||||||
value: client.messages.replace(client.messages.playDescription2, {
|
value: client.messages.replace(client.messages.playDescription2, {
|
||||||
"%radio.station.track%": radio.station.track != undefined ? "\n\n" + radio.station.track : "-"
|
"%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')
|
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: client.messages.footerText,
|
text: client.messages.footerText,
|
||||||
@ -99,18 +106,19 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
setInterval(async function(){
|
setInterval(async function(){
|
||||||
|
const radio = client.radio?.get(guild.id);
|
||||||
let changed = false;
|
let changed = false;
|
||||||
|
|
||||||
if(radio.station?.playlist?.type == "supla" || radio.station?.playlist?.type == "yle"){
|
try {
|
||||||
let playlist: any = await fetch(radio.station.playlist.address)
|
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())
|
.then((response: Response) => response.json())
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
});
|
});
|
||||||
try {
|
|
||||||
switch(radio.station?.playlist.type){
|
switch(radio.station?.playlist.type){
|
||||||
case "supla":
|
case "supla":
|
||||||
if(radio.station.track != playlist.items[0].artist + "\n" + playlist.items[0].song){
|
if(radio.station.track != "__" + playlist.items[0]?.artist + "__" + "\n" + playlist.items[0].song){
|
||||||
changed = true;
|
|
||||||
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;
|
break;
|
||||||
@ -120,45 +128,54 @@ export default async function play(client: RadioClient, interaction: ChatInputCo
|
|||||||
default:
|
default:
|
||||||
radio.station.track = "-";
|
radio.station.track = "-";
|
||||||
}
|
}
|
||||||
} catch(TypeError) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch(TypeError) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(changed == true){
|
let date = new Date();
|
||||||
const embed = new EmbedBuilder()
|
radio.currentTime = date.getTime();
|
||||||
.setTitle(client.user?.username || "-")
|
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
||||||
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messages.emojis["play"].replace(/[^0-9]+/g, '')))
|
const completed = (radio.playTime);
|
||||||
.setColor(client.config.embedColor)
|
|
||||||
.addFields({
|
const embed = new EmbedBuilder()
|
||||||
name: client.messages.playTitle1,
|
.setTitle(client.user?.username || "-")
|
||||||
value: client.messages.replace(client.messages.playDescription1, {
|
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messages.emojis["play"].replace(/[^0-9]+/g, '')))
|
||||||
"%radio.station.name%": radio.station.name,
|
.setColor(client.config.embedColor)
|
||||||
"%radio.station.owner%": radio.station.name != radio.station.owner ? radio.station.owner + "\n" : ""
|
.addFields({
|
||||||
})
|
name: client.messages.playTitle1,
|
||||||
},
|
value: client.messages.replace(client.messages.playDescription1, {
|
||||||
{
|
"%radio.station.name%": radio.station.name,
|
||||||
name: client.messages.playTitle2,
|
"%radio.station.owner%": radio.station.name != radio.station.owner ? radio.station.owner + "\n" : ""
|
||||||
value: client.messages.replace(client.messages.playDescription2, {
|
|
||||||
"%radio.station.track%": radio.station.track != undefined ? "\n\n" + radio.station.track : "-"
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
},
|
||||||
.setFooter({
|
{
|
||||||
text: client.messages.footerText,
|
name: client.messages.playTitle2,
|
||||||
iconURL: "https://cdn.discordapp.com/emojis/" + client.messages.emojis["eximiabots"].replace(/[^0-9]+/g, '')
|
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){
|
if(!radio.message){
|
||||||
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
|
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 {
|
} else {
|
||||||
if(radio.textChannel.id == radio.message.channel.id){
|
radio.message?.delete();
|
||||||
radio.message.edit({ embeds: [embed], components: [buttons] });
|
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
|
||||||
} else {
|
|
||||||
radio.message?.delete();
|
|
||||||
radio.message = await radio.textChannel?.send({ embeds: [embed], components: [buttons] });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},15000);
|
},15000);
|
||||||
|
@ -26,8 +26,8 @@ export const messages = {
|
|||||||
playDescription1: "__%radio.station.name%__" + "\n" + "%radio.station.owner%",
|
playDescription1: "__%radio.station.name%__" + "\n" + "%radio.station.owner%",
|
||||||
playTitle2: ":musical_note: Track",
|
playTitle2: ":musical_note: Track",
|
||||||
playDescription2: "%radio.station.track%",
|
playDescription2: "%radio.station.track%",
|
||||||
nowplayingTitle: "Now Playing",
|
playTitle3: ":stopwatch: Duration",
|
||||||
nowplayingDescription: "**%radio.station.name%**" + "\n" + "%radio.station.owner%" + "\n" + "%client.funcs.msToTime(completed)%" + "\n\n" + "%radio.station.track%",
|
playDescription3: "%client.funcs.msToTime(completed)%",
|
||||||
noVoiceChannel: "You need to be in a voice channel to play radio!",
|
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!",
|
noQuery: "You need to use a number or search for a supported station!",
|
||||||
noPermsConnect: "I cannot connect to your voice channel.",
|
noPermsConnect: "I cannot connect to your voice channel.",
|
||||||
|
Loading…
Reference in New Issue
Block a user