Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.18 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client();
  3. const ytdl = require('ytdl-core');
  4. const request = require('request');
  5. const fs = require('fs');
  6. const getYoutubeID = require('get-youtube-id');
  7. const fetchVideoInfo = require('youtube-info');
  8.  
  9.  
  10. const yt_api_key = "AIzaSyDeoIH0u1e72AtfpwSKKOSy3IPp2UHzqi4";
  11. const prefix = '!';
  12. const discord_token = "NTAxNDE3MTA1NjkwNzIyMzA0.DqZEsg.kk6pgIuQzA4LRcSZTGbGg8FOg1E";
  13. client.login(discord_token);
  14. client.on('ready', function() {
  15. console.log(`i am ready ${client.user.username}`);
  16. });
  17. /*
  18. ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
  19. ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
  20. ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
  21. ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
  22. */
  23. var servers = [];
  24. var queue = [];
  25. var guilds = [];
  26. var queueNames = [];
  27. var isPlaying = false;
  28. var dispatcher = null;
  29. var voiceChannel = null;
  30. var skipReq = 0;
  31. var skippers = [];
  32. var now_playing = [];
  33. /*
  34. \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
  35. \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
  36. \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
  37. \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
  38. */
  39.  
  40. client.on('ready', () => {
  41. client.user.setPresence({
  42. game: {
  43. name: '!play or !skip',
  44. type: 0
  45. }
  46. });
  47. });
  48. var download = function(uri, filename, callback) {
  49. request.head(uri, function(err, res, body) {
  50. console.log('content-type:', res.headers['content-type']);
  51. console.log('content-length:', res.headers['content-length']);
  52.  
  53. request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
  54. });
  55.  
  56. };
  57.  
  58. client.on('message', async message => {
  59. const member = message.member;
  60. const mess = message.content.toLowerCase();
  61. const args = message.content.split(' ').slice(1).join(' ');
  62.  
  63. if (mess.startsWith(prefix + 'play')) {
  64. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  65. // if user is not insert the URL or song title
  66. if (args.length == 0) {
  67. let play_info = new Discord.RichEmbed()
  68. .setAuthor(client.user.username, client.user.avatarURL)
  69. .setFooter('طلب بواسطة: ' + message.author.tag)
  70. .setDescription('**قم بإدراج رابط او اسم الأغنيه**')
  71. message.channel.sendEmbed(play_info)
  72. return;
  73. }
  74. if (queue.length > 0 || isPlaying) {
  75. getID(args, function(id) {
  76. add_to_queue(id);
  77. fetchVideoInfo(id, function(err, videoInfo) {
  78. if (err) throw new Error(err);
  79. let play_info = new Discord.RichEmbed()
  80. .setAuthor(client.user.username, client.user.avatarURL)
  81. .addField('تمت إضافةالاغنيه بقائمة الإنتظار', `**
  82. ${videoInfo.title}
  83. **`)
  84. .setColor("#a637f9")
  85. .setFooter('|| ' + message.author.tag)
  86. .setThumbnail(videoInfo.thumbnailUrl)
  87. message.channel.sendEmbed(play_info);
  88. queueNames.push(videoInfo.title);
  89. now_playing.push(videoInfo.title);
  90.  
  91. });
  92. });
  93. }
  94. else {
  95.  
  96. isPlaying = true;
  97. getID(args, async function(id) {
  98. queue.push('placeholder');
  99. playMusic(id, message);
  100. fetchVideoInfo(id, async function(err, videoInfo) {
  101. if (err) throw new Error(err);
  102. const msg = await message.channel.send(`**Searching for "${args}"**`);
  103. msg.edit(`**Now Playing: "${videoInfo.title}"**`);
  104. let play_info = new Discord.RichEmbed()
  105. .setAuthor(client.user.username, client.user.avatarURL)
  106. });
  107. });
  108. }
  109. }
  110. else if (mess.startsWith(prefix + 'skip')) {
  111. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  112. message.channel.send('`✔`').then(() => {
  113. skip_song(message);
  114. var server = server = servers[message.guild.id];
  115. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  116. });
  117. }
  118. else if (message.content.startsWith(prefix + 'vol')) {
  119. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  120. // console.log(args)
  121. if (args > 100) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
  122. if (args < 1) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
  123. dispatcher.setVolume(1 * args / 50);
  124. message.channel.sendMessage(`**__ ${dispatcher.volume*50}% مستوى الصوت __**`);
  125. }
  126. else if (mess.startsWith(prefix + 'pause')) {
  127. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  128. message.channel.send('`✔`').then(() => {
  129. dispatcher.pause();
  130. });
  131. }
  132. else if (mess.startsWith(prefix + 'ok')) {
  133. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  134. message.channel.send('`✔`').then(() => {
  135. dispatcher.resume();
  136. });
  137. }
  138. else if (mess.startsWith(prefix + 'stop')) {
  139. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  140. message.channel.send('`✔`');
  141. var server = server = servers[message.guild.id];
  142. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  143. }
  144. else if (mess.startsWith(prefix + 'تعال')) {
  145. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  146. message.member.voiceChannel.join().then(message.channel.send(':ok:'));
  147. }
  148. else if (mess.startsWith(prefix + 'play')) {
  149. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  150. if (isPlaying == false) return message.channel.send(':anger: || **__تم التوقيف__**');
  151. let playing_now_info = new Discord.RichEmbed()
  152. .setAuthor(client.user.username, client.user.avatarURL)
  153. .addField('تمت إضافةالاغنيه بقائمة الإنتظار', `**
  154. ${videoInfo.title}
  155. **`)
  156. .setColor("RANDOM")
  157. .setFooter('طلب بواسطة: ' + message.author.tag)
  158. .setThumbnail(videoInfo.thumbnailUrl)
  159. //.setDescription('?')
  160. message.channel.sendEmbed(playing_now_info);
  161. }
  162. });
  163.  
  164. function skip_song(message) {
  165. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  166. dispatcher.end();
  167. }
  168.  
  169. function playMusic(id, message) {
  170. voiceChannel = message.member.voiceChannel;
  171.  
  172.  
  173. voiceChannel.join().then(function(connectoin) {
  174. let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
  175. filter: 'audioonly'
  176. });
  177. skipReq = 0;
  178. skippers = [];
  179.  
  180. dispatcher = connectoin.playStream(stream);
  181. dispatcher.on('end', function() {
  182. skipReq = 0;
  183. skippers = [];
  184. queue.shift();
  185. queueNames.shift();
  186. if (queue.length === 0) {
  187. queue = [];
  188. queueNames = [];
  189. isPlaying = false;
  190. }
  191. else {
  192. setTimeout(function() {
  193. playMusic(queue[0], message);
  194. }, 500);
  195. }
  196. });
  197. });
  198. }
  199.  
  200. function getID(str, cb) {
  201. if (isYoutube(str)) {
  202. cb(getYoutubeID(str));
  203. }
  204. else {
  205. search_video(str, function(id) {
  206. cb(id);
  207. });
  208. }
  209. }
  210.  
  211. function add_to_queue(strID) {
  212. if (isYoutube(strID)) {
  213. queue.push(getYoutubeID(strID));
  214. }
  215. else {
  216. queue.push(strID);
  217. }
  218. }
  219.  
  220. function search_video(query, cb) {
  221. request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
  222. var json = JSON.parse(body);
  223. cb(json.items[0].id.videoId);
  224. });
  225. }
  226.  
  227.  
  228. function isYoutube(str) {
  229. return str.toLowerCase().indexOf('youtube.com') > -1;
  230. }
  231. client.on('message', message => {
  232. if (message.content === prefix +"help") {
  233. const embed = new Discord.RichEmbed()
  234. .setColor("RANDOM")
  235. .addField(`Zyad,aLmutairi commands:
  236.  
  237. +about - shows info about the bot
  238. +ping - checks the bot's latency
  239.  
  240. Music:
  241.  
  242. +play - shows the song that is currently playing
  243. +play <title|URL|subcommand> - plays the provided song
  244. +queue [pagenum] - shows the current queue
  245. +تعال <title|URL|subcommand> - plays the provided song
  246. +skip - votes to skip the current song
  247.  
  248. DJ:
  249. +ok <title|URL|subcommand> - plays the provided song
  250. +skip - skips the current song
  251. +pause - pauses the current song
  252. +skipt <position> - skips to the specified song
  253. +stop - stops the current song and clears the queue
  254. +vol [0-150] - sets or shows volume
  255.  
  256. For additional help, `)
  257.  
  258. message.channel.send({embed});
  259. }
  260. });
  261. client.on('message', message => {
  262. if (message.content.startsWith("habout")) {
  263. message.channel.send({
  264. embed: new Discord.RichEmbed()
  265. .setColor('RED')
  266. .addField('**الذاكرة المستخدمة 💾**', `${(process.memoryUsage().rss / 1000000).toFixed()}MB`, true)
  267. .addField('**سرعة الاتصال📡**' , `${Date.now() - message.createdTimestamp}` + ' ms')
  268. .addField('**وقت الاقلاع⌚**', timeCon(process.uptime()), true)
  269. .addField('**استخدام المعالج💿**', `${(process.cpuUsage().rss / 10000).toFixed()}%`, true)
  270. })
  271. }
  272. });
  273. client.on('message', message => {
  274. if(!message.channel.guild) return;
  275. if (message.content.startsWith('hping')) {
  276. if(!message.channel.guild) return;
  277. var msg = `${Date.now() - message.createdTimestamp}`
  278. var api = `${Math.round(client.ping)}`
  279. if (message.author.bot) return;
  280. let embed = new Discord.RichEmbed()
  281. .setAuthor(message.author.username,message.author.avatarURL)
  282. .setColor('RANDOM')
  283. .addField('**Time Taken:**',msg + " ms 📶 ")
  284. .addField('**WebSocket:**',api + " ms 📶 ")
  285. message.channel.send({embed:embed});
  286. }
  287. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement