new: skip command

This commit is contained in:
ZtereoHYPE 2021-11-03 23:59:27 +01:00
parent 562015b40c
commit 580594adaf
2 changed files with 70 additions and 5 deletions

View file

@ -1,9 +1,10 @@
package codes.ztereohype.ztereomusic; package codes.ztereohype.ztereomusic;
import codes.ztereohype.ztereomusic.audio.TrackScheduer; import codes.ztereohype.ztereomusic.audio.TrackManager;
import codes.ztereohype.ztereomusic.command.Command; import codes.ztereohype.ztereomusic.command.Command;
import codes.ztereohype.ztereomusic.command.commands.Ping; import codes.ztereohype.ztereomusic.command.commands.Ping;
import codes.ztereohype.ztereomusic.command.commands.Playtest; import codes.ztereohype.ztereomusic.command.commands.Play;
import codes.ztereohype.ztereomusic.command.commands.Skip;
import codes.ztereohype.ztereomusic.database.Config; import codes.ztereohype.ztereomusic.database.Config;
import codes.ztereohype.ztereomusic.listeners.CommandListener; import codes.ztereohype.ztereomusic.listeners.CommandListener;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
@ -25,7 +26,7 @@ public class Bot {
private static @Getter final Map<String, String> commandAliases = new HashMap<>(); private static @Getter final Map<String, String> commandAliases = new HashMap<>();
public static AudioPlayerManager playerManager; public static AudioPlayerManager playerManager;
public static Map<VoiceChannel, TrackScheduer> trackScheduerMap = new HashMap<>(); public static Map<VoiceChannel, TrackManager> trackScheduerMap = new HashMap<>();
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
config = new Config("./config.json5"); config = new Config("./config.json5");
@ -40,11 +41,16 @@ public class Bot {
Ping ping = new Ping(); Ping ping = new Ping();
commandMap.put(ping.getMeta().getName(), ping); commandMap.put(ping.getMeta().getName(), ping);
Playtest playtest = new Playtest(); Play play = new Play();
commandMap.put(playtest.getMeta().getName(), playtest); commandMap.put(play.getMeta().getName(), play);
Skip skip = new Skip();
commandMap.put(skip.getMeta().getName(), skip);
for (String commandName : commandMap.keySet()) { for (String commandName : commandMap.keySet()) {
System.out.println("loading aliases from: " + commandName);
for (String aliasName : commandMap.get(commandName).getMeta().getAliases()) { for (String aliasName : commandMap.get(commandName).getMeta().getAliases()) {
System.out.println("loaded " + aliasName + " from command " + commandName);
commandAliases.put(aliasName, commandName); commandAliases.put(aliasName, commandName);
} }
} }

View file

@ -0,0 +1,59 @@
package codes.ztereohype.ztereomusic.command.commands;
import codes.ztereohype.ztereomusic.Bot;
import codes.ztereohype.ztereomusic.audio.TrackManager;
import codes.ztereohype.ztereomusic.command.Command;
import codes.ztereohype.ztereomusic.command.CommandMeta;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.managers.AudioManager;
import java.util.Objects;
public class Skip implements Command {
CommandMeta meta = new CommandMeta("skip", "Skip the current track!", new String[]{"next"}, false, false);
@Override
public CommandMeta getMeta() {
return this.meta;
}
public void execute(MessageReceivedEvent messageEvent, String[] args) {
Member author = Objects.requireNonNull(messageEvent.getMember());
if (author.getVoiceState() == null) {
messageEvent.getChannel().sendMessage("I was unable to access your information... strange...").queue();
return;
}
if (!author.getVoiceState().inVoiceChannel()) {
messageEvent.getMessage().reply("You are not in a voice channel!").queue();
return;
}
Guild guild = messageEvent.getGuild();
VoiceChannel voiceChannel = author.getVoiceState().getChannel();
AudioManager manager = guild.getAudioManager();
boolean isInVC = manager.isConnected();
boolean isInSameVC = isInVC && Objects.equals(manager.getConnectedChannel(), voiceChannel);
if (isInSameVC && Bot.trackScheduerMap.containsKey(voiceChannel)) {
TrackManager trackManager = Bot.trackScheduerMap.get(voiceChannel);
if (trackManager.getPlayer().getPlayingTrack() == null) {
messageEvent.getMessage().reply("No track is playing.").queue();
return;
}
trackManager.skip();
} else {
messageEvent.getMessage().reply("No track is playing...").queue();
}
}
}