From 4b6789f6eb4bb40720bc0e445d701935d0cafdcb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:18:59 +0200 Subject: Backend: /shdebug + bz fetch (#2675) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/data/bazaar/HypixelBazaarFetcher.kt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/data/bazaar/HypixelBazaarFetcher.kt b/src/main/java/at/hannibal2/skyhanni/data/bazaar/HypixelBazaarFetcher.kt index 13044b7c3..c1a7af289 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/bazaar/HypixelBazaarFetcher.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/bazaar/HypixelBazaarFetcher.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarData import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -29,10 +30,29 @@ object HypixelBazaarFetcher { private const val HIDDEN_FAILED_ATTEMPTS = 3 var latestProductInformation = mapOf() + private var lastSuccessfulFetch = SimpleTimeMark.farPast() private var nextFetchTime = SimpleTimeMark.farPast() private var failedAttempts = 0 private var nextFetchIsManual = false + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Bazaar Fetching") + + val data = listOf( + "failedAttempts: $failedAttempts", + "nextFetchIsManual: $nextFetchIsManual", + "nextFetchTime: ${nextFetchTime.timeUntil()}", + "lastSuccessfulFetch: ${lastSuccessfulFetch.passedSince()}", + ) + + if (failedAttempts == 0) { + event.addIrrelevant(data) + } else { + event.addData(data) + } + } + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!canFetch()) return @@ -51,6 +71,7 @@ object HypixelBazaarFetcher { if (response.success) { latestProductInformation = process(response.products) failedAttempts = 0 + lastSuccessfulFetch = SimpleTimeMark.now() } else { val rawResponse = jsonResponse.toString() onError(fetchType, Exception("success=false, cause=${response.cause}"), rawResponse) -- cgit