From 3001af7c4277c96f2818ea2efe3c7836b1f1498f Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 30 Oct 2024 19:01:07 +0100 Subject: fix: single buy/sell npc detection --- src/main/kotlin/moe/nea/ledger/NpcDetection.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/moe/nea/ledger/NpcDetection.kt b/src/main/kotlin/moe/nea/ledger/NpcDetection.kt index 656f1d6..65693ef 100644 --- a/src/main/kotlin/moe/nea/ledger/NpcDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/NpcDetection.kt @@ -6,9 +6,9 @@ import java.util.regex.Pattern class NpcDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { val npcBuyPattern = - Pattern.compile("You bought (?.*?) x(?$SHORT_NUMBER_PATTERN) for (?$SHORT_NUMBER_PATTERN) Coins!") + Pattern.compile("You bought (?.*?) (x(?$SHORT_NUMBER_PATTERN) )?for (?$SHORT_NUMBER_PATTERN) Coins!") val npcSellPattern = - Pattern.compile("You sold (?.*) x(?$SHORT_NUMBER_PATTERN) for (?$SHORT_NUMBER_PATTERN) Coins!") + Pattern.compile("You sold (?.*) (x(?$SHORT_NUMBER_PATTERN) )?for (?$SHORT_NUMBER_PATTERN) Coins!") @SubscribeEvent fun onNpcBuy(event: ChatReceived) { @@ -19,7 +19,7 @@ class NpcDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { event.timestamp, parseShortNumber(group("coins")), ids.findForName(group("what")), - parseShortNumber(group("count")).toInt(), + group("count")?.let(::parseShortNumber)?.toInt() ?: 1, ) ) } @@ -30,7 +30,7 @@ class NpcDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { event.timestamp, parseShortNumber(group("coins")), ids.findForName(group("what")), - parseShortNumber(group("count")).toInt(), + group("count")?.let(::parseShortNumber)?.toInt() ?: 1, ) ) } -- cgit