From f9f271831ba80631e73d5f5c2e44c297552af9cc Mon Sep 17 00:00:00 2001 From: saga <45262877+saga-00@users.noreply.github.com> Date: Mon, 26 Aug 2024 07:09:49 -0300 Subject: Improvement: Default amount for /gfs (#1927) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../at/hannibal2/skyhanni/api/GetFromSackAPI.kt | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/api') diff --git a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt index 54517905a..7407dd660 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt @@ -148,7 +148,7 @@ object GetFromSackAPI { when (result) { CommandResult.VALID -> getFromSack(stack ?: return) - CommandResult.WRONG_ARGUMENT -> ChatUtils.userError("Missing arguments! Usage: /getfromsacks ") + CommandResult.WRONG_ARGUMENT -> ChatUtils.userError("Missing arguments! Usage: /getfromsacks [amount]") CommandResult.WRONG_IDENTIFIER -> ChatUtils.userError("Couldn't find an item with this name or identifier!") CommandResult.WRONG_AMOUNT -> ChatUtils.userError("Invalid amount!") CommandResult.INTERNAL_ERROR -> {} @@ -168,20 +168,27 @@ object GetFromSackAPI { ) private fun commandValidator(args: List): Pair { - if (args.size <= 1) { - return CommandResult.WRONG_ARGUMENT to null - } + if (args.isEmpty()) return CommandResult.WRONG_ARGUMENT to null + + // The last parameter could be "2*3". This does not support ending with ")", but it is good enough + val argsNull = !args.last().last().isDigit() + val arguments = if (argsNull) { + if (!config.defaultGFS) return CommandResult.WRONG_ARGUMENT to null + + args + config.defaultAmountGFS.toString() + } else args - var amountString = args.last() + var amountString = arguments.last() amountString = NEUCalculator.calculateOrNull(amountString)?.toString() ?: amountString if (!amountString.isDouble()) return CommandResult.WRONG_AMOUNT to null - val itemString = args.dropLast(1).joinToString(" ").uppercase().replace(':', '-') + val itemString = arguments.dropLast(1).joinToString(" ").uppercase().replace(':', '-') + val replacedString = itemString.replace("_"," ") val item = when { SackAPI.sackListInternalNames.contains(itemString) -> itemString.asInternalName() - SackAPI.sackListNames.contains(itemString) -> NEUInternalName.fromItemNameOrNull(itemString) ?: run { + SackAPI.sackListNames.contains(replacedString) -> NEUInternalName.fromItemNameOrNull(replacedString) ?: run { ErrorManager.logErrorStateWithData( "Couldn't resolve item name", "Query failed", -- cgit