Add isSlashCommandOnly to command interface
This commit is contained in:
1 parent
6b453bb7e2
commit
50430589e6
6 files changed
+23
-11
No files matched your search
@@ -17,6 +17,11 @@ public abstract class AbstractCommand implements Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlashCommandOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultMemberPermissions getSlashCommandPermission() {
|
||||
return DefaultMemberPermissions.ENABLED;
|
||||
|
||||
@@ -22,6 +22,8 @@ public interface Command {
|
||||
|
||||
boolean isSlashCommand();
|
||||
|
||||
boolean isSlashCommandOnly();
|
||||
|
||||
String getCommandName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
@@ -31,6 +31,11 @@ public class ReportIssueCommand extends AbstractCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlashCommandOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "report-bug";
|
||||
|
||||
@@ -62,11 +62,11 @@ public class SlashCommandContext extends CommandContext implements InteractionCo
|
||||
|
||||
@Override
|
||||
public String getSubcommandGroup() {
|
||||
return getFullCommand().split(" ")[2];
|
||||
return event.getSubcommandGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubcommand() {
|
||||
return getFullCommand().split(" ")[1];
|
||||
return event.getSubcommandName();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ package me.bobert.netneutrality.core.command;
|
||||
import io.sentry.Sentry;
|
||||
import me.bobert.netneutrality.command.Command;
|
||||
import me.bobert.netneutrality.command.CommandOptions;
|
||||
import me.bobert.netneutrality.context.MessageCommandContext;
|
||||
import me.bobert.netneutrality.context.SlashCommandContext;
|
||||
import me.bobert.netneutrality.core.LogHandler;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
@@ -57,8 +56,9 @@ public class CommandProcessor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context instanceof SlashCommandContext slashCommandContext) {
|
||||
logger.debug("SlashCommandInteractionId: {}", slashCommandContext.getEvent().getInteraction().getId());
|
||||
if (command.isSlashCommandOnly() && !(context instanceof SlashCommandContext)) {
|
||||
context.replyEphemeral("This command is only available as a slash command");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface InteractionContext extends Context {
|
||||
throw new RuntimeException("Interaction isn't acknowledged yet");
|
||||
}
|
||||
|
||||
return getReplyCallback(getEvent()).getHook();
|
||||
return getReplyCallback().getHook();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +38,7 @@ public interface InteractionContext extends Context {
|
||||
throw new RuntimeException("Interaction is already acknowledged, please use getInteractionHook() instead.");
|
||||
}
|
||||
|
||||
getReplyCallback(getEvent()).deferReply(ephemeral).queue(hook -> consumer.accept(new AsyncContext(hook)));
|
||||
getReplyCallback().deferReply(ephemeral).queue(hook -> consumer.accept(new AsyncContext(hook)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,14 +70,14 @@ public interface InteractionContext extends Context {
|
||||
return;
|
||||
}
|
||||
|
||||
getReplyCallback(getEvent()).reply(messageCreateData).setEphemeral(ephemeral).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||
getReplyCallback().reply(messageCreateData).setEphemeral(ephemeral).setComponents(components).queue(message -> consumer.accept(new AsyncContext(message)));
|
||||
}
|
||||
|
||||
static IReplyCallback getReplyCallback(Event event) {
|
||||
private IReplyCallback getReplyCallback() {
|
||||
try {
|
||||
return (IReplyCallback) event;
|
||||
return (IReplyCallback) getEvent();
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(event.getClass().getSimpleName() + " does not implement class 'IReplyCallback'", e);
|
||||
throw new IllegalArgumentException(getEvent().getClass().getSimpleName() + " does not implement class 'IReplyCallback'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user