mirror of
				https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
				synced 2025-10-26 12:59:19 +01:00 
			
		
		
		
	new: Disconnect and Queue commands!
This commit is contained in:
		
							parent
							
								
									7d9766a5b8
								
							
						
					
					
						commit
						a2dd6b3aae
					
				
					 3 changed files with 92 additions and 5 deletions
				
			
		|  | @ -2,10 +2,7 @@ package codes.ztereohype.ztereomusic; | |||
| 
 | ||||
| import codes.ztereohype.ztereomusic.audio.TrackManager; | ||||
| import codes.ztereohype.ztereomusic.command.Command; | ||||
| import codes.ztereohype.ztereomusic.command.commands.Pause; | ||||
| import codes.ztereohype.ztereomusic.command.commands.Ping; | ||||
| import codes.ztereohype.ztereomusic.command.commands.Play; | ||||
| import codes.ztereohype.ztereomusic.command.commands.Skip; | ||||
| import codes.ztereohype.ztereomusic.command.commands.*; | ||||
| import codes.ztereohype.ztereomusic.database.Config; | ||||
| import codes.ztereohype.ztereomusic.listeners.CommandListener; | ||||
| import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; | ||||
|  | @ -74,8 +71,15 @@ public class ZtereoMUSIC { | |||
|         Pause pause = new Pause(); | ||||
|         this.getCommandMap().put(pause.getMeta().getName(), pause); | ||||
| 
 | ||||
|         for (String commandName : this.getCommandAliases().keySet()) { | ||||
|         Disconnect disconnect = new Disconnect(); | ||||
|         this.getCommandMap().put(disconnect.getMeta().getName(), disconnect); | ||||
| 
 | ||||
|         Queue queue = new Queue(); | ||||
|         this.getCommandMap().put(queue.getMeta().getName(), queue); | ||||
| 
 | ||||
|         for (String commandName : this.getCommandMap().keySet()) { | ||||
|             for (String aliasName : this.getCommandMap().get(commandName).getMeta().getAliases()) { | ||||
|                 System.out.println("Loaded alias \"" + aliasName + "\" for command: " + commandName); | ||||
|                 this.getCommandAliases().put(aliasName, commandName); | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -0,0 +1,34 @@ | |||
| package codes.ztereohype.ztereomusic.command.commands; | ||||
| 
 | ||||
| import codes.ztereohype.ztereomusic.ZtereoMUSIC; | ||||
| import codes.ztereohype.ztereomusic.audio.TrackManager; | ||||
| import codes.ztereohype.ztereomusic.audio.TrackManagers; | ||||
| import codes.ztereohype.ztereomusic.command.Command; | ||||
| import codes.ztereohype.ztereomusic.command.CommandMeta; | ||||
| import codes.ztereohype.ztereomusic.command.permissions.VoiceChecks; | ||||
| import net.dv8tion.jda.api.entities.Guild; | ||||
| import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||||
| import net.dv8tion.jda.api.managers.AudioManager; | ||||
| 
 | ||||
| public class Disconnect implements Command { | ||||
|     CommandMeta meta = new CommandMeta("disconnect", "A command to kick the bot from the vc.", new String[]{"fuckoff", "bye"}, false, false, new VoiceChecks[]{ VoiceChecks.BOT_CONNECTED, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED }); | ||||
| 
 | ||||
|     @Override | ||||
|     public CommandMeta getMeta() { | ||||
|         return this.meta; | ||||
|     } | ||||
| 
 | ||||
|     public void execute(MessageReceivedEvent messageEvent, String[] args) { | ||||
|         Guild guild = messageEvent.getGuild(); | ||||
|         AudioManager audioManager = guild.getAudioManager(); | ||||
| 
 | ||||
|         TrackManager trackManager = ZtereoMUSIC.getInstance().getGuildTrackManagerMap().get(guild.getIdLong()); | ||||
| 
 | ||||
|         if (trackManager == null) { | ||||
|             audioManager.closeAudioConnection(); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         TrackManagers.removeGuildTrackManager(guild); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,49 @@ | |||
| package codes.ztereohype.ztereomusic.command.commands; | ||||
| 
 | ||||
| import codes.ztereohype.ztereomusic.ZtereoMUSIC; | ||||
| import codes.ztereohype.ztereomusic.audio.TrackManager; | ||||
| import codes.ztereohype.ztereomusic.audio.TrackManagers; | ||||
| import codes.ztereohype.ztereomusic.command.Command; | ||||
| import codes.ztereohype.ztereomusic.command.CommandMeta; | ||||
| import codes.ztereohype.ztereomusic.command.permissions.VoiceChecks; | ||||
| import com.sedmelluq.discord.lavaplayer.track.AudioTrack; | ||||
| import net.dv8tion.jda.api.entities.Guild; | ||||
| import net.dv8tion.jda.api.entities.MessageChannel; | ||||
| import net.dv8tion.jda.api.entities.VoiceChannel; | ||||
| import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||||
| 
 | ||||
| import java.util.List; | ||||
| import java.util.Objects; | ||||
| 
 | ||||
| public class Queue implements Command { | ||||
|     CommandMeta meta = new CommandMeta("queue", "See the queue", new String[]{"q"}, false, false, new VoiceChecks[]{ VoiceChecks.BOT_CONNECTED, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED }); | ||||
| 
 | ||||
|     @Override | ||||
|     public CommandMeta getMeta() { | ||||
|         return this.meta; | ||||
|     } | ||||
| 
 | ||||
|     public void execute(MessageReceivedEvent messageEvent, String[] args) { | ||||
|         Guild guild = messageEvent.getGuild(); | ||||
|         VoiceChannel voiceChannel = Objects.requireNonNull(Objects.requireNonNull(messageEvent.getMember()).getVoiceState()).getChannel(); | ||||
|         MessageChannel messageChannel = messageEvent.getChannel(); | ||||
|         VoiceChannel connectedChannel = guild.getAudioManager().getConnectedChannel(); | ||||
| 
 | ||||
|         TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, connectedChannel, voiceChannel); | ||||
| 
 | ||||
|         StringBuilder messageBuilder = new StringBuilder(); | ||||
|         List<AudioTrack> trackList = trackManager.trackQueue; | ||||
|         for (AudioTrack track: trackList) { | ||||
|             messageBuilder.append(trackList.indexOf(track)).append(". "); | ||||
|             messageBuilder.append(track.getInfo().title); | ||||
|             messageBuilder.append(System.getProperty("line.separator")); | ||||
|         } | ||||
| 
 | ||||
|         if (messageBuilder.length() == 0) { | ||||
|             messageBuilder.append("There are no items in queue"); | ||||
|         } | ||||
| 
 | ||||
|         messageChannel.sendMessage(messageBuilder.toString()).queue(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue