mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-25 13:39:19 +02:00
new: audiochecks system! according to reperak it sucks but hey im kinda happy with it
This commit is contained in:
parent
7276ff91a0
commit
77785bc44f
4 changed files with 103 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ import net.dv8tion.jda.api.entities.VoiceChannel;
|
|||
import java.util.Objects;
|
||||
|
||||
public class TrackManagers {
|
||||
//todo: change to a statement that only returns a trackmanager if it exists and overload it to accept various things eg guild but also vc or infoMessage channel
|
||||
public static TrackManager getGuildTrackManager(Guild guild) {
|
||||
long guildId = guild.getIdLong();
|
||||
|
||||
|
|
@ -23,11 +24,13 @@ public class TrackManagers {
|
|||
return trackManager;
|
||||
}
|
||||
|
||||
//todo: rename to getOrCreateGuildTrackManager
|
||||
public static TrackManager getGuildTrackManager(Guild guild, MessageChannel infoChannel, VoiceChannel connectedChannel, VoiceChannel requestedChannel) {
|
||||
long guildId = guild.getIdLong();
|
||||
boolean isInSameVC = Objects.equals(connectedChannel, requestedChannel);
|
||||
|
||||
// If I get called in a different vc I delete the old manager
|
||||
//todo: move this check to the audio micropermissions and handle it there
|
||||
if (!isInSameVC) {
|
||||
ZtereoMUSIC.getInstance().getGuildTrackManagerMap().remove(guildId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package codes.ztereohype.ztereomusic.command;
|
||||
|
||||
import codes.ztereohype.ztereomusic.command.permissions.VoiceChecks;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
|
|
@ -9,12 +10,14 @@ public class CommandMeta {
|
|||
private final String[] aliases;
|
||||
private final boolean isNsfw;
|
||||
private final boolean isHidden;
|
||||
private final VoiceChecks[] checks;
|
||||
|
||||
public CommandMeta(String name, String description, String[] aliases, boolean isNsfw, boolean isHidden) {
|
||||
public CommandMeta(String name, String description, String[] aliases, boolean isNsfw, boolean isHidden, VoiceChecks[] checks) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.aliases = aliases;
|
||||
this.isNsfw = isNsfw;
|
||||
this.isHidden = isHidden;
|
||||
this.checks = checks;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package codes.ztereohype.ztereomusic.command.permissions;
|
||||
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
|
||||
public interface Check {
|
||||
boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, TrackManager trackManager);
|
||||
String getErrorCode();
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package codes.ztereohype.ztereomusic.command.permissions;
|
||||
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManagers;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
// todo: make an actual good system
|
||||
// Since these permission checks basically need to run for every single voice-related command,
|
||||
// we just get the info we need... idk i need to think this through
|
||||
public enum VoiceChecks {
|
||||
BOT_CONNECTED(new Check() {
|
||||
@Override
|
||||
public boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, TrackManager trackManager) {
|
||||
return connectedChannel != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return "I am not playing anything.";
|
||||
}
|
||||
}),
|
||||
|
||||
BOT_PLAYING(new Check() {
|
||||
@Override
|
||||
public boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, @Nullable TrackManager trackManager) {
|
||||
return trackManager != null && trackManager.getPlayer().getPlayingTrack() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return "I am not playing anything.";
|
||||
}
|
||||
}),
|
||||
|
||||
USER_CONNECTED(new Check() {
|
||||
@Override
|
||||
public boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, TrackManager trackManager) {
|
||||
if (messageAuthor.getVoiceState() == null) return false;
|
||||
return messageAuthor.getVoiceState().inVoiceChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return "You are not connected to a voice channel.";
|
||||
}
|
||||
}),
|
||||
|
||||
SAME_VC_IF_CONNECTED(new Check() { // the "if connected" specifies to the bot: if the bot is not connected always return true since the condition should be ignored basically. if the user is not in vc and the bot is though...
|
||||
@Override
|
||||
public boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, TrackManager trackManager) {
|
||||
if (connectedChannel == null) return true;
|
||||
if (messageAuthor.getVoiceState() == null) return false;
|
||||
return Objects.equals(messageAuthor.getVoiceState().getChannel(), connectedChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return "We are not in the same voice channel.";
|
||||
}
|
||||
}),
|
||||
|
||||
// Note: this is currently unused but will be used for role-based permissions
|
||||
HAS_ROLE(new Check() {
|
||||
@Override
|
||||
public boolean getResult(Member messageAuthor, VoiceChannel connectedChannel, TrackManager trackManager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return "You don't have the *DJ role*.";
|
||||
}
|
||||
});
|
||||
|
||||
private @Getter final Check check;
|
||||
|
||||
VoiceChecks(Check check) {
|
||||
this.check = check;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue