From e8ef3adf3b483d79df1c1a07c61f2c7fa65fa55a Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:15:35 +0700 Subject: [PATCH] improve flag checking in FilterCommand --- .../chomens_bot/commands/FilterCommand.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java index b4362ab..76abbf5 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java @@ -47,21 +47,15 @@ public class FilterCommand extends Command { String action = context.getString(false, true); - // this is a mess - if (action.equals("-ignorecase")) { - ignoreCase = true; - action = context.getString(false, true); - } else if (action.equals("-regex")) { - regex = true; - action = context.getString(false, true); - } - - if (action.equals("-ignorecase")) { - ignoreCase = true; - action = context.getString(false, true); - } else if (action.equals("-regex")) { - regex = true; - action = context.getString(false, true); + // run 2 times. for example `*filter -ignorecase -regex add test` will be both accepted + for (int i = 0; i < 2; i++) { + if (action.equals("-ignorecase")) { + ignoreCase = true; + action = context.getString(false, true); + } else if (action.equals("-regex")) { + regex = true; + action = context.getString(false, true); + } } final Gson gson = new Gson(); @@ -128,9 +122,7 @@ public class FilterCommand extends Command { Component.join(JoinConfiguration.newlines(), filtersComponents) ); } - default -> { - throw new CommandException(Component.text("Invalid action")); - } + default -> throw new CommandException(Component.text("Invalid action")); } } }