Advertisement
Guest User

Untitled

a guest
May 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 KB | None | 0 0
  1. const ytdl = require("ytdl-core-discord");
  2. const Youtube = require("simple-youtube-api");
  3. const youtube = new Youtube(process.env.google_api_key);
  4. const fetchVideoInfo = require("youtube-info");
  5. const Discord = require("discord.js");
  6. const REGEX_URL = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/i
  7. const checkUrl = (url) => REGEX_URL.test(url)
  8.  
  9. module.exports = {
  10. run: async function (_, message, args) {
  11. const embed = new Discord.RichEmbed()
  12.  
  13. if (!message.member.voiceChannel) {
  14. return message.channel.send("Por favor, entre em um canal de voz primeiro!");
  15. } else if (!message.member.voiceChannel.permissionsFor(message.client.user).has("CONNECT")) {
  16. return message.channel.send(`» **${message.author.username}** | Desculpe, eu não tenho permissão para entrar neste canal! Permissão requirida: \`\`CONNECT\`\`.`);
  17. } else if (!message.member.voiceChannel.permissionsFor(message.client.user).has("SPEAK")) {
  18. return message.channel.send(`» **${message.author.username}** | Desculpe, eu não tenho permissão para trasmitir áudio neste canal! Permissão requirida: \`\`SPEAK\`\`.`);
  19. } else if (args.length === 0) {
  20. return message.channel.send("Insira uma URL do youtube, ou pesquisa uma musica pelo nome");
  21. } else {
  22. if (checkUrl(args[0])) {
  23. message.member.voiceChannel.join().then(async function(connection) {
  24. youtube.getVideo(args[0]).then(async function(video) {
  25. fetchVideoInfo(video.id).then(async function(videoInfo) {
  26. try {
  27. const stream = connection.playOpusStream(await ytdl(video.url));
  28. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  29. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  30. embed.addField("📈Visualizações", videoInfo.views, true)
  31. embed.addField("📝Comentários", videoInfo.commentCount, true)
  32. embed.addField("👍Likes", videoInfo.likeCount, true)
  33. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  34. embed.addField("⏰Duração da música", videoInfo.duration, true)
  35. embed.addField("🎭Gênero", videoInfo.genre, true)
  36. embed.setThumbnail(videoInfo.thumbnailUrl)
  37. embed.setTimestamp(new Date())
  38. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  39. embed.setColor("#e83127")
  40. message.channel.send(embed);
  41. stream.on('end', async () => {
  42. await message.member.voiceChannel.leave();
  43. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  44. });
  45. } catch(e) {
  46. message.channel.send("A URL que você inseriu está inválida.");
  47. console.log(e);
  48. }
  49. });
  50. });
  51. });
  52. } else {
  53. youtube.searchVideos(args.join(" "), 5).then(async function(search) {
  54. message.channel.send(`Você tem \`\`60s\`\` para escolher um número entre 1 a 5 para selecionar a música correspondente a pesquisa\n[1] - ${search[0].title}\n[2] - ${search[1].title}\n[3] - ${search[2].title}\n[4] - ${search[3].title}\n[5] - ${search[4].title}`).then(async (msg) => {
  55. await msg.react("1⃣");
  56. await msg.react("2⃣");
  57. await msg.react("3⃣");
  58. await msg.react("4⃣");
  59. await msg.react("5⃣");
  60.  
  61. const filter = (r, u) => r.me && u.id === message.author.id;
  62. const collector = msg.createReactionCollector(filter, {max: 1, time: 60 * 1000 });
  63.  
  64. collector.on("collect", async (r) => {
  65. msg.delete();
  66. switch (r.emoji.name) {
  67. case "1⃣":
  68. message.member.voiceChannel.join().then(async function(connection) {
  69. fetchVideoInfo(search[0].id).then(async function(videoInfo) {
  70. const stream2 = connection.playOpusStream(await ytdl(search[0].url));
  71. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  72. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  73. embed.addField("📈Visualizações", videoInfo.views, true)
  74. embed.addField("📝Comentários", videoInfo.commentCount, true)
  75. embed.addField("👍Likes", videoInfo.likeCount, true)
  76. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  77. embed.addField("⏰Duração da música", videoInfo.duration, true)
  78. embed.addField("🎭Gênero", videoInfo.genre, true)
  79. embed.setThumbnail(videoInfo.thumbnailUrl)
  80. embed.setTimestamp(new Date())
  81. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  82. embed.setColor("#e83127")
  83. message.channel.send(embed);
  84. stream2.on('end', async () => {
  85. await message.member.voiceChannel.leave();
  86. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  87. });
  88. });
  89. });
  90. break;
  91. case "2⃣":
  92. message.member.voiceChannel.join().then(async function(connection) {
  93. fetchVideoInfo(search[1].id).then(async function(videoInfo) {
  94. const stream3 = connection.playOpusStream(await ytdl(search[1].url));
  95. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  96. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  97. embed.addField("📈Visualizações", videoInfo.views, true)
  98. embed.addField("📝Comentários", videoInfo.commentCount, true)
  99. embed.addField("👍Likes", videoInfo.likeCount, true)
  100. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  101. embed.addField("⏰Duração da música", videoInfo.duration, true)
  102. embed.addField("🎭Gênero", videoInfo.genre, true)
  103. embed.setThumbnail(videoInfo.thumbnailUrl)
  104. embed.setTimestamp(new Date())
  105. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  106. embed.setColor("#e83127")
  107. message.channel.send(embed);
  108. stream3.on('end', async () => {
  109. await message.member.voiceChannel.leave();
  110. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  111. });
  112. });
  113. });
  114. break;
  115. case "3⃣":
  116. message.member.voiceChannel.join().then(async function(connection) {
  117. fetchVideoInfo(search[2].id).then(async function(videoInfo) {
  118. const stream4 = connection.playOpusStream(await ytdl(search[2].url));
  119. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  120. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  121. embed.addField("📈Visualizações", videoInfo.views, true)
  122. embed.addField("📝Comentários", videoInfo.commentCount, true)
  123. embed.addField("👍Likes", videoInfo.likeCount, true)
  124. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  125. embed.addField("⏰Duração da música", videoInfo.duration, true)
  126. embed.addField("🎭Gênero", videoInfo.genre, true)
  127. embed.setThumbnail(videoInfo.thumbnailUrl)
  128. embed.setTimestamp(new Date())
  129. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  130. embed.setColor("#e83127")
  131. message.channel.send(embed);
  132. stream4.on('end', async () => {
  133. await message.member.voiceChannel.leave();
  134. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  135. });
  136. });
  137. });
  138. break;
  139. case "4⃣":
  140. message.member.voiceChannel.join().then(async function(connection) {
  141. fetchVideoInfo(search[3].id).then(async function(videoInfo) {
  142. const stream5 = connection.playOpusStream(await ytdl(search[3].url));
  143. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  144. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  145. embed.addField("📈Visualizações", videoInfo.views, true)
  146. embed.addField("📝Comentários", videoInfo.commentCount, true)
  147. embed.addField("👍Likes", videoInfo.likeCount, true)
  148. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  149. embed.addField("⏰Duração da música", videoInfo.duration, true)
  150. embed.addField("🎭Gênero", videoInfo.genre, true)
  151. embed.setThumbnail(videoInfo.thumbnailUrl)
  152. embed.setTimestamp(new Date())
  153. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  154. embed.setColor("#e83127")
  155. message.channel.send(embed);
  156. stream5.on('end', async () => {
  157. await message.member.voiceChannel.leave();
  158. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  159. });
  160. });
  161. });
  162. break;
  163. case "5⃣":
  164. message.member.voiceChannel.join().then(async function(connection) {
  165. fetchVideoInfo(search[4].id).then(async function(videoInfo) {
  166. const stream6 = connection.playOpusStream(await ytdl(search[4].url));
  167. embed.addField("📀Música", `[${videoInfo.title}](${videoInfo.url})`)
  168. embed.addField("🎧Canal", `[${videoInfo.owner}](https://youtube.com/channel/${videoInfo.channelId})`)
  169. embed.addField("📈Visualizações", videoInfo.views, true)
  170. embed.addField("📝Comentários", videoInfo.commentCount, true)
  171. embed.addField("👍Likes", videoInfo.likeCount, true)
  172. embed.addField("👎Dislikes", videoInfo.dislikeCount, true)
  173. embed.addField("⏰Duração da música", videoInfo.duration, true)
  174. embed.addField("🎭Gênero", videoInfo.genre, true)
  175. embed.setThumbnail(videoInfo.thumbnailUrl)
  176. embed.setTimestamp(new Date())
  177. embed.setFooter(`Musica solicitada por ${message.author.tag}`, message.author.displayAvatarURL)
  178. embed.setColor("#e83127")
  179. message.channel.send(embed);;
  180. stream6.on('end', async () => {
  181. await message.member.voiceChannel.leave();
  182. await message.channel.send(`A Música terminou, saindo do canal \`\`${message.guild.me.voiceChannel.name}\`\``);
  183. });
  184. });
  185. });
  186. break;
  187. }
  188. });
  189. });
  190. });
  191. }
  192. }
  193. },
  194. aliases: ["tocar"],
  195. category: "Música",
  196. description: "Tocar uma música"
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement