Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix queue command
Browse files Browse the repository at this point in the history
  • Loading branch information
itsayushch committed Aug 14, 2020
1 parent 2a125b6 commit bcf3f00
Showing 1 changed file with 6 additions and 62 deletions.
68 changes: 6 additions & 62 deletions src/commands/music/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,95 +29,39 @@ class QueueCommand extends Command {

async exec(message, { page }) {
const queue = this.client.music.queues.get(message.guild.id);
const current = await queue.current();
const current = Object.assign({ track: null, position: 0 }, await queue.current());
const tracks = [(current || { track: null }).track].concat(await queue.tracks()).filter(track => track);
if (!tracks.length) {
const embed = new MessageEmbed()
.setColor(0x5e17eb)
.setColor(0x0080ff)
.setAuthor(`Queue for ${message.guild.name}`, message.guild.iconURL())
.setDescription('No more songs in Queue');
return message.util.send({ embed });
}

const decoded = await this.client.music.decode(tracks);
const totalLength = decoded.filter(track => !track.info.isStream).reduce((prev, song) => prev + song.info.length, 0);
let pagesNum = Math.ceil(decoded.length / 10);
if (pagesNum === 0) pagesNum = 1;
const totalLength = decoded.slice(1).filter(track => !track.info.isStream).reduce((prev, song) => prev + song.info.length, 0);
const paginated = paginate(decoded.slice(1), page);
let index = (paginated.page - 1) * 10;
const pages = [];
for (let i = 0; i < pagesNum; i++) {
const str = decoded.slice(i * 10, (i * 10) + 10).join('');
const embed = new MessageEmbed()
.setAuthor(`Queue - ${message.guild.name}`, message.guild.iconURL())
.setColor(0x5e17eb)
.setDescription([
'🎵 **Now Playing**',
`[${decoded[0].info.title}](${decoded[0].info.uri}) (${timeString(current.position)}/${decoded[0].info.isStream ? '∞' : timeString(decoded[0].info.length)})`,
'',
decoded.length
? stripIndents`🎶 **Current Queue${paginated.maxPage > 1 ? `, Page ${paginated.page}/${paginated.maxPage}` : ''}**
${paginated.items.map(song => `**${++index}.** [${song.info.title}](${song.info.uri}) (${song.info.isStream ? '∞' : timeString(song.info.length)})`).join('\n')}

**Total Queue Time:** ${timeString(totalLength)}, **Song${decoded.length > 1 || decoded.length === 0 ? 's' : ''}:** ${decoded.length}`
: 'No songs in Queue!'
]);
pages.push(embed);
}
const embed = new MessageEmbed()
.setColor(0x5e17eb)
.setAuthor(`Queue for ${message.guild.name}`, message.guild.iconURL())
.setThumbnail(`https://i.ytimg.com/vi/${decoded[0].info.identifier}/hqdefault.jpg`)
.setDescription([
'🎵 **Now Playing**',
'**Now Playing**',
`[${decoded[0].info.title}](${decoded[0].info.uri}) (${timeString(current.position)}/${decoded[0].info.isStream ? '∞' : timeString(decoded[0].info.length)})`,
'',
paginated.items.length
? stripIndents`🎶 **Current Queue${paginated.maxPage > 1 ? `, Page ${paginated.page}/${paginated.maxPage}` : ''}**
? stripIndents`**Queue${paginated.maxPage > 1 ? `, Page ${paginated.page}/${paginated.maxPage}` : ''}**
${paginated.items.map(song => `**${++index}.** [${song.info.title}](${song.info.uri}) (${song.info.isStream ? '∞' : timeString(song.info.length)})`).join('\n')}
**Total Queue Time:** ${timeString(totalLength)}, **Song${decoded.length > 1 || decoded.length === 0 ? 's' : ''}:** ${decoded.length}`
: 'No songs in Queue!'
: 'No more songs in Queue'
]);

return message.util.send({ embed });
}

async page(message, pages) {
let page = 0;
const emojiList = ['⬅', '➡'];
const msg = await message.channel.send(pages[page]);

for (const emoji of ['⬅', '➡']) {
await msg.react(emoji);
}

const collector = msg.createReactionCollector(
(reaction, user) => emojiList.includes(reaction.emoji.name) && user.id === message.author.id,
{ time: 45000, max: 10 }
);

collector.on('collect', reaction => {
reaction.users.remove(message.author);
switch (reaction.emoji.name) {
case emojiList[0]:
page = page > 0 ? --page : pages.length - 1;
break;
case emojiList[1]:
page = page + 1 < pages.length ? ++page : 0;
break;
default:
break;
}
msg.edit(pages[page]);
});

collector.on('end', async () => {
await msg.reactions.removeAll().catch(() => null);
});

return msg;
}
}

module.exports = QueueCommand;

0 comments on commit bcf3f00

Please sign in to comment.