feat: reworked Rotation Status

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-12-07 18:17:20 +01:00
parent 5ad7fe0ae6
commit 60c30af3e9
Signed by: moonleay
GPG key ID: 82667543CCD715FB
2 changed files with 32 additions and 35 deletions

View file

@ -66,52 +66,50 @@ object Splatoon3Api {
throw Exception("No current mode found") 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 { fun getRegularMapsFormatted(timestamp: Long): String {
val modeData = getRegularMode(timestamp) val modeData = getRegularMode(timestamp)
val map1 = modeData.map1!!.name.split(" ")[0] val map1 = modeData.map1!!.name.split(" ")[0]
val map2 = modeData.map2!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0]
return "R: $map1 & $map2" 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"
} }
fun getOpenMapFormatted(timestamp: Long): String { fun getOpenMapFormatted(timestamp: Long): String {
val modeData = getOpenMode(timestamp) val modeData = getOpenMode(timestamp)
val map1 = modeData.map1!!.name.split(" ")[0] val map1 = modeData.map1!!.name.split(" ")[0]
val map2 = modeData.map2!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0]
return "O: $map1 & $map2" return "O: ${modeData.ruleSetName}: $map1, $map2"
} .replace("Rainmaker", "RMK")
.replace("Tower Control", "TC")
fun getSeriesModeFormatted(timestamp: Long): String { .replace("Splat Zones", "SZ")
val modeData = getSeriesMode(timestamp) .replace("Clam Blitz", "CB")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime)
return "S: ${modeData.ruleSetName} $diffStamp left"
} }
fun getSeriesMapsFormatted(timestamp: Long): String { fun getSeriesMapsFormatted(timestamp: Long): String {
val modeData = getSeriesMode(timestamp) val modeData = getSeriesMode(timestamp)
val map1 = modeData.map1!!.name.split(" ")[0] val map1 = modeData.map1!!.name.split(" ")[0]
val map2 = modeData.map2!!.name.split(" ")[0] val map2 = modeData.map2!!.name.split(" ")[0]
return "S: $map1 & $map2" return "S: ${modeData.ruleSetName}: $map1, $map2"
} .replace("Rainmaker", "RMK")
.replace("Tower Control", "TC")
fun getXModeFormatted(timestamp: Long): String { .replace("Splat Zones", "SZ")
val modeData = getXMode(timestamp) .replace("Clam Blitz", "CB")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
val diffStamp = TimeUtil.getTimeDifferenceFormatted(System.currentTimeMillis(), endTime)
return "X: ${modeData.ruleSetName} $diffStamp left"
} }
fun getXMapFormatted(timestamp: Long): String { fun getXMapFormatted(timestamp: Long): String {
val modeData = getXMode(timestamp) val modeData = getXMode(timestamp)
val map1 = modeData.map1!!.name.split(" ")[0] val map1 = modeData.map1!!.name.split(" ")[0]
val map2 = modeData.map2!!.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")
} }
} }

View file

@ -41,27 +41,26 @@ object StatusUpdater : ICronjob {
private var statusList = listOf<String>() private var statusList = listOf<String>()
private var index = 0 private var index = 0
// I h8 this job. I'll recode this someday.
override suspend fun jobFunction() { override suspend fun jobFunction() {
refreshStatusList(System.currentTimeMillis()) if (index >= statusList.size) {
index = 0
refreshStatusList(System.currentTimeMillis())
}
Bot.bot.kordRef.editPresence { Bot.bot.kordRef.editPresence {
this.status = PresenceStatus.DoNotDisturb this.status = PresenceStatus.DoNotDisturb
this.competing(statusList[index]) this.competing(statusList[index])
} }
++index ++index
if (index >= statusList.size) {
index = 0
}
} }
fun refreshStatusList(timestamp: Long) { private fun refreshStatusList(timestamp: Long) {
statusList = listOf( statusList = listOf(
Splatoon3Api.getRotationTime(timestamp),
Splatoon3Api.getRegularMapsFormatted(timestamp), Splatoon3Api.getRegularMapsFormatted(timestamp),
Splatoon3Api.getSeriesModeFormatted(timestamp),
Splatoon3Api.getSeriesMapsFormatted(timestamp),
Splatoon3Api.getOpenModeFormatted(timestamp),
Splatoon3Api.getOpenMapFormatted(timestamp), Splatoon3Api.getOpenMapFormatted(timestamp),
Splatoon3Api.getXModeFormatted(timestamp), Splatoon3Api.getSeriesMapsFormatted(timestamp),
Splatoon3Api.getXMapFormatted(timestamp), Splatoon3Api.getXMapFormatted(timestamp)
) )
} }
} }