From d708dca108dcbfe3d67dfe90c27de9cdb41184a6 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 7 Dec 2024 00:50:33 +0100 Subject: feat: Add SQLITE database entry logging --- .../moe/nea/ledger/modules/MinionDetection.kt | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt') diff --git a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt index 73d06fa..1b48095 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt @@ -1,12 +1,15 @@ package moe.nea.ledger.modules -import moe.nea.ledger.events.BeforeGuiAction -import moe.nea.ledger.events.ChatReceived import moe.nea.ledger.ExpiringValue +import moe.nea.ledger.ItemChange +import moe.nea.ledger.ItemId import moe.nea.ledger.LedgerEntry import moe.nea.ledger.LedgerLogger import moe.nea.ledger.ROMAN_NUMBER_PATTERN import moe.nea.ledger.SHORT_NUMBER_PATTERN +import moe.nea.ledger.TransactionType +import moe.nea.ledger.events.BeforeGuiAction +import moe.nea.ledger.events.ChatReceived import moe.nea.ledger.parseRomanNumber import moe.nea.ledger.parseShortNumber import moe.nea.ledger.unformattedString @@ -23,7 +26,7 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) { val hopperCollectPattern = "You received (?$SHORT_NUMBER_PATTERN) coins?!".toPattern() val minionNamePattern = "(?.*) Minion (?$ROMAN_NUMBER_PATTERN)".toPattern() - var lastOpenedMinion = ExpiringValue.empty() + var lastOpenedMinion = ExpiringValue.empty() @SubscribeEvent fun onBeforeClaim(event: BeforeGuiAction) { @@ -33,7 +36,9 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) { minionNamePattern.useMatcher(invName) { val name = group("name") val level = parseRomanNumber(group("level")) - lastOpenedMinion = ExpiringValue(name.uppercase().replace(" ", "_") + "_" + level) + lastOpenedMinion = ExpiringValue( + ItemId(name.uppercase().replace(" ", "_") + .replace("MINION", "GENERATOR") + "_" + level)) } } @@ -43,10 +48,12 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) { hopperCollectPattern.useMatcher(event.message) { val minionName = lastOpenedMinion.consume(3.seconds) ledger.logEntry(LedgerEntry( - "AUTOMERCHANT_PROFIT_COLLECT", + TransactionType.AUTOMERCHANT_PROFIT_COLLECT, Instant.now(), - parseShortNumber(group("amount")), - minionName, // TODO: switch to its own column idk + listOf( + ItemChange.gainCoins(parseShortNumber(group("amount"))), + ItemChange(minionName ?: ItemId.NIL, 1.0, ItemChange.ChangeDirection.CATALYST) + ), )) } } -- cgit