refactor: getAction in context

This commit is contained in:
ChomeNS
2025-01-03 14:41:37 +07:00
parent 1acc0fdbfd
commit f7f3813ec8
8 changed files with 11 additions and 7 deletions

View File

@@ -87,6 +87,10 @@ public class CommandContext {
return returnLowerCase ? string.toLowerCase() : string;
}
public String getAction () throws CommandException {
return getString(false, true, true, "action");
}
public Integer getInteger (boolean required) throws CommandException {
final String string = getString(false, required, "integer");

View File

@@ -30,7 +30,7 @@ public class CloopCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true, true);
final String action = context.getAction();
switch (action) {
case "add" -> {

View File

@@ -30,7 +30,7 @@ public class EvalCommand extends Command {
if (!bot.eval.connected) throw new CommandException(Component.text("Eval server is not online"));
final String action = context.getString(false, true);
final String action = context.getAction();
switch (action) {
case "run" -> {

View File

@@ -37,7 +37,7 @@ public class IPFilterCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true, true);
final String action = context.getAction();
switch (action) {
case "add" -> {

View File

@@ -45,7 +45,7 @@ public class MailCommand extends Command {
// kinda messy ngl
final String action = context.getString(false, true, true);
final String action = context.getAction();
switch (action) {
case "send" -> DatabasePlugin.executorService.submit(() -> {

View File

@@ -64,7 +64,7 @@ public class MusicCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
if (context.bot.music.locked && !(context instanceof ConsoleCommandContext)) throw new CommandException(Component.text("Managing music is currently locked"));
final String action = context.getString(false, true, true);
final String action = context.getAction();
root = MusicPlayerPlugin.SONG_DIR;
return switch (action) {

View File

@@ -29,7 +29,7 @@ public class WhitelistCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true, true);
final String action = context.getAction();
switch (action) {
case "enable" -> {