Skip to content

Commit cbaf096

Browse files
committed
fix(currentSong): use song.stream.song when possible
This patch allows supporting other plugins such as Spotify
1 parent a44176b commit cbaf096

5 files changed

Lines changed: 10 additions & 11 deletions

File tree

commands/info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ module.exports = {
1010
.setDMPermission(false),
1111
run: async (client, interaction, guildData, queue, lang) => {
1212
const member = interaction.member;
13-
const currentSong = queue?.songs[0];
13+
const currentSong = queue?.songs[0]?.stream?.song || queue?.songs[0];
1414

1515
if (!currentSong) return client.sendErrorNotification(interaction, `${lang.ERROR_SONG_NO_PLAYING}`);
1616
if (!client.handleCooldown("infoCommand", member.id, 2000)) return client.sendErrorNotification(interaction, `${lang.ERROR_ACTION_NOT_POSSIBLE}`);
1717
// Create duration bar
18-
const durationBar = client.createDurationBar(queue);
18+
const durationBar = client.createDurationBar(queue, currentSong);
1919
// Create info embed
2020
const infoEmbed = new EmbedBuilder().setAuthor({ name: `${currentSong.name}`, url: currentSong.url, iconURL: elements.ICON_FLOPY }).setThumbnail(currentSong.thumbnail).addFields({ name: `**${lang.MESSAGE_ITEM_AUTHOR}**`, value: `${currentSong.uploader?.name || "-"}`, inline: true }, { name: `**${lang.MESSAGE_ITEM_VIEWS}**`, value: `${currentSong.views.toString().replace(/(.)(?=(\d{3})+$)/g, "$1,")}`, inline: true }, { name: `**${lang.MESSAGE_ITEM_LIKES}**`, value: `${currentSong.likes.toString().replace(/(.)(?=(\d{3})+$)/g, "$1,")}`, inline: true }, { name: `**${lang.MESSAGE_ITEM_DURATION}**`, value: `${durationBar}` }).setColor(elements.COLOR_FLOPY);
2121
// Send song informaton and then delete reply

commands/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = {
6565
case "add":
6666
const type = options.getString("type") || "video";
6767
const isPlaylist = type === "playlist";
68-
const currentItem = isPlaylist ? queue?.songs[0]?.playlist : queue?.songs[0];
68+
const currentItem = isPlaylist ? queue?.songs[0]?.playlist : queue?.songs[0]?.stream?.song || queue?.songs[0];
6969
if (!currentItem) return client.sendErrorNotification(interaction, `${isPlaylist ? lang.ERROR_PLAYLIST_NO_PLAYING : lang.ERROR_SONG_NO_PLAYING}`);
7070
if (library.find((item) => item.url === currentItem.url)) return client.sendErrorNotification(interaction, `${isPlaylist ? lang.ERROR_LIBRARY_PLAYLIST_ALREADY_ADDED : lang.ERROR_LIBRARY_SONG_ALREADY_ADDED}`);
7171
if (library.length >= config.LIBRARY_MAX_LENGTH) return client.sendErrorNotification(interaction, `${lang.ERROR_LIBRARY_LIMIT_REACHED}`);

commands/replay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
.setDMPermission(false),
1010
run: async (client, interaction, guildData, queue, lang) => {
1111
const { guild, member } = interaction;
12-
const currentSong = queue?.songs[0];
12+
const currentSong = queue?.songs[0]?.stream?.song || queue?.songs[0];
1313

1414
if (!currentSong) return client.sendErrorNotification(interaction, `${lang.ERROR_SONG_NO_PLAYING}`);
1515
if (!client.checkMemberIsInMyVoiceChannel(guild, member)) return client.sendErrorNotification(interaction, `${lang.ERROR_MEMBER_MUST_JOIN_MY_VOICE_CHANNEL}`);

commands/seek.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
),
1717
run: async (client, interaction, guildData, queue, lang) => {
1818
const { guild, member, options } = interaction;
19-
const currentSong = queue?.songs[0];
19+
const currentSong = queue?.songs[0]?.stream?.song || queue?.songs[0];
2020
const hhmmss = options.getInteger("hhmmss").toString();
2121

2222
if(!currentSong) return client.sendErrorNotification(interaction, `${lang.ERROR_SONG_NO_PLAYING}`);
@@ -35,7 +35,7 @@ module.exports = {
3535
client.updateDashboardMessage(guild, queue, lang);
3636
}
3737
// Create duration bar
38-
const durationBar = client.createDurationBar(queue);
38+
const durationBar = client.createDurationBar(queue, currentSong);
3939
// Send notification
4040
client.sendNotification(interaction, `${durationBar}`, { editReply: true });
4141
} catch (error) {

utils/functions.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module.exports = (client) => {
130130
// Create dashboard
131131
client.createDashboard = (guild, queue, lang) => {
132132
const songs = queue?.songs || [];
133-
const currentSong = songs[0];
133+
const currentSong = songs[0]?.stream?.song || songs[0];
134134
const formattedSongs = songs.slice(1, config.QUEUE_MAX_LENGTH_DISPLAY + 1).map((song, i) => { return `**${i + 1}.** ${song.name.length > config.ITEM_NAME_MAX_LENGTH_DISPLAY ? song.name.substr(0, config.ITEM_NAME_MAX_LENGTH_DISPLAY).concat("...") : song.name}` }).reverse().join("\n");
135135
const dashboardContent = `**__${lang.DASHBOARD_QUEUE}__**\n${currentSong ? `${songs.length - 1 > config.QUEUE_MAX_LENGTH_DISPLAY ? `**+${songs.length - 1 - config.QUEUE_MAX_LENGTH_DISPLAY}**\n` : ""}${formattedSongs || lang.DASHBOARD_QUEUE_NO_SONG}` : lang.DASHBOARD_QUEUE_NONE}`;
136136
const dashboardEmbed = new EmbedBuilder().setTitle(currentSong ? `[${currentSong.formattedDuration}] ${currentSong.name}` : `${lang.DASHBOARD_SONG_NO_PLAYING}`).setDescription(!currentSong ? `[Flopy](${elements.INVITE_FLOPY}) | [Flopy 2](${elements.INVITE_FLOPY2}) | [Flopy 3](${elements.INVITE_FLOPY3}) | [Support](${elements.INVITE_SUPPORT})` : null).setImage(currentSong ? currentSong.thumbnail : elements.BANNER_DASHBOARD).setFooter(currentSong ? { text: `${lang.DASHBOARD_VOLUME} ${queue.volume}%${queue.repeatMode === 1 ? ` | ${lang.DASHBOARD_REPEAT_SONG}` : queue.repeatMode === 2 ? ` | ${lang.DASHBOARD_REPEAT_QUEUE}` : ""}${queue.autoplay ? ` | ${lang.DASHBOARD_AUTOPLAY_ON}` : ""}${queue.filters.size > 0 ? ` | ${lang.DASHBOARD_FILTERS} ${queue.filters.size}` : ""}` } : null).setColor(currentSong ? guild.members.me.displayHexColor.replace("#000000", elements.COLOR_WHITE) : elements.COLOR_FLOPY);
@@ -171,12 +171,11 @@ module.exports = (client) => {
171171
}
172172

173173
// Create duration bar
174-
client.createDurationBar = (queue) => {
175-
const currentSong = queue.songs[0];
176-
const progress = Math.min(Math.round((queue.currentTime / currentSong.duration) * config.DURATION_BAR_MAX_LENGTH_DISPLAY), config.DURATION_BAR_MAX_LENGTH_DISPLAY);
174+
client.createDurationBar = (queue, song) => {
175+
const progress = Math.min(Math.round((queue.currentTime / song.duration) * config.DURATION_BAR_MAX_LENGTH_DISPLAY), config.DURATION_BAR_MAX_LENGTH_DISPLAY);
177176
const rest = config.DURATION_BAR_MAX_LENGTH_DISPLAY - progress;
178177
const bar = new Array(progress).fill(elements.SYMBOL_LINE).concat(elements.SYMBOL_CIRCLE).concat(new Array(rest).fill(" ")).join("");
179-
return `\`${queue.formattedCurrentTime} ${bar} ${currentSong.formattedDuration}\``;
178+
return `\`${queue.formattedCurrentTime} ${bar} ${song.formattedDuration}\``;
180179
}
181180

182181
// Convert HHMMSS to seconds

0 commit comments

Comments
 (0)