Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const fetch = require('node-fetch');
  3. const convert = require('xml-js');
  4. const reactions = require('../core/reactions');
  5. const _ = require('lodash');
  6.  
  7. exports.run = async (client, message, args, level) => {
  8.  
  9. const queue = client.getQueue(message.guild.id);
  10. const buttons = [
  11. reactions.zero, reactions.one, reactions.two, reactions.three, reactions.four,
  12. reactions.five, reactions.six, reactions.seven, reactions.eight, reactions.nine,
  13. ];
  14. const songsPerPage = 10;
  15. let pages;
  16. pages = _.chunk(queue, songsPerPage);
  17. pages = pages.map((page) => {
  18. let desc = page.map(track => ` **${track.info.title}** added by: **${track.requester.username}** [\`${client.getYTLive(track.info.length)}\`]`).join("\n");
  19. let pagesSize = Math.ceil(queue.length / 10);
  20. return {
  21. embed: {
  22. color: 0xbe3e99,
  23. author: {
  24. name: `Current queue for ${message.guild.name}`,
  25. icon_url: message.guild.iconURL
  26. },
  27. description: `Page **${page}** of **${pagesSize}**\n\n${desc}`,
  28. footer: {
  29. 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.`
  30. }
  31. }
  32. }
  33. });
  34.  
  35. message.channel.send(pages[0])
  36. .then(async (msg) => {
  37. /*for (const [index, _] of pages.entries()) {
  38. await msg.react(buttons[index]);
  39. }*/
  40. await msg.react(reactions.arrowleft);
  41. await msg.react(reactions.arrowright);
  42. await msg.react(reactions.x);
  43. msg.delete(60000).catch();
  44. const collector = msg.createReactionCollector((buttons, user) => user !== client.user);
  45.  
  46. let pageIndex = 0; // i added this here -- feb199
  47.  
  48. collector.on('collect', async (messageReaction) => {
  49.  
  50.  
  51. const notbot = messageReaction.users.filter(clientuser => clientuser !== client.user).first();
  52. await messageReaction.remove(notbot);
  53.  
  54. if (pagesSize < 1) {
  55. if (messageReaction.emoji.name === reactions.arrowleft) {
  56.  
  57. msg.edit(pages[pageIndex--]);
  58.  
  59. } else if (messageReaction.emoji.name === reactions.arrowright) {
  60.  
  61.  
  62. msg.edit(pages[pageIndex++]);
  63.  
  64. } else if (messageReaction.emoji.name === reactions.x) {
  65.  
  66. msg.delete(); // Delete the message
  67. collector.stop(); // Delete the collector.
  68. return;
  69.  
  70. }
  71. } else {
  72. if (messageReaction.emoji.name === reactions.x) {
  73.  
  74. msg.delete(); // Delete the message
  75. collector.stop(); // Delete the collector.
  76. return;
  77.  
  78. }
  79. }
  80.  
  81. if (messageReaction.emoji.name === reactions.x) {
  82. msg.delete(); // Delete the message
  83. collector.stop(); // Delete the collector.
  84. return;
  85. };
  86.  
  87. /* const pageIndex = buttons.indexOf(messageReaction.emoji.name);
  88. if (pageIndex === -1 || !pages[pageIndex]) return;
  89.  
  90. msg.edit(pages[pageIndex]);
  91. const notbot = messageReaction.users.filter(clientuser => clientuser !== client.user).first();
  92. await messageReaction.remove(notbot); */
  93. })
  94. }).catch(err => console.log(err));
  95. };
  96.  
  97. exports.conf = {
  98. enabled: true,
  99. guildOnly: false,
  100. aliases: ["l", "list"],
  101. permLevel: "Bot Owner"
  102. };
  103.  
  104. exports.help = {
  105. name: "list",
  106. category: "Music",
  107. description: "Displays the current queue playing on the bot",
  108. usage: "list"
  109. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement