diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-07 00:50:33 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-07 00:50:33 +0100 |
commit | d708dca108dcbfe3d67dfe90c27de9cdb41184a6 (patch) | |
tree | 2b4b0c1d12396abbbaba7b6653616f6391988bbf /src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt | |
parent | 6bdc91b4bda1497e785af695769acae91e8e7064 (diff) | |
download | LocalTransactionLedger-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/AuctionHouseDetection.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt | 152 |
1 files changed, 80 insertions, 72 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt index cbbff12..0d9b0cb 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt @@ -1,11 +1,14 @@ package moe.nea.ledger.modules -import moe.nea.ledger.events.BeforeGuiAction -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.BeforeGuiAction +import moe.nea.ledger.events.ChatReceived import moe.nea.ledger.getInternalId import moe.nea.ledger.getLore import moe.nea.ledger.parseShortNumber @@ -18,83 +21,88 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern class AuctionHouseDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) { - data class LastViewedItem( - val count: Int, - val id: String, - ) - /* - You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction! - You collected 60,000 coins from selling Walnut to [MVP++] Alea1337 in an auction! - You purchased 2x Walnut for 69 coins! - You purchased ◆ Ice Rune I for 4,000 coins! - */ + data class LastViewedItem( + val count: Int, + val id: ItemId, + ) + /* + You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction! + You collected 60,000 coins from selling Walnut to [MVP++] Alea1337 in an auction! + You purchased 2x Walnut for 69 coins! + You purchased ◆ Ice Rune I for 4,000 coins! + */ - val collectSold = - Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!") - val purchased = - Pattern.compile("You purchased (?:(?<amount>[0-9]+)x )?(?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!") - var lastViewedItems: MutableList<LastViewedItem> = mutableListOf() + val collectSold = + Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!") + val purchased = + Pattern.compile("You purchased (?:(?<amount>[0-9]+)x )?(?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!") + var lastViewedItems: MutableList<LastViewedItem> = mutableListOf() - @SubscribeEvent - fun onEvent(event: ChatReceived) { - collectSold.useMatcher(event.message) { - val lastViewedItem = lastViewedItems.removeLastOrNull() - ledger.logEntry( - LedgerEntry( - "AUCTION_SOLD", - event.timestamp, - parseShortNumber(group("coins")), - lastViewedItem?.id, - lastViewedItem?.count - ) - ) - } - purchased.useMatcher(event.message) { - ledger.logEntry( - LedgerEntry( - "AUCTION_BOUGHT", - event.timestamp, - parseShortNumber(group("coins")), - ids.findForName(group("what")), - group("amount")?.toInt() ?: 1 - ) - ) - } - } + @SubscribeEvent + fun onEvent(event: ChatReceived) { + collectSold.useMatcher(event.message) { + val lastViewedItem = lastViewedItems.removeLastOrNull() + ledger.logEntry( + LedgerEntry( + TransactionType.AUCTION_SOLD, + event.timestamp, + listOfNotNull( + ItemChange.gainCoins(parseShortNumber(group("coins"))), + lastViewedItem?.let { ItemChange.lose(it.id, it.count) } + ), + ) + ) + } + purchased.useMatcher(event.message) { + ledger.logEntry( + LedgerEntry( + TransactionType.AUCTION_BOUGHT, + event.timestamp, + listOf( + ItemChange.loseCoins(parseShortNumber(group("coins"))), + ItemChange.gain( + ids.findForName(group("what")) ?: ItemId.NIL, + group("amount")?.toInt() ?: 1 + ) + ) + ) + ) + } + } - @SubscribeEvent - fun onBeforeAuctionCollected(event: BeforeGuiAction) { - val chest = (event.gui as? GuiChest) ?: return - val slots = chest.inventorySlots as ContainerChest - val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString() + @SubscribeEvent + fun onBeforeAuctionCollected(event: BeforeGuiAction) { + val chest = (event.gui as? GuiChest) ?: return + val slots = chest.inventorySlots as ContainerChest + val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString() - if (name == "BIN Auction View" || name == "Auction View") { - handleCollectSingleAuctionView(slots) - } - if (name == "Manage Auctions") { - handleCollectMultipleAuctionsView(slots) - } - } + if (name == "BIN Auction View" || name == "Auction View") { + handleCollectSingleAuctionView(slots) + } + if (name == "Manage Auctions") { + handleCollectMultipleAuctionsView(slots) + } + } - private fun handleCollectMultipleAuctionsView(slots: ContainerChest) { - lastViewedItems = - (0 until slots.lowerChestInventory.sizeInventory) - .mapNotNull { slots.lowerChestInventory.getStackInSlot(it) } - .filter { - it.getLore().contains("§7Status: §aSold!") // BINs - || it.getLore().contains("§7Status: §aEnded!") // Auctions - } - .mapNotNull { LastViewedItem(it.stackSize, it.getInternalId() ?: return@mapNotNull null) } - .toMutableList() - } + private fun handleCollectMultipleAuctionsView(slots: ContainerChest) { + lastViewedItems = + (0 until slots.lowerChestInventory.sizeInventory) + .mapNotNull { slots.lowerChestInventory.getStackInSlot(it) } + .filter { + it.getLore().contains("§7Status: §aSold!") // BINs + || it.getLore().contains("§7Status: §aEnded!") // Auctions + } + .mapNotNull { LastViewedItem(it.stackSize, it.getInternalId() ?: return@mapNotNull null) } + .toMutableList() + } - fun handleCollectSingleAuctionView(slots: ContainerChest) { - val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return - val id = soldItem.getInternalId() ?: return - val count = soldItem.stackSize - lastViewedItems = mutableListOf(LastViewedItem(count, id)) - } + fun handleCollectSingleAuctionView(slots: ContainerChest) { + val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return + val id = soldItem.getInternalId() ?: return + val count = soldItem.stackSize + lastViewedItems = mutableListOf(LastViewedItem(count, id)) + } }
\ No newline at end of file |