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