queue.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. const { MessageEmbed } = require("discord.js");
  2. const _ = require("lodash");
  3. const prettyMilliseconds = require("pretty-ms");
  4. module.exports = {
  5. name: "queue",
  6. description: "The server queue",
  7. usage: "",
  8. permissions: {
  9. channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
  10. member: [],
  11. },
  12. aliases: ["q"],
  13. /**
  14. *
  15. * @param {import("../structures/DiscordMusicBot")} client
  16. * @param {import("discord.js").Message} message
  17. * @param {string[]} args
  18. * @param {*} param3
  19. */
  20. run: async (client, message, args, { GuildDB }) => {
  21. let player = await client.Manager.get(message.guild.id);
  22. if (!player)
  23. return client.sendTime(
  24. message.channel,
  25. "❌ | **Nothing is playing right now...**"
  26. );
  27. if (!player.queue || !player.queue.length || player.queue === 0) {
  28. let QueueEmbed = new MessageEmbed()
  29. .setAuthor("Currently playing", client.config.IconURL)
  30. .setColor("RANDOM")
  31. .setDescription(
  32. `[${player.queue.current.title}](${player.queue.current.uri})`
  33. )
  34. .addField("Requested by", `${player.queue.current.requester}`, true)
  35. .addField(
  36. "Duration",
  37. `${
  38. client.ProgressBar(
  39. player.position,
  40. player.queue.current.duration,
  41. 15
  42. ).Bar
  43. } \`[${prettyMilliseconds(player.position, {
  44. colonNotation: true,
  45. })} / ${prettyMilliseconds(player.queue.current.duration, {
  46. colonNotation: true,
  47. })}]\``
  48. )
  49. .setThumbnail(player.queue.current.displayThumbnail());
  50. return message.channel.send(QueueEmbed);
  51. }
  52. let Songs = player.queue.map((t, index) => {
  53. t.index = index;
  54. return t;
  55. });
  56. let ChunkedSongs = _.chunk(Songs, 10); //How many songs to show per-page
  57. let Pages = ChunkedSongs.map((Tracks) => {
  58. let SongsDescription = Tracks.map(
  59. (t) =>
  60. `\`${t.index + 1}.\` [${t.title}](${t.uri}) \n\`${prettyMilliseconds(
  61. t.duration,
  62. {
  63. colonNotation: true,
  64. }
  65. )}\` **|** Requested by: ${t.requester}\n`
  66. ).join("\n");
  67. let Embed = new MessageEmbed()
  68. .setAuthor("Queue", client.config.IconURL)
  69. .setColor("RANDOM")
  70. .setDescription(
  71. `**Currently Playing:** \n[${player.queue.current.title}](${player.queue.current.uri}) \n\n**Up Next:** \n${SongsDescription}\n\n`
  72. )
  73. .addField("Total songs: \n", `\`${player.queue.totalSize - 1}\``, true)
  74. .addField(
  75. "Total length: \n",
  76. `\`${prettyMilliseconds(player.queue.duration, {
  77. colonNotation: true,
  78. })}\``,
  79. true
  80. )
  81. .addField("Requested by:", `${player.queue.current.requester}`, true)
  82. .addField(
  83. "Current song duration:",
  84. `${
  85. client.ProgressBar(
  86. player.position,
  87. player.queue.current.duration,
  88. 15
  89. ).Bar
  90. } \`${prettyMilliseconds(player.position, {
  91. colonNotation: true,
  92. })} / ${prettyMilliseconds(player.queue.current.duration, {
  93. colonNotation: true,
  94. })}\``
  95. )
  96. .setThumbnail(player.queue.current.displayThumbnail());
  97. return Embed;
  98. });
  99. if (!Pages.length || Pages.length === 1)
  100. return message.channel.send(Pages[0]);
  101. else client.Pagination(message, Pages);
  102. },
  103. SlashCommand: {
  104. /**
  105. *
  106. * @param {import("../structures/DiscordMusicBot")} client
  107. * @param {import("discord.js").Message} message
  108. * @param {string[]} args
  109. * @param {*} param3
  110. */
  111. run: async (client, interaction, args, { GuildDB }) => {
  112. let player = await client.Manager.get(interaction.guild_id);
  113. if (!player)
  114. return interaction.send("❌ | **Nothing is playing right now...**");
  115. if (!player.queue || !player.queue.length || player.queue === 0) {
  116. let QueueEmbed = new MessageEmbed()
  117. .setAuthor("Currently playing", client.config.IconURL)
  118. .setColor("RANDOM")
  119. .setDescription(
  120. `[${player.queue.current.title}](${player.queue.current.uri})`
  121. )
  122. .addField("Requested by", `${player.queue.current.requester}`, true)
  123. .addField(
  124. "Duration",
  125. `${
  126. client.ProgressBar(
  127. player.position,
  128. player.queue.current.duration,
  129. 15
  130. ).Bar
  131. } \`[${prettyMilliseconds(player.position, {
  132. colonNotation: true,
  133. })} / ${prettyMilliseconds(player.queue.current.duration, {
  134. colonNotation: true,
  135. })}]\``
  136. )
  137. .setThumbnail(player.queue.current.displayThumbnail());
  138. return interaction.send(QueueEmbed);
  139. }
  140. let Songs = player.queue.map((t, index) => {
  141. t.index = index;
  142. return t;
  143. });
  144. let ChunkedSongs = _.chunk(Songs, 10); //How many songs to show per-page
  145. let Pages = ChunkedSongs.map((Tracks) => {
  146. let SongsDescription = Tracks.map(
  147. (t) =>
  148. `\`${t.index + 1}.\` [${t.title}](${
  149. t.uri
  150. }) \n\`${prettyMilliseconds(t.duration, {
  151. colonNotation: true,
  152. })}\` **|** Requested by: ${t.requester}\n`
  153. ).join("\n");
  154. let Embed = new MessageEmbed()
  155. .setAuthor("Queue", client.config.IconURL)
  156. .setColor("RANDOM")
  157. .setDescription(
  158. `**Currently Playing:** \n[${player.queue.current.title}](${player.queue.current.uri}) \n\n**Up Next:** \n${SongsDescription}\n\n`
  159. )
  160. .addField(
  161. "Total songs: \n",
  162. `\`${player.queue.totalSize - 1}\``,
  163. true
  164. )
  165. .addField(
  166. "Total length: \n",
  167. `\`${prettyMilliseconds(player.queue.duration, {
  168. colonNotation: true,
  169. })}\``,
  170. true
  171. )
  172. .addField("Requested by:", `${player.queue.current.requester}`, true)
  173. .addField(
  174. "Current song duration:",
  175. `${
  176. client.ProgressBar(
  177. player.position,
  178. player.queue.current.duration,
  179. 15
  180. ).Bar
  181. } \`[${prettyMilliseconds(player.position, {
  182. colonNotation: true,
  183. })} / ${prettyMilliseconds(player.queue.current.duration, {
  184. colonNotation: true,
  185. })}]\``
  186. )
  187. .setThumbnail(player.queue.current.displayThumbnail());
  188. return Embed;
  189. });
  190. if (!Pages.length || Pages.length === 1)
  191. return interaction.send(Pages[0]);
  192. else client.Pagination(interaction, Pages);
  193. },
  194. },
  195. };