aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-07 00:50:33 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-07 00:50:33 +0100
commitd708dca108dcbfe3d67dfe90c27de9cdb41184a6 (patch)
tree2b4b0c1d12396abbbaba7b6653616f6391988bbf /src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
parent6bdc91b4bda1497e785af695769acae91e8e7064 (diff)
downloadLocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.tar.gz
LocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.tar.bz2
LocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.zip
feat: Add SQLITE database entry logging
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
index 68f0257..341dd12 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.ChatReceived
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.ItemIdProvider
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.useMatcher
import moe.nea.ledger.utils.Inject
@@ -23,22 +26,32 @@ class NpcDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemId
npcBuyPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "NPC_BUY",
+ TransactionType.NPC_BUY,
event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ listOf(
+ ItemChange.loseCoins(
+ parseShortNumber(group("coins")),
+ ),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ group("count")?.let(::parseShortNumber) ?: 1,
+ )
+ )
)
)
}
npcSellPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "NPC_SELL",
+ TransactionType.NPC_SELL,
event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ listOf(
+ ItemChange.gainCoins(parseShortNumber(group("coins"))),
+ ItemChange.lose(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ )
+ )
)
)
}