Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. const reactions = require('../core/reactions');
  2. const _ = require('lodash');
  3.  
  4. exports.run = async (client, message, args, level) => {
  5.  
  6. let TempPageIndex = 0;
  7. const queue = client.getQueue(message.guild.id);
  8. const songsPerPage = 20;
  9. let pages;
  10. let pagesSize = Math.ceil(queue.length / 20);
  11.  
  12. pages = _.chunk(queue, songsPerPage);
  13. pages = pages.map((page) => {
  14. let index = 0;
  15. let desc = page.map(track => `**${++index}** - **${track.info.title}** added by: **${track.requester.username}** [\`${client.getYTLive(track.info.length)}\`]`).join("\n");
  16. TempPageIndex = TempPageIndex + 1;
  17. console.log(TempPageIndex);
  18. return {
  19. embed: {
  20. color: 0xbe3e99,
  21. author: {
  22. name: `Current queue for ${message.guild.name}`,
  23. icon_url: message.guild.iconURL
  24. },
  25. description: `Page **${TempPageIndex}** of **${pagesSize}**\n\n${desc}`,
  26. footer: {
  27. text: `There are ${Math.ceil(queue.length - 1)} tracks with a remaining length of [${client.getYTLive(queue.reduce((a, b) => a + b.info.length, 0))}] in the queue.`
  28. }
  29. }
  30. }
  31. });
  32.  
  33. message.channel.send(pages[0])
  34. .then(async (msg) => {
  35.  
  36. await msg.react('⬅');
  37. await msg.react('➡');
  38. await msg.react('🇽');
  39. const collector = msg.createReactionCollector((buttons, user) => user !== client.user);
  40.  
  41. let pageIndex = 0;
  42.  
  43. collector.on('collect', async (messageReaction) => {
  44.  
  45. const notbot = messageReaction.users.filter(clientuser => clientuser !== client.user).first();
  46. await messageReaction.remove(notbot);
  47. if (messageReaction.emoji.name === '⬅') {
  48.  
  49. msg.edit(pages[pageIndex--]);
  50.  
  51. } else if (messageReaction.emoji.name === '➡') {
  52.  
  53. msg.edit(pages[pageIndex++]);
  54.  
  55. } else if (messageReaction.emoji.name === '🇽') {
  56.  
  57. msg.delete(); // Delete the message
  58. collector.stop(); // Delete the collector.
  59. return;
  60.  
  61. }
  62. if(pageIndex === 0) messageReaction.fetchUsers().then(users => {
  63. users.forEach(user => {
  64. messageReaction.remove(user);
  65. });
  66. }).catch(console.error);
  67. })
  68. }).catch(err => console.log(err));
  69.  
  70.  
  71. function switchPage(reaction) {
  72. if (reaction.emoji.name == '⬅') {
  73. if (currentPage === 0) reaction.fetchUsers().then(users => {
  74. users.forEach(user => {
  75. reaction.remove(user);
  76. });
  77. }).catch(console.error);
  78. else {
  79. //etc.
  80. }
  81. } else if (reaction.emoji.name == '➡') {
  82.  
  83. } else throw new Error('No valid emoji was catched.')
  84. }
  85. };
  86.  
  87. exports.conf = {
  88. enabled: true,
  89. guildOnly: false,
  90. aliases: ["l", "list"],
  91. permLevel: "Bot Owner"
  92. };
  93.  
  94. exports.help = {
  95. name: "list",
  96. category: "Music",
  97. description: "Displays the current queue playing on the bot",
  98. usage: "list"
  99. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement