forked from embee/woomy
		
	queue
This commit is contained in:
		
							parent
							
								
									89dc88d786
								
							
						
					
					
						commit
						d85a10c7d0
					
				
					 1 changed files with 39 additions and 17 deletions
				
			
		| 
						 | 
					@ -88,37 +88,45 @@ module.exports = client => {
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client.music.play = async function(message, query) {
 | 
					  client.music.play = async function(message, query, ignoreQueue) {
 | 
				
			||||||
    let guild = client.music.getGuild(message.guild.id);
 | 
					    let guild = client.music.getGuild(message.guild.id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!message.member.voice.channel && !guild.voiceChannel) {
 | 
					    if(!message.member.voice.channel && !guild.voiceChannel) {
 | 
				
			||||||
      return message.member.reply('you are not in a voice channel!');
 | 
					      return message.reply('you are not in a voice channel!');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let vc = message.member.voice.channel;
 | 
					    let vc = message.member.voice.channel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let video = await client.music.getVideoByQuery(query);
 | 
					    let video;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if(!ignoreQueue) {
 | 
				
			||||||
 | 
					      video = await client.music.getVideoByQuery(query);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(video) {
 | 
					    if(video || ignoreQueue) {
 | 
				
			||||||
      // Fix the bot if somehow broken
 | 
					      if(!ignoreQueue) {
 | 
				
			||||||
      // music "playing", nothing in queue
 | 
					        // Fix the bot if somehow broken
 | 
				
			||||||
      if((guild.playing || guild.dispatcher) && guild.queue.length == 0) {
 | 
					        // music "playing", nothing in queue
 | 
				
			||||||
        guild.playing = false;
 | 
					        if((guild.playing || guild.dispatcher) && guild.queue.length == 0) {
 | 
				
			||||||
        guild.dispatcher = null;
 | 
					          guild.playing = false;
 | 
				
			||||||
      // music not playing, something is in queue
 | 
					          guild.dispatcher = null;
 | 
				
			||||||
      } else if(!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
 | 
					        // music not playing, something is in queue
 | 
				
			||||||
        guild.queue = [];
 | 
					        } else if(!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
 | 
				
			||||||
 | 
					          guild.queue = [];
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Add video to queue
 | 
				
			||||||
 | 
					        guild.queue.push({video: video, requestedBy: message.member.id});
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Add video to queue
 | 
					 | 
				
			||||||
      guild.queue.push({video: video, requestedBy: message.member.id});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Figure out if the bot should add it to queue or play it right now
 | 
					      // Figure out if the bot should add it to queue or play it right now
 | 
				
			||||||
      if(guild.playing) {
 | 
					      if(guild.playing) {
 | 
				
			||||||
        message.reply('added **' + video.snippet.title + '** to the queue');
 | 
					        message.reply('added **' + video.snippet.title + '** to the queue');
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        guild.playing = true;
 | 
					        guild.playing = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        guild.voiceChannel = vc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let connection = await vc.join();
 | 
					        let connection = await vc.join();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        let v = guild.queue[0];
 | 
					        let v = guild.queue[0];
 | 
				
			||||||
| 
						 | 
					@ -126,10 +134,24 @@ module.exports = client => {
 | 
				
			||||||
        guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'});
 | 
					        guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'});
 | 
				
			||||||
        guild.dispatcher.setVolume(0.25);
 | 
					        guild.dispatcher.setVolume(0.25);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        message.reply('playing **' + v.video.snippet.title + '**');
 | 
					        message.channel.send('Playing **' + v.video.snippet.title + '**');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // play next in queue on end
 | 
				
			||||||
 | 
					        guild.dispatcher.once('finish', () => {
 | 
				
			||||||
 | 
					          guild.queue.shift();
 | 
				
			||||||
 | 
					          guild.playing = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          if(guild.queue.length > 0) {
 | 
				
			||||||
 | 
					            client.music.play(message, null, true);
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            guild.dispatcher = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            connection.leave();
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      return message.member.reply('failed to find the video!');
 | 
					      return message.reply('failed to find the video!');
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue