Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Repo Patterns BazaarAPI #3271

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Using repo patterns in BazaarApi
  • Loading branch information
hannibal002 committed Jan 23, 2025
commit 3d72df71d5b71dde861e926f60a82d02162c8a9b
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.item.ItemStack
Expand All @@ -50,6 +52,45 @@ object BazaarApi {
var currentlyOpenedProduct: NEUInternalName? = null
var orderOptionProduct: NEUInternalName? = null

private val patternGroup = RepoPattern.group("inventory.bazaar")

/**
* REGEX-TEST: [Bazaar] Bought 1x Small Storage for 3,999.5 coins!
*/
private val resetCurrentSearchPattern by patternGroup.pattern(
"reset-current-search",
"\\[Bazaar] (?:Buy Order Setup!|Bought) \\d+x (?<item>.*) for .*",
)

/**
* REGEX-TEST: Bazaar ➜ Coal
* REGEX-TEST: How many do you want?
* REGEX-TEST: Confirm Buy Order
* REGEX-TEST: Confirm Buy Order
* REGEX-TEST: Order options
*/
private val inventoryNamePattern by patternGroup.list(
"inventory-name",
"Bazaar ➜ .*",
"How many do you want\\?",
"How much do you want to pay\\?",
"Confirm Buy Order",
"Confirm Instant Buy",
"At what price are you selling\\?",
"Confirm Sell Offer",
"Order options",
)

/**
* REGEX-TEST: Your Bazaar Orders
* REGEX-TEST: Co-op Bazaar Orders
*/
private val inventoryBazaarOrdersPattern by patternGroup.list(
"inventory-bazaar-orders",
"Your Bazaar Orders",
"Co-op Bazaar Orders",
)

fun NEUInternalName.getBazaarData(): BazaarData? = HypixelBazaarFetcher.latestProductInformation[this]

fun NEUInternalName.getBazaarDataOrError(): BazaarData = getBazaarData() ?: run {
Expand Down Expand Up @@ -149,11 +190,14 @@ object BazaarApi {
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!inBazaarInventory) return
// TODO USE SH-REPO
// TODO remove dynamic pattern
"\\[Bazaar] (Buy Order Setup!|Bought).*$currentSearchedItem.*".toPattern()
.matchMatcher(event.message.removeColor()) { currentSearchedItem = "" }
val message = event.message.removeColor()
val item = resetCurrentSearchPattern.matchMatcher(message) {
group("item")
} ?: return

if (currentSearchedItem == item) {
currentSearchedItem = ""
}
}

private fun checkIfInBazaar(event: InventoryFullyOpenedEvent): Boolean {
Expand All @@ -169,18 +213,8 @@ object BazaarApi {
}
}

if (event.inventoryName.startsWith("Bazaar ➜ ")) return true
return when (event.inventoryName) {
"How many do you want?" -> true
"How much do you want to pay?" -> true
"Confirm Buy Order" -> true
"Confirm Instant Buy" -> true
"At what price are you selling?" -> true
"Confirm Sell Offer" -> true
"Order options" -> true

else -> false
}
if (isBazaarOrderInventory(event.inventoryName)) return true
return inventoryNamePattern.matches(event.inventoryName)
}

@HandleEvent
Expand All @@ -194,9 +228,5 @@ object BazaarApi {
currentlyOpenedProduct = null
}

fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) {
"Your Bazaar Orders" -> true
"Co-op Bazaar Orders" -> true
else -> false
}
fun isBazaarOrderInventory(inventoryName: String): Boolean = inventoryBazaarOrdersPattern.matches(inventoryName)
}
Loading