forked from embee/woomy
		
	player monitor to hopefully help music break less
This commit is contained in:
		
							parent
							
								
									6d60845546
								
							
						
					
					
						commit
						0b8c4ec38d
					
				
					 1 changed files with 42 additions and 0 deletions
				
			
		
							
								
								
									
										42
									
								
								src/events/voiceStateUpdate.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/events/voiceStateUpdate.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,42 @@
 | 
			
		|||
// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
 | 
			
		||||
 | 
			
		||||
const music = require('../modules/music')
 | 
			
		||||
 | 
			
		||||
module.exports = (client, oldState, newState) => {
 | 
			
		||||
  if (newState.channelID !== oldState.channelID) {
 | 
			
		||||
    const guild = music.getGuild(newState.guild.id)
 | 
			
		||||
 | 
			
		||||
    // Reset queue, dispatcher, etc if Woomy is forcibly disconnected from the queue
 | 
			
		||||
    if (guild.voiceChannel && !guild.voiceChannel.members.get(client.user.id) && guild.queue.length > 0) {
 | 
			
		||||
      guild.queue = []
 | 
			
		||||
      guild.playing = false
 | 
			
		||||
      guild.paused = false
 | 
			
		||||
      guild.skippers = []
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Auto-disconnect feature
 | 
			
		||||
    if (guild.playing && guild.channel && guild.voiceChannel.id === oldState.channelID) {
 | 
			
		||||
      if (guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) {
 | 
			
		||||
        guild.message.channel.send('Everyone has left my voice channel, the music will end in two minutes if no one rejoins.')
 | 
			
		||||
          .then(msg => {
 | 
			
		||||
            msg.delete({ timeout: 120000 })
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
          if (guild.dispatcher !== null && guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) {
 | 
			
		||||
            // Probably should be async? But no need here I think
 | 
			
		||||
            guild.dispatcher.end('silent')
 | 
			
		||||
 | 
			
		||||
            guild.queue = []
 | 
			
		||||
            guild.playing = false
 | 
			
		||||
            guild.paused = false
 | 
			
		||||
            guild.dispatcher = null
 | 
			
		||||
            guild.skippers = []
 | 
			
		||||
 | 
			
		||||
            guild.message.channel.send('The music has ended because no one was listening to me ;~;')
 | 
			
		||||
          }
 | 
			
		||||
        }, 120000)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue