mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-25 05:29:18 +02:00
change: update all commands to use that system
This commit is contained in:
parent
c3dd98bfb0
commit
7d9766a5b8
4 changed files with 13 additions and 98 deletions
|
|
@ -4,17 +4,12 @@ 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.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
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 Pause implements Command {
|
||||
CommandMeta meta = new CommandMeta("pause", "Pause the playing music", new String[]{"resume"}, false, false);
|
||||
CommandMeta meta = new CommandMeta("pause", "Pause the playing music", new String[]{"resume"}, false, false, new VoiceChecks[]{ VoiceChecks.BOT_CONNECTED, VoiceChecks.BOT_PLAYING, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED });
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
|
|
@ -23,48 +18,10 @@ public class Pause implements Command {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
// todo: make this part of a perms system (only people in same vc or vc at all have perms on music control)
|
||||
/* Note to self: Things to check before executing command
|
||||
- if he's in vc
|
||||
- if we are in vc
|
||||
- if we are in the same vc
|
||||
*/
|
||||
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();
|
||||
MessageChannel messageChannel = messageEvent.getChannel();
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
|
||||
if (manager.getConnectedChannel() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we are in the same vc
|
||||
if (!Objects.equals(author.getVoiceState().getChannel(), manager.getConnectedChannel())) {
|
||||
messageChannel.sendMessage("We aren't in the same channel").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
// Check if we are playing anything
|
||||
if (trackManager.getPlayer().getPlayingTrack() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild);
|
||||
|
||||
assert trackManager != null; // the command will not execute if it is anyway because of our VoiceChecks
|
||||
if (trackManager.getPlayer().isPaused()) {
|
||||
trackManager.resume();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ package codes.ztereohype.ztereomusic.command.commands;
|
|||
|
||||
import codes.ztereohype.ztereomusic.command.Command;
|
||||
import codes.ztereohype.ztereomusic.command.CommandMeta;
|
||||
import codes.ztereohype.ztereomusic.command.permissions.VoiceChecks;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class Ping implements Command {
|
||||
CommandMeta meta = new CommandMeta("ping", "A command to get pinged", new String[]{"pong", "pog"}, false, false);
|
||||
CommandMeta meta = new CommandMeta("ping", "A command to get pinged", new String[]{"pong", "pog"}, false, false, new VoiceChecks[]{});
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ 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 codes.ztereohype.ztereomusic.networking.YoutubeSearch;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
|
|
@ -25,7 +26,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class Play implements Command {
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("^(http|https)://([a-z]+\\.[a-z]+)+/\\S+$", Pattern.CASE_INSENSITIVE);
|
||||
CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{"p"}, false, false);
|
||||
CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{"p"}, false, false, new VoiceChecks[]{ VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED });
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
|
|
@ -35,18 +36,8 @@ public class Play implements Command {
|
|||
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();
|
||||
VoiceChannel voiceChannel = Objects.requireNonNull(author.getVoiceState()).getChannel();
|
||||
MessageChannel messageChannel = messageEvent.getChannel();
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
AudioPlayerManager playerManager = ZtereoMUSIC.getInstance().getPlayerManager();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
|
@ -11,10 +12,8 @@ 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);
|
||||
CommandMeta meta = new CommandMeta("skip", "Skip the current track!", new String[]{"next"}, false, false, new VoiceChecks[]{ VoiceChecks.BOT_CONNECTED, VoiceChecks.BOT_PLAYING, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED });
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
|
|
@ -22,44 +21,11 @@ public class Skip implements Command {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// todo: make this part of a perms system (only people in same vc or vc at all have perms on music control)
|
||||
/* Note to self: Things to check before executing command
|
||||
- if we are in vc
|
||||
- if we are in the same vc
|
||||
- if we are playing something
|
||||
- if mr user has the goshdarn role
|
||||
*/
|
||||
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();
|
||||
MessageChannel messageChannel = messageEvent.getChannel();
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild);
|
||||
|
||||
if (manager.getConnectedChannel() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we are in the same vc
|
||||
if (!Objects.equals(author.getVoiceState().getChannel(), manager.getConnectedChannel())) {
|
||||
messageChannel.sendMessage("We aren't in the same channel").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
// Check if we are playing anything
|
||||
assert trackManager != null; // the command will not execute if it is anyway because of our VoiceChecks (BOT_PLAYING)
|
||||
if (trackManager.getPlayer().getPlayingTrack() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue