From 60c30af3e91a9152cb93a8a5a9a0c8da515f8e5a Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 7 Dec 2023 18:17:20 +0100 Subject: [PATCH] feat: reworked Rotation Status Signed-off-by: moonleay --- .../moonleay/lilJudd/data/api/Splatoon3Api.kt | 48 +++++++++---------- .../moonleay/lilJudd/jobs/StatusUpdater.kt | 19 ++++---- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/data/api/Splatoon3Api.kt b/src/main/kotlin/net/moonleay/lilJudd/data/api/Splatoon3Api.kt index b0192e5..92ad889 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/data/api/Splatoon3Api.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/data/api/Splatoon3Api.kt @@ -66,52 +66,50 @@ object Splatoon3Api { throw Exception("No current mode found") } + fun getRotationTime(timestamp: Long): String { + val modeData = getRegularMode(timestamp) + val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC") + val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime) + return "$diffStamp left in rotation" + } + fun getRegularMapsFormatted(timestamp: Long): String { val modeData = getRegularMode(timestamp) val map1 = modeData.map1!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0] - return "R: $map1 & $map2" - } - - fun getOpenModeFormatted(timestamp: Long): String { - val modeData = getOpenMode(timestamp) - val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC") - val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime) - return "O: ${modeData.ruleSetName} $diffStamp left" + return "R: $map1, $map2" } fun getOpenMapFormatted(timestamp: Long): String { val modeData = getOpenMode(timestamp) val map1 = modeData.map1!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0] - return "O: $map1 & $map2" - } - - fun getSeriesModeFormatted(timestamp: Long): String { - val modeData = getSeriesMode(timestamp) - val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC") - val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime) - return "S: ${modeData.ruleSetName} $diffStamp left" + return "O: ${modeData.ruleSetName}: $map1, $map2" + .replace("Rainmaker", "RMK") + .replace("Tower Control", "TC") + .replace("Splat Zones", "SZ") + .replace("Clam Blitz", "CB") } fun getSeriesMapsFormatted(timestamp: Long): String { val modeData = getSeriesMode(timestamp) val map1 = modeData.map1!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0] - return "S: $map1 & $map2" - } - - fun getXModeFormatted(timestamp: Long): String { - val modeData = getXMode(timestamp) - val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC") - val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime) - return "X: ${modeData.ruleSetName} $diffStamp left" + return "S: ${modeData.ruleSetName}: $map1, $map2" + .replace("Rainmaker", "RMK") + .replace("Tower Control", "TC") + .replace("Splat Zones", "SZ") + .replace("Clam Blitz", "CB") } fun getXMapFormatted(timestamp: Long): String { val modeData = getXMode(timestamp) val map1 = modeData.map1!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0] - return "X: $map1 & $map2" + return "X: ${modeData.ruleSetName}: $map1, $map2" + .replace("Rainmaker", "RMK") + .replace("Tower Control", "TC") + .replace("Splat Zones", "SZ") + .replace("Clam Blitz", "CB") } } diff --git a/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt b/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt index 31b687c..9f5688d 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt @@ -41,27 +41,26 @@ object StatusUpdater : ICronjob { private var statusList = listOf() private var index = 0 + // I h8 this job. I'll recode this someday. override suspend fun jobFunction() { - refreshStatusList(System.currentTimeMillis()) + if (index >= statusList.size) { + index = 0 + refreshStatusList(System.currentTimeMillis()) + } Bot.bot.kordRef.editPresence { this.status = PresenceStatus.DoNotDisturb this.competing(statusList[index]) } ++index - if (index >= statusList.size) { - index = 0 - } } - fun refreshStatusList(timestamp: Long) { + private fun refreshStatusList(timestamp: Long) { statusList = listOf( + Splatoon3Api.getRotationTime(timestamp), Splatoon3Api.getRegularMapsFormatted(timestamp), - Splatoon3Api.getSeriesModeFormatted(timestamp), - Splatoon3Api.getSeriesMapsFormatted(timestamp), - Splatoon3Api.getOpenModeFormatted(timestamp), Splatoon3Api.getOpenMapFormatted(timestamp), - Splatoon3Api.getXModeFormatted(timestamp), - Splatoon3Api.getXMapFormatted(timestamp), + Splatoon3Api.getSeriesMapsFormatted(timestamp), + Splatoon3Api.getXMapFormatted(timestamp) ) } }