Advertisement
iBeAnthonyD

music code

Apr 18th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //music//
  2. const ytdl = require("ytdl-core");
  3. const { Client, Util } = require('discord.js');
  4. const getYoutubeID = require('get-youtube-id');
  5. const fetchVideoInfo = require('youtube-info');
  6. const YouTube = require('simple-youtube-api');
  7. const youtube = new YouTube("AIzaSyAdORXg7UZUo7sePv97JyoDqtQVi3Ll0b8");//youtube api key
  8. const queue = new Map();//the queue m
  9.  
  10. //All copytights for Eyad & (old) Codes
  11.  
  12. /*
  13. Packages
  14. npm install discord.js
  15. npm install ytdl-core
  16. npm install get-youtube-id
  17. npm install youtube-info
  18. npm install simple-youtube-api
  19. npm install queue
  20. */
  21.  
  22. client.on('message', async msg => {
  23.     if (msg.author.bot) return undefined;
  24.     if (!msg.content.startsWith(prefix)) return undefined;
  25.     const args = msg.content.split(' ');
  26.     const searchString = args.slice(1).join(' ');
  27.     const url = args[1] ? args[1] .replace(/<(.+)>/g, 's!1') : '';
  28.     const serverQueue = queue.get(msg.guild.id);
  29.     let command = msg.content.toLowerCase().split(" ")[0];
  30.     command = command.slice(prefix.length)
  31.     if (command === `play`) {
  32.         const voiceChannel = msg.member.voiceChannel;
  33.         if (!voiceChannel) return msg.channel.send('join a Voice Channel first');
  34.         const permissions = voiceChannel.permissionsFor(msg.client.user);
  35.         if (!permissions.has('CONNECT')) {
  36.             return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  37.         }
  38.         if (!permissions.has('SPEAK')) {
  39.             return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  40.         }
  41.  
  42.         if (!permissions.has('EMBED_LINKS')) {
  43.             return msg.channel.sendMessage("**يجب توآفر برمشن `EMBED LINKS`لدي **rl")
  44.             }
  45.  
  46.         if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  47.             const playlist = await youtube.getPlaylist(url);
  48.             const videos = await playlist.getVideos();
  49.             for (const video of Object.values(videos)) {
  50.                 const video2 = await youtube.getVideoByID(video.id);
  51.                 await handleVideo(video2, msg, voiceChannel, true);
  52.             }
  53.             return msg.channel.send(` **${playlist.title}** تم الإضآفة إلى قأئمة التشغيل`);
  54.         } else {
  55.             try {
  56.  
  57.                 var video = await youtube.getVideo(url);
  58.  
  59.             } catch (error) {
  60.                 try {
  61.                                      var fast = {};
  62.                     var videos = await youtube.searchVideos(searchString, 10);
  63.                     let index = 0;
  64.                     const embed1 = new Discord.RichEmbed()
  65.              .setDescription(`**الرجآء من حضرتك إختيآر رقم المقطع** :
  66. ${videos.map(video2 => `[**${++index}**] **${video2.title}**`).join('\n')}`)
  67.                     .setFooter(`${msg.guild.name}`)
  68.                     msg.channel.sendEmbed(embed1).then(message =>{
  69.  
  70.                         message.delete(15000)
  71.  
  72.                     });
  73.                     try {
  74.                         var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  75.                             maxMatches: 1,
  76.                             time: 20000,
  77.                             errors: ['time']
  78.                         })
  79.  
  80.                         }catch(err) {
  81.                         console.error(err);
  82.                         return msg.channel.send('لم يتم إختيآر مقطع صوتي');
  83.                         }
  84.                     const videoIndex = parseInt(response.first().content);
  85.                     var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  86.                 } catch (err) {
  87.                     console.error(err);
  88.                     return msg.channel.send(':x: لا يتوفر نتآئج بحث ');
  89.                 }
  90.         }
  91.  
  92.             return handleVideo(video, msg, voiceChannel);
  93.         }
  94.     } else if (command === `skip`) {
  95.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  96.         if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لتجآوزه');
  97.         serverQueue.connection.dispatcher.end('تم تجآوز هذآ المقطع');
  98.         return undefined;
  99.     } else if (command === `stop`) {
  100.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  101.         if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لإيقآفه');
  102.         serverQueue.songs = [];
  103.         serverQueue.connection.dispatcher.end('تم إيقآف هذآ المقطع');
  104.         return undefined;
  105.     } else if (command === `vol`) {
  106.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  107.         if (!serverQueue) return msg.channel.send('لا يوجد شيء شغآل.');
  108.         if (!args[1]) return msg.channel.send(`:loud_sound: مستوى الصوت **${serverQueue.volume}**`);
  109.         serverQueue.volume = args[1];
  110.         serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 50);
  111.         return msg.channel.send(`:speaker: تم تغير الصوت الي **${args[1]}**`);
  112.     } else if (command === `np`) {
  113.         if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  114.         const embedNP = new Discord.RichEmbed()
  115.     .setDescription(`:notes: الان يتم تشغيل : **${serverQueue.songs[0].title}**`)
  116.         return msg.channel.sendEmbed(embedNP);
  117.     } else if (command === `replay`) {
  118.         if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  119.         const embedNP = new Discord.RichEmbed()
  120.     .setDescription(`سيتم اعاده تشغيل الفديو :**${serverQueue.songs[0].title}**`)
  121.     msg.channel.send({embed: embedNP})
  122.      return handleVideo(video, msg, msg.member.voiceChannel);
  123.  
  124.     } else if (command === `queue`) {
  125.         if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  126.         let index = 0;
  127.         const embedqu = new Discord.RichEmbed()
  128. .setDescription(`**Songs Queue**
  129. ${serverQueue.songs.map(song => `**${++index} -** ${song.title}`).join('\n')}
  130. **الان يتم تشغيل** ${serverQueue.songs[0].title}`)
  131.         return msg.channel.sendEmbed(embedqu);
  132.     } else if (command === `pause`) {
  133.         if (serverQueue && serverQueue.playing) {
  134.             serverQueue.playing = false;
  135.             serverQueue.connection.dispatcher.pause();
  136.             return msg.channel.send('تم إيقاف الموسيقى مؤقتا!');
  137.         }
  138.         return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  139.     } else if (command === "resume") {
  140.         if (serverQueue && !serverQueue.playing) {
  141.             serverQueue.playing = true;
  142.             serverQueue.connection.dispatcher.resume();
  143.             return msg.channel.send('استأنفت الموسيقى بالنسبة لك !');
  144.         }
  145.         return msg.channel.send('لا يوجد شيء حالي في العمل.');
  146.     }
  147.  
  148.     return undefined;
  149. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  150.     const serverQueue = queue.get(msg.guild.id);
  151.     const song = {
  152.         id: video.id,
  153.         title: Util.escapeMarkdown(video.title),
  154.         url: `https://www.youtube.com/watch?v=${video.id}`,
  155.         time:`${video.duration.hours}:${video.duration.minutes}:${video.duration.seconds}`,
  156.         eyad:`${video.thumbnails.high.url}`,
  157.         best:`${video.channel.title}`,
  158.         bees:`${video.raw.snippet.publishedAt}`,
  159.         shahd:`${video.raw.kind}`,
  160.         zg:`${video.raw.snippet.channelId}`,
  161. views:`${video.raw.views}`,
  162. like:`${video.raw.likeCount}`,
  163. dislike:`${video.raw.dislikeCount}`,
  164. hi:`${video.raw.id}`
  165.     };
  166.     if (!serverQueue) {
  167.         const queueConstruct = {
  168.             textChannel: msg.channel,
  169.             voiceChannel: voiceChannel,
  170.             connection: null,
  171.             songs: [],
  172.             volume: 5,
  173.             playing: true
  174.         };
  175.         queue.set(msg.guild.id, queueConstruct);
  176.         queueConstruct.songs.push(song);
  177.         try {
  178.             var connection = await voiceChannel.join();
  179.             queueConstruct.connection = connection;
  180.             play(msg.guild, queueConstruct.songs[0]);
  181.         } catch (error) {
  182.             console.error(`I could not join the voice channel: ${error}`);
  183.             queue.delete(msg.guild.id);
  184.             return msg.channel.send(`لا أستطيع دخول هذآ الروم ${error}`);
  185.         }
  186.     } else {
  187.         serverQueue.songs.push(song);
  188.         console.log(serverQueue.songs);
  189.         if (playlist) return undefined;
  190.         else return msg.channel.send(` **${song.title}** تم اضافه الاغنية الي القائمة!`);
  191.     }
  192.     return undefined;
  193. }
  194.  
  195. function play(guild, song) {
  196.     const serverQueue = queue.get(guild.id);
  197.  
  198.     if (!song) {
  199.         serverQueue.voiceChannel.leave();
  200.         queue.delete(guild.id);
  201.         return;
  202.     }
  203.     console.log(serverQueue.songs);
  204.     const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  205.         .on('end', reason => {
  206.             if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  207.             else console.log(reason);
  208.             serverQueue.songs.shift();
  209.             play(guild, serverQueue.songs[0]);
  210.         })
  211.         .on('error', error => console.error(error));
  212.     dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  213.         fetchVideoInfo(`${song.hi}`, function (err, idk) {
  214. if (err) throw new Error(err);
  215. console.log( idk);
  216.      const yyyy = {}
  217. if(!yyyy[msg.guild.id]) yyyy[msg.guild.id] = {
  218. like: `${ idk.likeCount}`,
  219. dislike: `${ idk.dislikeCount}`
  220. }
  221.     serverQueue.textChannel.send({embed : new Discord.RichEmbed()
  222. .setTitle(`${ idk.title}`)
  223. .setURL( idk.url)
  224. .addField('مدة المقطع:' , `${song.time}`, true)
  225. .addField('اسم القناة:' , `${song.best}`, true)
  226. .addField('هوية القناة:' , `${song.zg}`, true)
  227. .addField('تم صنع الفيديو في:' , `${ idk.datePublished}`, true)
  228. .addField('المشاهدات:' , `${ idk.views}`, true)
  229. .addField('اعجب فيها:' , `${ idk.likeCount}`, true)
  230. .addField('لم يعجب فيها:' , `${ idk.dislikeCount}`, true)
  231. .addField('عدد التعليقات:' , `${ idk.commentCount}`, true)
  232.     .setImage(`${song.eyad}`)
  233.     .setThumbnail('http://cdn.akhbaar24.com/430e061a-f89a-43c7-86d9-82fae5f7c495.jpg')
  234.     .setColor('#ff0000')
  235.     .setTimestamp()
  236.     }).then(love => {
  237.         love.react('👍').then(r=>{
  238.         love.react('👎').then(r =>{
  239.         love.react('🙌').then(r=> {
  240. let likee = (reaction, user) => reaction.emoji.name === '👍' && user.id === msg.author.id;
  241. let dislikee = (reaction, user) => reaction.emoji.name === '👎' && user.id === msg.author.id;
  242. let cnn = (reaction, user) => reaction.emoji.name === '🙌' && user.id === msg.author.id;
  243.  
  244. let ll = love.createReactionCollector(likee , {max:5});
  245. let dd = love.createReactionCollector(dislikee , {max:5});
  246. let cn = love.createReactionCollector(cnn , {max:5});
  247.  
  248.          ll.on("collect", r => {
  249.          yyyy[msg.guild.id].like++;
  250.     love.edit({embed : new Discord.RichEmbed()
  251. .setTitle(`**${ idk.title}**`)
  252. .setURL( idk.url)
  253. .addField('Time The Video :' , `${song.time}`, true)
  254. .addField('Channel Name :' , `${song.best}`, true)
  255. .addField('Channel ID :' , `${song.zg}`, true)
  256. .addField('Video Created at :' , `${ idk.datePublished}`, true)
  257. .addField('Views :' , `${ idk.views}`, true)
  258. .addField('Like👍 :' , `${yyyy[msg.guild.id].like}`, true)
  259. .addField('dislike👎 :' , `${ idk.dislikeCount}`, true)
  260. .addField('comments :' , `${ idk.commentCount}`, true)
  261.     .setImage(`${song.eyad}`)
  262.     .setThumbnail('http://cdn.akhbaar24.com/430e061a-f89a-43c7-86d9-82fae5f7c495.jpg')
  263.     .setColor('#ff0000')
  264.     .setTimestamp()
  265. });
  266. })
  267.  
  268. dd.on("collect", r => {
  269. yyyy[msg.guild.id].dislike++;
  270.     love.edit({embed : new Discord.RichEmbed()
  271. .setTitle(`**${ idk.title}**`)
  272. .setURL( idk.url)
  273. .addField('Time The Video :' , `${song.time}`, true)
  274. .addField('Channel Name :' , `${song.best}`, true)
  275. .addField('Channel ID :' , `${song.zg}`, true)
  276. .addField('Video Created at :' , `${ idk.datePublished}`, true)
  277. .addField('Views :' , `${ idk.views}`, true)
  278. .addField('Like👍 :' , `${ idk.likeCount}`, true)
  279. .addField('dislike👎 :' , `${yyyy[msg.guild.id].dislike}`, true)
  280. .addField('comments :' , `${ idk.commentCount}`, true)
  281.     .setImage(`${song.eyad}`)
  282.     .setThumbnail('http://cdn.akhbaar24.com/430e061a-f89a-43c7-86d9-82fae5f7c495.jpg')
  283.     .setColor('#ff0000')
  284.     .setTimestamp()
  285. });
  286. })
  287. cn.on("collect", r => {
  288.     love.edit({embed : new Discord.RichEmbed()
  289. .setTitle(`**${ idk.title}**`)
  290. .setURL( idk.url)
  291. .addField('Time The Video :' , `${song.time}`, true)
  292. .addField('Channel Name :' , `${song.best}`, true)
  293. .addField('Channel ID :' , `${song.zg}`, true)
  294. .addField('Video Created at :' , `${ idk.datePublished}`, true)
  295. .addField('Views :' , `${ idk.views}`, true)
  296. .addField('Like👍 :' , `${ idk.likeCount}`, true)
  297. .addField('dislike👎 :' , `${ idk.dislikeCount}`, true)
  298. .addField('comments :' , `${ idk.commentCount}`, true)
  299.     .setImage(`${song.eyad}`)
  300.     .setThumbnail('http://cdn.akhbaar24.com/430e061a-f89a-43c7-86d9-82fae5f7c495.jpg')
  301.     .setColor('#ff0000')
  302.     .setTimestamp()
  303. });
  304. })
  305. })
  306. })
  307. })
  308. })
  309. })
  310. }
  311. });
  312. //https//
  313. const http = require('http');
  314. var express = require('express');
  315. const app = express();
  316. app.get("/", (request, response) => {
  317.   response.sendStatus(200);
  318. });
  319. app.listen(process.env.PORT);
  320. setInterval(() => {
  321.   http.get(`http://project.glitch.me/`);
  322. }, 280000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement