Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. play: (msg) => {
  2. if (queue[msg.guild.id] === undefined) return msg.channel.send(`Add some songs to the queue first with !add`);
  3. if (!msg.guild.voiceConnection) return commands.join(msg).then(() => commands.play(msg));
  4. if (queue[msg.guild.id].playing) return msg.channel.send('Already Playing');
  5. let dispatcher;
  6. queue[msg.guild.id].playing = true;
  7.  
  8. console.log(queue);
  9. (function play(song) {
  10. console.log(song);
  11. if (song === undefined) return msg.channel.send('Queue is empty').then(() => {
  12. queue[msg.guild.id].playing = false;
  13. msg.member.voiceChannel.leave();
  14. });
  15. msg.channel.send(`Playing: **${song.title}** as requested by: **${song.requester}**`);
  16. dispatcher = msg.guild.voiceConnection.playStream(yt(song.url, { audioonly: true }), { passes : 1 });
  17. // let collector = msg.channel.createCollector(m => m);
  18. // collector.on('message', m => {
  19. // if (m.content.startsWith('!pause')) {
  20. // msg.channel.send('paused').then(() => {dispatcher.pause();});
  21. // } else if (m.content.startsWith('!resume')){
  22. // msg.channel.send('resumed').then(() => {dispatcher.resume();});
  23. // } else if (m.content.startsWith('!skip')){
  24. // msg.channel.send('skipped').then(() => {dispatcher.end();});
  25. // } else if (m.content.startsWith('volume+')){
  26. // if (Math.round(dispatcher.volume*50) >= 100) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`);
  27. // dispatcher.setVolume(Math.min((dispatcher.volume*50 + (2*(m.content.split('+').length-1)))/50,2));
  28. // msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`);
  29. // } else if (m.content.startsWith('volume-')){
  30. // if (Math.round(dispatcher.volume*50) <= 0) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`);
  31. // dispatcher.setVolume(Math.max((dispatcher.volume*50 - (2*(m.content.split('-').length-1)))/50,0));
  32. // msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`);
  33. // } else if (m.content.startsWith('!time')){
  34. // msg.channel.send(`time: ${Math.floor(dispatcher.time / 60000)}:${Math.floor((dispatcher.time % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.time % 60000)/1000) : Math.floor((dispatcher.time % 60000)/1000)}`);
  35. // }
  36. // });
  37. dispatcher.on('end', () => {
  38. collector.stop();
  39. play(queue[msg.guild.id].songs.shift());
  40. });
  41. dispatcher.on('error', (err) => {
  42. return msg.channel.send('error: ' + err).then(() => {
  43. collector.stop();
  44. play(queue[msg.guild.id].songs.shift());
  45. });
  46. });
  47. })(queue[msg.guild.id].songs.shift());
  48. },
  49. join: (msg) => {
  50. return new Promise((resolve, reject) => {
  51. const voiceChannel = msg.member.voiceChannel;
  52. if (!voiceChannel || voiceChannel.type !== 'voice'){
  53. msg.reply('I couldn\'t connect to your voice channel...');
  54. }else {
  55. voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err));
  56. }
  57. });
  58. },
  59. add: (msg) => {
  60. let url = msg.content.split(' ')[1];
  61. if (url == '' || url === undefined) return msg.channel.send(`You must add a YouTube video url, or id after !add`);
  62. yt.getInfo(url, (err, info) => {
  63. if(err) return msg.channel.send('Invalid YouTube Link: ' + err);
  64. if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
  65. queue[msg.guild.id].songs.push({url: url, title: info.title, requester: msg.author.username});
  66. msg.channel.send(`added **${info.title}** to the queue`);
  67. });
  68. },
  69. queue: (msg) => {
  70. if (queue[msg.guild.id] === undefined) return msg.channel.send(`Add some songs to the queue first with !add`);
  71. let tosend = [];
  72. queue[msg.guild.id].songs.forEach((song, i) => { tosend.push(`${i+1}. ${song.title} - Requested by: ${song.requester}`);});
  73. msg.channel.send(`__**${msg.guild.name}'s Music Queue:**__ Currently **${tosend.length}** songs queued ${(tosend.length > 15 ? '*[Only next 15 shown]*' : '')}\n\`\`\`${tosend.slice(0,15).join('\n')}\`\`\``);
  74. },
  75. help: (msg) => {
  76. let tosend = ['```xl', '!join : "Join Voice channel of msg sender"', '!add : "Add a valid youtube link to the queue"', '!queue : "Shows the current queue, up to 15 songs shown."', '!play : "Play the music queue if already joined to a voice channel"', '', 'the following commands only function while the play command is running:'.toUpperCase(), '!pause : "pauses the music"', '!resume : "resumes the music"', '!skip : "skips the playing song"', '!time : "Shows the playtime of the song."', 'volume+(+++) : "increases volume by 2%/+"', 'volume-(---) : "decreases volume by 2%/-"', '```'];
  77. msg.channel.send(tosend.join('\n'));
  78. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement