Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.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. const http2 = require('http2');
  9.  
  10.  
  11. const yt_api_key = "AIzaSyAyTW85_mLhJCH4WDIlXBHe2UO5RpAVJMQ";
  12. const prefix = '!!';
  13. const discord_token = "MzYxMjM1MDg5NTY2NDY2MDQ4.DRKZ1w.AJ11RcdyHd6z10FfeMtb3m3E7K4";
  14. client.login(discord_token);
  15. client.on('ready', function() {
  16. console.log(`Logged in as * [ " ${client.user.username} " ]`);
  17. console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
  18. console.log('By : #jrjer Team ');
  19. console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
  20. console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
  21.  
  22. });
  23.  
  24. var servers = ['351519476879196174','351519138566373386','250642763094294528','372737066536140820','342590736090529794','352297008696000512','','','','','','','','',''];
  25. var queue = [];
  26. var guilds = ['',''];
  27. var queueNames = [];
  28. var isPlaying = false;
  29. var dispatcher = null;
  30. var voiceChannel = null;
  31. var skipReq = 0;
  32. var skippers = [];
  33. var now_playing = [];
  34.  
  35. client.on('ready', () => {
  36.  
  37. client.user.setGame(` | !!play`,'https://www.twitch.tv/mixclann')
  38. client.user.setStatus("online");
  39. });
  40.  
  41.  
  42. client.on('ready', () => {});
  43. var download = function(uri, filename, callback) {
  44. request.head(uri, function(err, res, body) {
  45. console.log('content-type:', res.headers['content-type']);
  46. console.log('content-length:', res.headers['content-length']);
  47.  
  48. request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
  49. });
  50. };
  51.  
  52. client.on('message', function(message) {
  53. const member = message.member;
  54. const mess = message.content.toLowerCase();
  55. const args = message.content.split(' ').slice(1).join(' ');
  56.  
  57. if (mess.startsWith(prefix + 'شغل')) {
  58. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
  59. // if user is not insert the URL or song title
  60. if (args.length == 0) {
  61. let play_info = new Discord.RichEmbed()
  62. .setAuthor(client.user.username, client.user.avatarURL)
  63. .setFooter('طلب بواسطة: ' + message.author.tag)
  64. .setDescription('**قم بإدراج رابط او اسم الأغنيه**')
  65. message.channel.sendEmbed(play_info)
  66. return;
  67.  
  68. }
  69. }
  70. else if (mess.startsWith(prefix + 'تخطي')) {
  71. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** يجب ان تكون في روم صوتي**');
  72. message.channel.send(':ok:').then(() => {
  73. skip_song(message);
  74. var server = server = servers[message.guild.id];
  75. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  76. });
  77. }
  78. else if (message.content.startsWith(prefix + 'صوت')) {
  79. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  80. // console.log(args)
  81. if (args > 100) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
  82. if (args < 1) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
  83. dispatcher.setVolume(1 * args / 50);
  84. message.channel.sendMessage(`** ${dispatcher.volume*50}% مستوى الصوت **`);
  85. }
  86. else if (mess.startsWith(prefix + 'وقف')) {
  87. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  88. message.channel.send(':ok:').then(() => {
  89. dispatcher.pause();
  90. });
  91. }
  92. else if (mess.startsWith(prefix + 'كمل')) {
  93. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  94. message.channel.send(':ok:').then(() => {
  95. dispatcher.resume();
  96. });
  97. }
  98. else if (mess.startsWith(prefix + 'اطلع')) {
  99. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  100. message.channel.send(':ok:');
  101. var server = server = servers[message.guild.id];
  102. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  103. }
  104. else if (mess.startsWith(prefix + 'ادخل')) {
  105. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  106. message.member.voiceChannel.join().then(message.channel.send(':ok:'));
  107. }
  108. else if (mess.startsWith(prefix + 'شغل')) {
  109. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  110. if (isPlaying == false) return message.channel.send(':anger: || **تم التوقيف**');
  111. let playing_now_info = new Discord.RichEmbed()
  112. .setAuthor(client.user.username, client.user.avatarURL)
  113. .addField('تمت إضافة الـأغنيه بقائمة الإنتظار', `**
  114. ${videoInfo.title}
  115. **`)
  116. .setColor("RANDOM")
  117. .setFooter('طلب بواسطة: ' + message.author.tag)
  118. .setThumbnail(videoInfo.thumbnailUrl)
  119. //.setDescription('?')
  120. message.channel.sendEmbed(playing_now_info);
  121. }
  122. });
  123.  
  124. function skip_song(message) {
  125. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
  126. dispatcher.end();
  127. }
  128.  
  129. function playMusic(id, message) {
  130. voiceChannel = message.member.voiceChannel;
  131.  
  132.  
  133. voiceChannel.join().then(function(connectoin) {
  134. let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
  135. filter: 'audioonly'
  136. });
  137. skipReq = 0;
  138. skippers = [];
  139.  
  140. dispatcher = connectoin.playStream(stream);
  141. dispatcher.on('end', function() {
  142. skipReq = 0;
  143. skippers = [];
  144. queue.shift();
  145. queueNames.shift();
  146. if (queue.length === 0) {
  147. queue = [];
  148. queueNames = [];
  149. isPlaying = false;
  150. }
  151. else {
  152. setTimeout(function() {
  153. playMusic(queue[0], message);
  154. }, 500);
  155. }
  156. });
  157. });
  158. }
  159.  
  160. function getID(str, cb) {
  161. if (isYoutube(str)) {
  162. cb(getYoutubeID(str));
  163. }
  164. else {
  165. search_video(str, function(id) {
  166. cb(id);
  167. });
  168. }
  169. }
  170.  
  171. function add_to_queue(strID) {
  172. if (isYoutube(strID)) {
  173. queue.push(getYoutubeID(strID));
  174. }
  175. else {
  176. queue.push(strID);
  177. }
  178. }
  179.  
  180. function search_video(query, cb) {
  181. request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
  182. try {
  183. var json = JSON.parse(body);
  184. cb(json.items[0].id.videoId);
  185. } catch (e) {
  186. cb('EgqUJOudrcM');
  187. return;
  188.  
  189. console.error(e);
  190.  
  191. }
  192. });
  193. }
  194.  
  195.  
  196. function isYoutube(str) {
  197. return str.toLowerCase().indexOf('youtube.com') > -1;
  198. }
  199.  
  200. client.on('ready', () => {});
  201. var download = function(uri, filename, callback) {
  202. request.head(uri, function(err, res, body) {
  203. console.log('content-type:', res.headers['content-type']);
  204. console.log('content-length:', res.headers['content-length']);
  205.  
  206. request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
  207. });
  208. };
  209.  
  210. client.on('message', function(message) {
  211. const member = message.member;
  212. const mess = message.content.toLowerCase();
  213. const args = message.content.split(' ').slice(1).join(' ');
  214.  
  215. if (mess.startsWith(prefix + 'play')) {
  216. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  217. // if user is not insert the URL or song title
  218. if (args.length == 0) {
  219. let play_info = new Discord.RichEmbed()
  220. .setAuthor(client.user.username, client.user.avatarURL)
  221. .setFooter('request by : ' + message.author.tag)
  222. .setDescription('**Please enter a song name or Link**')
  223. message.channel.sendEmbed(play_info)
  224. return;
  225. }
  226. if (queue.length > 0 || isPlaying) {
  227. getID(args, function(id) {
  228. add_to_queue(id);
  229. fetchVideoInfo(id, function(err, videoInfo) {
  230. if (err) throw new Error(err);
  231. let play_info = new Discord.RichEmbed()
  232. .setAuthor(client.user.username, client.user.avatarURL)
  233. .addField('The song has been added to the waiting list', `**
  234. ${videoInfo.title}
  235. **`)
  236. .setColor("RANDOM")
  237. .setFooter('|| ' + message.author.tag)
  238. .setThumbnail(videoInfo.thumbnailUrl)
  239. message.channel.sendEmbed(play_info);
  240. queueNames.push(videoInfo.title);
  241. now_playing.push(videoInfo.title);
  242.  
  243. });
  244. });
  245. }
  246. else {
  247.  
  248. isPlaying = true;
  249. getID(args, function(id) {
  250. queue.push('placeholder');
  251. playMusic(id, message);
  252. fetchVideoInfo(id, function(err, videoInfo) {
  253. if (err) throw new Error(err);
  254. let play_info = new Discord.RichEmbed()
  255. .setAuthor(client.user.username, client.user.avatarURL)
  256. .addField('||** Playing **', `**${videoInfo.title}
  257. **`)
  258. .setColor("RANDOM")
  259. .addField(`By : ${message.author.username}`, `**jrjer Team**`)
  260. .setThumbnail(videoInfo.thumbnailUrl)
  261.  
  262. // .setDescription('?')
  263. message.channel.sendEmbed(play_info)
  264. // client.user.setGame(videoInfo.title,'https://www.twitch.tv/Abdulmohsen');
  265. });
  266. });
  267. }
  268. }
  269. else if (mess.startsWith(prefix + 'skip')) {
  270. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  271. message.channel.send(':ok:').then(() => {
  272. skip_song(message);
  273. var server = server = servers[message.guild.id];
  274. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  275. });
  276. }
  277. else if (message.content.startsWith(prefix + 'vol')) {
  278. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  279. // console.log(args)
  280. if (args > 100) return message.channel.send('1 - 100')
  281. if (args < 1) return message.channel.send('1 - 100')
  282. dispatcher.setVolume(1 * args / 50);
  283. message.channel.sendMessage(`** ${dispatcher.volume*50}% volume **`);
  284. }
  285. else if (mess.startsWith(prefix + 'stop')) {
  286. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  287. message.channel.send(':ok:').then(() => {
  288. dispatcher.pause();
  289. });
  290. }
  291. else if (mess.startsWith(prefix + 'ruseme')) {
  292. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** Must BE at a voice channel**');
  293. message.channel.send(':ok:').then(() => {
  294. dispatcher.resume();
  295. });
  296. }
  297. else if (mess.startsWith(prefix + 'go')) {
  298. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  299. message.channel.send(':ok:');
  300. var server = server = servers[message.guild.id];
  301. if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
  302. }
  303. else if (mess.startsWith(prefix + 'join')) {
  304. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** Must BE at a voice channel **');
  305. message.member.voiceChannel.join().then(message.channel.send(':ok:'));
  306. }
  307. else if (mess.startsWith(prefix + 'play')) {
  308. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  309. if (isPlaying == false) return message.channel.send(':anger: || **Stoped**');
  310. let playing_now_info = new Discord.RichEmbed()
  311. .setAuthor(client.user.username, client.user.avatarURL)
  312. .addField('Playing:', `**
  313. ${videoInfo.title}
  314. **`)
  315. .setColor("RANDOM")
  316. .setFooter('request By : ' + message.author.tag)
  317. .setThumbnail(videoInfo.thumbnailUrl)
  318. //.setDescription('?')
  319. message.channel.sendEmbed(playing_now_info);
  320. }
  321. });
  322.  
  323. function skip_song(message) {
  324. if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
  325. dispatcher.end();
  326. }
  327.  
  328. function playMusic(id, message) {
  329. voiceChannel = message.member.voiceChannel;
  330.  
  331.  
  332. voiceChannel.join().then(function(connectoin) {
  333. let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
  334. filter: 'audioonly'
  335. });
  336. skipReq = 0;
  337. skippers = [];
  338.  
  339. dispatcher = connectoin.playStream(stream);
  340. dispatcher.on('end', function() {
  341. skipReq = 0;
  342. skippers = [];
  343. queue.shift();
  344. queueNames.shift();
  345. if (queue.length === 0) {
  346. queue = [];
  347. queueNames = [];
  348. isPlaying = false;
  349. }
  350. else {
  351. setTimeout(function() {
  352. playMusic(queue[0], message);
  353. }, 500);
  354. }
  355. });
  356. });
  357. }
  358.  
  359. function getID(str, cb) {
  360. if (isYoutube(str)) {
  361. cb(getYoutubeID(str));
  362. }
  363. else {
  364. search_video(str, function(id) {
  365. cb(id);
  366. });
  367. }
  368. }
  369.  
  370. function add_to_queue(strID) {
  371. if (isYoutube(strID)) {
  372. queue.push(getYoutubeID(strID));
  373. }
  374. else {
  375. queue.push(strID);
  376. }
  377. }
  378.  
  379. function search_video(query, cb) {
  380. request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
  381. try {
  382. var json = JSON.parse(body);
  383. cb(json.items[0].id.videoId);
  384. } catch (e) {
  385. cb('EgqUJOudrcM');
  386. return;
  387.  
  388. console.error(e);
  389.  
  390. }
  391. });
  392. }
  393.  
  394.  
  395.  
  396. function isYoutube(str) {
  397. return str.toLowerCase().indexOf('youtube.com') > -1;
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement