Skip to content

Commit

Permalink
chore: Add createMusicEmbed function for music embed creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyphen1223 committed May 13, 2024
1 parent e1d56ac commit d5a5cdf
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
57 changes: 56 additions & 1 deletion util/embed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const config = require('../config.json');

const { formatTime } = require('./time.js');

const { EmbedBuilder } = require('discord.js');

function createMessageEmbed(content, interaction) {
Expand All @@ -12,4 +14,57 @@ function createMessageEmbed(content, interaction) {
return embed;
}

module.exports = { createMessageEmbed };
function createMusicEmbed(guildId, mode, type) {
const current = global.queue[guildId].queue[global.queue[guildId].index].data.info;
let requester = '';
if (
global.queue[guildId].queue[global.queue[guildId].index].user ===
'Auto Recommendation'
) {
requester = 'Auto Recommendation';
} else {
requester = `<@${queue[guildId].queue[queue[guildId].index].user.id}>`;
}
const embed = new EmbedBuilder()
.setColor(config.config?.color?.info || '#000000')
.addFields(
{
name: 'Author',
value: current.author,
inline: true,
},
{
name: 'Title',
value: current.title,
inline: true,
},
{
name: 'Duration',
value: `${formatTime(
Math.floor(global.queue[guildId].player.position / 1000)
)}/${formatTime(Math.floor(current.length / 1000))}`,
inline: true,
},
{
name: 'Requested by',
value: requester,
inline: true,
},
{
name: 'Volume',
value: `${queue[guildId].volume}%`,
inline: true,
},
{
name: 'Position',
value: `${global.queue[guildId].index + 1}/${
global.queue[guildId].queue.length
}`,
inline: true,
}
)
.setImage(current.artworkUrl);
return embed;
}

module.exports = { createMessageEmbed, createMusicEmbed };
3 changes: 2 additions & 1 deletion util/playerEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
const listenEvents = async (guildId) => {
global.queue[guildId].player.on('start', async (data) => {
const current = global.queue[guildId].queue[global.queue[guildId].index];
global.queue[guildId].textChannel.send(`Now playing: ${current.data.info.title}`);
const embed = createMusicEmbed(guildId, 'Start');
await global.queue[guildId].textChannel.send({ embeds: [embed] });
});
};

Expand Down
Empty file added util/test.js
Empty file.
20 changes: 20 additions & 0 deletions util/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function formatTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
let formattedTime = '';
if (hours > 0) {
formattedTime += `${hours}h`;
}
if (minutes > 0) {
formattedTime += `${minutes}m`;
}
if (remainingSeconds > 0) {
formattedTime += `${remainingSeconds}s`;
}
return formattedTime;
}

module.exports = {
formatTime,
};

0 comments on commit d5a5cdf

Please sign in to comment.