From 7375808ececd341d92533bc52c583524d25af792 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Mon, 20 Jan 2025 22:50:42 +0100 Subject: feat: Bank Interest Detection --- mod/src/main/kotlin/moe/nea/ledger/Ledger.kt | 2 ++ .../nea/ledger/modules/BankInterestDetection.kt | 38 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 mod/src/main/kotlin/moe/nea/ledger/modules/BankInterestDetection.kt (limited to 'mod/src/main/kotlin/moe/nea') diff --git a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt index 5db4346..06ee9c9 100644 --- a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -16,6 +16,7 @@ import moe.nea.ledger.modules.AccessorySwapperDetection import moe.nea.ledger.modules.AllowanceDetection import moe.nea.ledger.modules.AuctionHouseDetection import moe.nea.ledger.modules.BankDetection +import moe.nea.ledger.modules.BankInterestDetection import moe.nea.ledger.modules.BazaarDetection import moe.nea.ledger.modules.BazaarOrderDetection import moe.nea.ledger.modules.BitsDetection @@ -127,6 +128,7 @@ class Ledger { AllowanceDetection::class.java, AuctionHouseDetection::class.java, BankDetection::class.java, + BankInterestDetection::class.java, BazaarDetection::class.java, BazaarOrderDetection::class.java, BitsDetection::class.java, diff --git a/mod/src/main/kotlin/moe/nea/ledger/modules/BankInterestDetection.kt b/mod/src/main/kotlin/moe/nea/ledger/modules/BankInterestDetection.kt new file mode 100644 index 0000000..1e8da23 --- /dev/null +++ b/mod/src/main/kotlin/moe/nea/ledger/modules/BankInterestDetection.kt @@ -0,0 +1,38 @@ +package moe.nea.ledger.modules + +import moe.nea.ledger.ItemChange +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.di.Inject +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + + +class BankInterestDetection { + + val bankInterestPattern = + Pattern.compile("You have just received (?$SHORT_NUMBER_PATTERN) coins as interest in your (co-op|personal) bank account!") + + @Inject + lateinit var logger: LedgerLogger + + @SubscribeEvent + fun onChat(event: ChatReceived) { + bankInterestPattern.useMatcher(event.message) { + logger.logEntry( + LedgerEntry( + TransactionType.BANK_WITHDRAW, + event.timestamp, + listOf( + ItemChange.gainCoins(parseShortNumber(group("coins"))), + ) + ) + ) + } + } +} -- cgit