fix: added try-catch to Splatoon3Api, fixed Statusupdater
Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
parent
94149e4272
commit
984bcabd0c
4 changed files with 357 additions and 301 deletions
|
@ -32,11 +32,17 @@ import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import net.moonleay.lilJudd.buttons.component.EditButtonManager
|
import net.moonleay.lilJudd.buttons.component.EditButtonManager
|
||||||
import net.moonleay.lilJudd.data.CredentialManager
|
import net.moonleay.lilJudd.data.CredentialManager
|
||||||
|
import net.moonleay.lilJudd.data.api.Splatoon3ApiCache
|
||||||
|
import net.moonleay.lilJudd.data.api.type.ApiDataType
|
||||||
|
import net.moonleay.lilJudd.data.api.type.ApiRequestType
|
||||||
import net.moonleay.lilJudd.data.database.DB
|
import net.moonleay.lilJudd.data.database.DB
|
||||||
import net.moonleay.lilJudd.extensions.*
|
import net.moonleay.lilJudd.extensions.*
|
||||||
import net.moonleay.lilJudd.features.AvailabilityManager
|
import net.moonleay.lilJudd.features.AvailabilityManager
|
||||||
import net.moonleay.lilJudd.features.MatchManager
|
import net.moonleay.lilJudd.features.MatchManager
|
||||||
import net.moonleay.lilJudd.features.TimeManager
|
import net.moonleay.lilJudd.features.TimeManager
|
||||||
|
import net.moonleay.lilJudd.jobs.Splatoon3ApiScheduleUpdateScheduler
|
||||||
|
import net.moonleay.lilJudd.jobs.StatusUpdater
|
||||||
|
import net.moonleay.lilJudd.jobs.component.JobManager
|
||||||
import net.moonleay.lilJudd.util.EmbedColor
|
import net.moonleay.lilJudd.util.EmbedColor
|
||||||
import net.moonleay.lilJudd.util.Logger
|
import net.moonleay.lilJudd.util.Logger
|
||||||
import net.moonleay.lilJudd.util.MessageUtil
|
import net.moonleay.lilJudd.util.MessageUtil
|
||||||
|
@ -158,12 +164,12 @@ object Bot {
|
||||||
AvailabilityManager.runThread() // Update Availabilities
|
AvailabilityManager.runThread() // Update Availabilities
|
||||||
MatchManager.update() // Update Matches
|
MatchManager.update() // Update Matches
|
||||||
// Make the bot update the status every 6 seconds
|
// Make the bot update the status every 6 seconds
|
||||||
// JobManager.addJob(StatusUpdater)
|
JobManager.addJob(StatusUpdater)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the Splatoon 3 api data and make sure it stays up-to-date
|
// Update the Splatoon 3 api data and make sure it stays up-to-date
|
||||||
// Splatoon3ApiCache.updateData(ApiDataType.SCHEDULES, ApiRequestType.AUTOMATIC_CACHE_CREATION_AT_STARTUP)
|
Splatoon3ApiCache.updateData(ApiDataType.SCHEDULES, ApiRequestType.AUTOMATIC_CACHE_CREATION_AT_STARTUP)
|
||||||
// JobManager.addJob(Splatoon3ApiScheduleUpdateScheduler)
|
JobManager.addJob(Splatoon3ApiScheduleUpdateScheduler)
|
||||||
/*
|
/*
|
||||||
Other caches will be added when implemented
|
Other caches will be added when implemented
|
||||||
its not used yet in order to reduce load on the api,
|
its not used yet in order to reduce load on the api,
|
||||||
|
|
|
@ -192,17 +192,21 @@ object Splatoon3ApiCache {
|
||||||
Logger.out("Error getting coop data: $apiResponse")
|
Logger.out("Error getting coop data: $apiResponse")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val json = Json.parseToJsonElement(apiResponse)
|
try {
|
||||||
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
val json = Json.parseToJsonElement(apiResponse)
|
||||||
cachedCoopRewardsData = mutableListOf()
|
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
||||||
cachedCoopRewardsData.add(
|
cachedCoopRewardsData = mutableListOf()
|
||||||
CoopGearData(
|
cachedCoopRewardsData.add(
|
||||||
data["name"]!!.jsonPrimitive.content,
|
CoopGearData(
|
||||||
Url(data["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
data["name"]!!.jsonPrimitive.content,
|
||||||
data["__typename"]!!.jsonPrimitive.content
|
Url(data["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||||
|
data["__typename"]!!.jsonPrimitive.content
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
Logger.out("Updated COOP data")
|
||||||
Logger.out("Updated COOP data")
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting coop data: ${e.cause}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateScheduleCache(uag: String) {
|
private fun updateScheduleCache(uag: String) {
|
||||||
|
@ -214,205 +218,236 @@ object Splatoon3ApiCache {
|
||||||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||||
val data = json["data"]!!.jsonObject
|
val data = json["data"]!!.jsonObject
|
||||||
|
|
||||||
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
try {
|
||||||
cachedMapData = mutableMapOf()
|
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
mapList.forEach {
|
cachedMapData = mutableMapOf()
|
||||||
val obj = it as JsonObject
|
mapList.forEach {
|
||||||
val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
val obj = it as JsonObject
|
||||||
val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int
|
val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
cachedMapData[id] = MapData(
|
val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int
|
||||||
id,
|
cachedMapData[id] = MapData(
|
||||||
imageURL,
|
id,
|
||||||
it.jsonObject["name"]!!.jsonPrimitive.content
|
imageURL,
|
||||||
)
|
it.jsonObject["name"]!!.jsonPrimitive.content
|
||||||
}
|
|
||||||
Logger.out("Updated maplist data")
|
|
||||||
|
|
||||||
val regularMatches = data["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
|
||||||
cachedRegularModeData = mutableListOf()
|
|
||||||
regularMatches.forEach {
|
|
||||||
val obj = it as JsonObject
|
|
||||||
val setting = obj["regularMatchSetting"]!!.jsonObject
|
|
||||||
cachedRegularModeData.add(
|
|
||||||
ModeData(
|
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
|
||||||
setting["__typename"]!!.jsonPrimitive.content,
|
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
|
||||||
"TURF_WAR"
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
Logger.out("Updated maplist data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting maplist data: ${e.cause}")
|
||||||
}
|
}
|
||||||
Logger.out("Updated Regular match data")
|
|
||||||
|
|
||||||
val compMatches = data["bankaraSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
try {
|
||||||
cachedCompetitiveSeriesModeData = mutableListOf()
|
val regularMatches = data["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedCompetitiveOpenModeData = mutableListOf()
|
cachedRegularModeData = mutableListOf()
|
||||||
compMatches.forEach {
|
regularMatches.forEach {
|
||||||
val obj = it as JsonObject
|
val obj = it as JsonObject
|
||||||
val setting = obj["bankaraMatchSettings"]!!.jsonArray
|
val setting = obj["regularMatchSetting"]!!.jsonObject
|
||||||
setting.forEach {
|
cachedRegularModeData.add(
|
||||||
val ob = it as JsonObject
|
ModeData(
|
||||||
val mode = ob["bankaraMode"]!!.jsonPrimitive.content
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
if (mode == "CHALLENGE") {
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
cachedCompetitiveSeriesModeData.add(
|
setting["__typename"]!!.jsonPrimitive.content,
|
||||||
ModeData(
|
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
ob["__typename"]!!.jsonPrimitive.content,
|
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
||||||
cachedMapData[ob["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
"TURF_WAR"
|
||||||
cachedMapData[ob["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
ob["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
ob["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
|
||||||
mode
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
} else if (mode == "OPEN") {
|
)
|
||||||
cachedCompetitiveOpenModeData.add(
|
}
|
||||||
ModeData(
|
Logger.out("Updated Regular match data")
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
} catch (e: Exception) {
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
Logger.out("Error getting regular match data: ${e.cause}")
|
||||||
ob["__typename"]!!.jsonPrimitive.content,
|
}
|
||||||
cachedMapData[ob["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
cachedMapData[ob["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
try {
|
||||||
ob["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
val compMatches = data["bankaraSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
ob["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
cachedCompetitiveSeriesModeData = mutableListOf()
|
||||||
mode
|
cachedCompetitiveOpenModeData = mutableListOf()
|
||||||
|
compMatches.forEach {
|
||||||
|
val obj = it as JsonObject
|
||||||
|
val setting = obj["bankaraMatchSettings"]!!.jsonArray
|
||||||
|
setting.forEach {
|
||||||
|
val ob = it as JsonObject
|
||||||
|
val mode = ob["bankaraMode"]!!.jsonPrimitive.content
|
||||||
|
if (mode == "CHALLENGE") {
|
||||||
|
cachedCompetitiveSeriesModeData.add(
|
||||||
|
ModeData(
|
||||||
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
|
ob["__typename"]!!.jsonPrimitive.content,
|
||||||
|
cachedMapData[ob["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
|
cachedMapData[ob["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
|
ob["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
ob["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
||||||
|
mode
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
} else if (mode == "OPEN") {
|
||||||
|
cachedCompetitiveOpenModeData.add(
|
||||||
|
ModeData(
|
||||||
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
|
ob["__typename"]!!.jsonPrimitive.content,
|
||||||
|
cachedMapData[ob["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
|
cachedMapData[ob["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
|
ob["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
ob["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
||||||
|
mode
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Logger.out("Updated Competitive match data")
|
||||||
Logger.out("Updated Competitive match data")
|
|
||||||
|
|
||||||
val xMatches = data["xSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
} catch (e: Exception) {
|
||||||
cachedXModeData = mutableListOf()
|
Logger.out("Error getting competitive match data: ${e.cause}")
|
||||||
xMatches.forEach {
|
|
||||||
val obj = it as JsonObject
|
|
||||||
val setting = obj["xMatchSetting"]!!.jsonObject
|
|
||||||
cachedXModeData.add(
|
|
||||||
ModeData(
|
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
|
||||||
setting["__typename"]!!.jsonPrimitive.content,
|
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
|
||||||
"X"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Logger.out("Updated X match data")
|
try {
|
||||||
|
val xMatches = data["xSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
cachedXModeData = mutableListOf()
|
||||||
cachedChallengesData = mutableListOf()
|
xMatches.forEach {
|
||||||
challengeData.forEach {
|
val obj = it as JsonObject
|
||||||
val obj = it as JsonObject
|
val setting = obj["xMatchSetting"]!!.jsonObject
|
||||||
val tpd = obj["timePeriods"]!!.jsonArray
|
cachedXModeData.add(
|
||||||
val setting = obj["leagueMatchSetting"]!!.jsonObject
|
ModeData(
|
||||||
val event = setting["leagueMatchEvent"]!!.jsonObject
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
cachedChallengesData.add(
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
ChallengeModeData(
|
setting["__typename"]!!.jsonPrimitive.content,
|
||||||
event["leagueMatchEventId"]!!.jsonPrimitive.content,
|
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
event["name"]!!.jsonPrimitive.content,
|
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
event["desc"]!!.jsonPrimitive.content,
|
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
event["regulation"]!!.jsonPrimitive.content,
|
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
"X"
|
||||||
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
|
||||||
setting["__typename"]!!.jsonPrimitive.content,
|
|
||||||
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
|
||||||
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
TimePeriodData(
|
|
||||||
tpd[0].jsonObject["startTime"]!!.jsonPrimitive.content,
|
|
||||||
tpd[0].jsonObject["endTime"]!!.jsonPrimitive.content
|
|
||||||
),
|
|
||||||
TimePeriodData(
|
|
||||||
tpd[1].jsonObject["startTime"]!!.jsonPrimitive.content,
|
|
||||||
tpd[1].jsonObject["endTime"]!!.jsonPrimitive.content
|
|
||||||
),
|
|
||||||
TimePeriodData(
|
|
||||||
tpd[2].jsonObject["startTime"]!!.jsonPrimitive.content,
|
|
||||||
tpd[2].jsonObject["endTime"]!!.jsonPrimitive.content
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
Logger.out("Updated X match data")
|
||||||
Logger.out("Updated Challenge data")
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting X match data: ${e.cause}")
|
||||||
val shiftData = data["coopGroupingSchedule"]!!.jsonObject["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
|
||||||
cachedShiftData = mutableListOf()
|
|
||||||
shiftData.forEach {
|
|
||||||
val obj = it as JsonObject
|
|
||||||
val setting = obj["setting"]!!.jsonObject
|
|
||||||
val stage = setting["coopStage"]!!.jsonObject
|
|
||||||
val weapons = setting["weapons"]!!.jsonArray
|
|
||||||
cachedShiftData.add(
|
|
||||||
ShiftData(
|
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
|
||||||
obj["__splatoon3ink_king_salmonid_guess"]!!.jsonPrimitive.content,
|
|
||||||
setting["__typename"]!!.jsonPrimitive.content,
|
|
||||||
stage["name"]!!.jsonPrimitive.content,
|
|
||||||
Url(stage["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
|
||||||
WeaponData(
|
|
||||||
weapons[0].jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
Url(weapons[0].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
|
||||||
),
|
|
||||||
WeaponData(
|
|
||||||
weapons[1].jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
Url(weapons[1].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
|
||||||
),
|
|
||||||
WeaponData(
|
|
||||||
weapons[2].jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
Url(weapons[2].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
|
||||||
),
|
|
||||||
WeaponData(
|
|
||||||
weapons[3].jsonObject["name"]!!.jsonPrimitive.content,
|
|
||||||
Url(weapons[3].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val bigRunData = data["coopGroupingSchedule"]!!.jsonObject["bigRunSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
try {
|
||||||
cachedBigRunShiftData = mutableListOf()
|
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
bigRunData.forEach {
|
cachedChallengesData = mutableListOf()
|
||||||
val obj = it as JsonObject
|
challengeData.forEach {
|
||||||
val setting = obj["setting"]!!.jsonObject
|
val obj = it as JsonObject
|
||||||
val stage = setting["coopStage"]!!.jsonObject
|
val tpd = obj["timePeriods"]!!.jsonArray
|
||||||
val weapons = setting["weapons"]!!.jsonArray
|
val setting = obj["leagueMatchSetting"]!!.jsonObject
|
||||||
cachedBigRunShiftData.add(
|
val event = setting["leagueMatchEvent"]!!.jsonObject
|
||||||
ShiftData(
|
cachedChallengesData.add(
|
||||||
obj["startTime"]!!.jsonPrimitive.content,
|
ChallengeModeData(
|
||||||
obj["endTime"]!!.jsonPrimitive.content,
|
event["leagueMatchEventId"]!!.jsonPrimitive.content,
|
||||||
obj["__splatoon3ink_king_salmonid_guess"]!!.jsonPrimitive.content,
|
event["name"]!!.jsonPrimitive.content,
|
||||||
setting["__typename"]!!.jsonPrimitive.content,
|
event["desc"]!!.jsonPrimitive.content,
|
||||||
stage["name"]!!.jsonPrimitive.content,
|
event["regulation"]!!.jsonPrimitive.content,
|
||||||
Url(stage["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
WeaponData(
|
cachedMapData[setting["vsStages"]!!.jsonArray[1].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||||
weapons[0].jsonObject["name"]!!.jsonPrimitive.content,
|
setting["__typename"]!!.jsonPrimitive.content,
|
||||||
Url(weapons[0].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
setting["vsRule"]!!.jsonObject["rule"]!!.jsonPrimitive.content,
|
||||||
),
|
setting["vsRule"]!!.jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
WeaponData(
|
TimePeriodData(
|
||||||
weapons[1].jsonObject["name"]!!.jsonPrimitive.content,
|
tpd[0].jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||||
Url(weapons[1].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
tpd[0].jsonObject["endTime"]!!.jsonPrimitive.content
|
||||||
),
|
),
|
||||||
WeaponData(
|
TimePeriodData(
|
||||||
weapons[2].jsonObject["name"]!!.jsonPrimitive.content,
|
tpd[1].jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||||
Url(weapons[2].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
tpd[1].jsonObject["endTime"]!!.jsonPrimitive.content
|
||||||
),
|
),
|
||||||
WeaponData(
|
TimePeriodData(
|
||||||
weapons[3].jsonObject["name"]!!.jsonPrimitive.content,
|
tpd[2].jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||||
Url(weapons[3].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
tpd[2].jsonObject["endTime"]!!.jsonPrimitive.content
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
Logger.out("Updated Challenge data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting Challenge data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val shiftData =
|
||||||
|
data["coopGroupingSchedule"]!!.jsonObject["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
|
cachedShiftData = mutableListOf()
|
||||||
|
shiftData.forEach {
|
||||||
|
val obj = it as JsonObject
|
||||||
|
val setting = obj["setting"]!!.jsonObject
|
||||||
|
val stage = setting["coopStage"]!!.jsonObject
|
||||||
|
val weapons = setting["weapons"]!!.jsonArray
|
||||||
|
cachedShiftData.add(
|
||||||
|
ShiftData(
|
||||||
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["__splatoon3ink_king_salmonid_guess"]!!.jsonPrimitive.content,
|
||||||
|
setting["__typename"]!!.jsonPrimitive.content,
|
||||||
|
stage["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(stage["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||||
|
WeaponData(
|
||||||
|
weapons[0].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[0].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[1].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[1].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[2].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[2].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[3].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[3].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Logger.out("Updated shift data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting coopGrouping data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val bigRunData =
|
||||||
|
data["coopGroupingSchedule"]!!.jsonObject["bigRunSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
|
cachedBigRunShiftData = mutableListOf()
|
||||||
|
bigRunData.forEach {
|
||||||
|
val obj = it as JsonObject
|
||||||
|
val setting = obj["setting"]!!.jsonObject
|
||||||
|
val stage = setting["coopStage"]!!.jsonObject
|
||||||
|
val weapons = setting["weapons"]!!.jsonArray
|
||||||
|
cachedBigRunShiftData.add(
|
||||||
|
ShiftData(
|
||||||
|
obj["startTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["endTime"]!!.jsonPrimitive.content,
|
||||||
|
obj["__splatoon3ink_king_salmonid_guess"]!!.jsonPrimitive.content,
|
||||||
|
setting["__typename"]!!.jsonPrimitive.content,
|
||||||
|
stage["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(stage["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||||
|
WeaponData(
|
||||||
|
weapons[0].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[0].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[1].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[1].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[2].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[2].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
),
|
||||||
|
WeaponData(
|
||||||
|
weapons[3].jsonObject["name"]!!.jsonPrimitive.content,
|
||||||
|
Url(weapons[3].jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Logger.out("Updated big run data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting big run data: ${e.cause}")
|
||||||
}
|
}
|
||||||
Logger.out("Updated big run data")
|
|
||||||
|
|
||||||
Logger.out("Updated all Schedules")
|
Logger.out("Updated all Schedules")
|
||||||
}
|
}
|
||||||
|
@ -423,113 +458,118 @@ object Splatoon3ApiCache {
|
||||||
Logger.out("Error getting splatfest data: $apiResponse")
|
Logger.out("Error getting splatfest data: $apiResponse")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
try {
|
||||||
val festivals = json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||||
cachedSplatfestData = mutableListOf()
|
val festivals =
|
||||||
festivals.forEach {
|
json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
val fest = it as JsonObject
|
cachedSplatfestData = mutableListOf()
|
||||||
val teams = fest.jsonObject["teams"]!!.jsonArray
|
festivals.forEach {
|
||||||
val team1 = teams[0].jsonObject
|
val fest = it as JsonObject
|
||||||
val team1Color = team1["color"]!!.jsonObject
|
val teams = fest.jsonObject["teams"]!!.jsonArray
|
||||||
var team1Result: JsonObject? = null
|
val team1 = teams[0].jsonObject
|
||||||
if (team1["result"] !is JsonNull) {
|
val team1Color = team1["color"]!!.jsonObject
|
||||||
team1Result = team1["result"]!!.jsonObject
|
var team1Result: JsonObject? = null
|
||||||
}
|
if (team1["result"] !is JsonNull) {
|
||||||
val team2 = teams[1].jsonObject
|
team1Result = team1["result"]!!.jsonObject
|
||||||
val team2Color = team2["color"]!!.jsonObject
|
}
|
||||||
var team2Result: JsonObject? = null
|
val team2 = teams[1].jsonObject
|
||||||
if (team2["result"] !is JsonNull) {
|
val team2Color = team2["color"]!!.jsonObject
|
||||||
team2Result = team2["result"]!!.jsonObject
|
var team2Result: JsonObject? = null
|
||||||
}
|
if (team2["result"] !is JsonNull) {
|
||||||
val team3 = teams[2].jsonObject
|
team2Result = team2["result"]!!.jsonObject
|
||||||
val team3Color = team3["color"]!!.jsonObject
|
}
|
||||||
var team3Result: JsonObject? = null
|
val team3 = teams[2].jsonObject
|
||||||
if (team3["result"] !is JsonNull) {
|
val team3Color = team3["color"]!!.jsonObject
|
||||||
team3Result = team3["result"]!!.jsonObject
|
var team3Result: JsonObject? = null
|
||||||
}
|
if (team3["result"] !is JsonNull) {
|
||||||
cachedSplatfestData.add(
|
team3Result = team3["result"]!!.jsonObject
|
||||||
SplatfestData(
|
}
|
||||||
fest.jsonObject["id"]!!.jsonPrimitive.content,
|
cachedSplatfestData.add(
|
||||||
fest.jsonObject["state"]!!.jsonPrimitive.content,
|
SplatfestData(
|
||||||
fest.jsonObject["startTime"]!!.jsonPrimitive.content,
|
fest.jsonObject["id"]!!.jsonPrimitive.content,
|
||||||
fest.jsonObject["endTime"]!!.jsonPrimitive.content,
|
fest.jsonObject["state"]!!.jsonPrimitive.content,
|
||||||
fest.jsonObject["title"]!!.jsonPrimitive.content,
|
fest.jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||||
Url(fest.jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
fest.jsonObject["endTime"]!!.jsonPrimitive.content,
|
||||||
SplatfestTeamData(
|
fest.jsonObject["title"]!!.jsonPrimitive.content,
|
||||||
team1["teamName"]!!.jsonPrimitive.content,
|
Url(fest.jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||||
SplatfestColor(
|
SplatfestTeamData(
|
||||||
team1Color["a"]!!.jsonPrimitive.int,
|
team1["teamName"]!!.jsonPrimitive.content,
|
||||||
team1Color["b"]!!.jsonPrimitive.double,
|
SplatfestColor(
|
||||||
team1Color["g"]!!.jsonPrimitive.double,
|
team1Color["a"]!!.jsonPrimitive.int,
|
||||||
team1Color["r"]!!.jsonPrimitive.double
|
team1Color["b"]!!.jsonPrimitive.double,
|
||||||
|
team1Color["g"]!!.jsonPrimitive.double,
|
||||||
|
team1Color["r"]!!.jsonPrimitive.double
|
||||||
|
),
|
||||||
|
if (team1Result.isNullOrEmpty() || team1Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
||||||
|
null
|
||||||
|
else SplatfestTeamResults(
|
||||||
|
team1Result["isWinner"]!!.jsonPrimitive.boolean,
|
||||||
|
team1Result["horagaiRatio"]!!.jsonPrimitive.double,
|
||||||
|
team1Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
|
team1Result["voteRatio"]!!.jsonPrimitive.double,
|
||||||
|
team1Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
|
team1Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
||||||
|
team1Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
|
team1Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
||||||
|
team1Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
|
team1Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
||||||
|
team1Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
|
)
|
||||||
),
|
),
|
||||||
if (team1Result.isNullOrEmpty() || team1Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
SplatfestTeamData(
|
||||||
null
|
team2["teamName"]!!.jsonPrimitive.content,
|
||||||
else SplatfestTeamResults(
|
SplatfestColor(
|
||||||
team1Result["isWinner"]!!.jsonPrimitive.boolean,
|
team2Color["a"]!!.jsonPrimitive.int,
|
||||||
team1Result["horagaiRatio"]!!.jsonPrimitive.double,
|
team2Color["b"]!!.jsonPrimitive.double,
|
||||||
team1Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
team2Color["g"]!!.jsonPrimitive.double,
|
||||||
team1Result["voteRatio"]!!.jsonPrimitive.double,
|
team2Color["r"]!!.jsonPrimitive.double
|
||||||
team1Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
),
|
||||||
team1Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
if (team2Result.isNullOrEmpty() || team2Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
||||||
team1Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
null
|
||||||
team1Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
else SplatfestTeamResults(
|
||||||
team1Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
team2Result["isWinner"]!!.jsonPrimitive.boolean,
|
||||||
team1Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
team2Result["horagaiRatio"]!!.jsonPrimitive.double,
|
||||||
team1Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
team2Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
)
|
team2Result["voteRatio"]!!.jsonPrimitive.double,
|
||||||
),
|
team2Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
SplatfestTeamData(
|
team2Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team2["teamName"]!!.jsonPrimitive.content,
|
team2Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
SplatfestColor(
|
team2Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team2Color["a"]!!.jsonPrimitive.int,
|
team2Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
team2Color["b"]!!.jsonPrimitive.double,
|
team2Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team2Color["g"]!!.jsonPrimitive.double,
|
team2Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
team2Color["r"]!!.jsonPrimitive.double
|
)
|
||||||
),
|
),
|
||||||
if (team2Result.isNullOrEmpty() || team2Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
SplatfestTeamData(
|
||||||
null
|
team3["teamName"]!!.jsonPrimitive.content,
|
||||||
else SplatfestTeamResults(
|
SplatfestColor(
|
||||||
team2Result["isWinner"]!!.jsonPrimitive.boolean,
|
team3Color["a"]!!.jsonPrimitive.int,
|
||||||
team2Result["horagaiRatio"]!!.jsonPrimitive.double,
|
team3Color["b"]!!.jsonPrimitive.double,
|
||||||
team2Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
team3Color["g"]!!.jsonPrimitive.double,
|
||||||
team2Result["voteRatio"]!!.jsonPrimitive.double,
|
team3Color["r"]!!.jsonPrimitive.double
|
||||||
team2Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
),
|
||||||
team2Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
if (team3Result.isNullOrEmpty() || team3Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
||||||
team2Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
null
|
||||||
team2Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
else SplatfestTeamResults(
|
||||||
team2Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
team3Result["isWinner"]!!.jsonPrimitive.boolean,
|
||||||
team2Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
team3Result["horagaiRatio"]!!.jsonPrimitive.double,
|
||||||
team2Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
team3Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
)
|
team3Result["voteRatio"]!!.jsonPrimitive.double,
|
||||||
),
|
team3Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
SplatfestTeamData(
|
team3Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team3["teamName"]!!.jsonPrimitive.content,
|
team3Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
SplatfestColor(
|
team3Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team3Color["a"]!!.jsonPrimitive.int,
|
team3Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
team3Color["b"]!!.jsonPrimitive.double,
|
team3Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
||||||
team3Color["g"]!!.jsonPrimitive.double,
|
team3Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||||
team3Color["r"]!!.jsonPrimitive.double
|
)
|
||||||
),
|
),
|
||||||
if (team3Result.isNullOrEmpty() || team3Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
)
|
||||||
null
|
|
||||||
else SplatfestTeamResults(
|
|
||||||
team3Result["isWinner"]!!.jsonPrimitive.boolean,
|
|
||||||
team3Result["horagaiRatio"]!!.jsonPrimitive.double,
|
|
||||||
team3Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
|
||||||
team3Result["voteRatio"]!!.jsonPrimitive.double,
|
|
||||||
team3Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
|
||||||
team3Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
|
||||||
team3Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
|
||||||
team3Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
|
||||||
team3Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
|
||||||
team3Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
|
||||||
team3Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
Logger.out("Updated Splatfest data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting splatfest data: ${e.cause}")
|
||||||
}
|
}
|
||||||
Logger.out("Updated Splatfest data")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ object StatusUpdater : ICronjob {
|
||||||
override val jobName: String
|
override val jobName: String
|
||||||
get() = "StatusUpdater"
|
get() = "StatusUpdater"
|
||||||
override val jobIncoming: String
|
override val jobIncoming: String
|
||||||
get() = "/5 * * * * * 0o *" //Every 5 seconds
|
get() = "/10 * * * * * 0o *" //Every 5 seconds
|
||||||
override val jobType: CronjobType
|
override val jobType: CronjobType
|
||||||
get() = CronjobType.INFINITE
|
get() = CronjobType.INFINITE
|
||||||
override val continueJob: Boolean
|
override val continueJob: Boolean
|
||||||
|
@ -45,7 +45,7 @@ object StatusUpdater : ICronjob {
|
||||||
refreshStatusList(System.currentTimeMillis())
|
refreshStatusList(System.currentTimeMillis())
|
||||||
Bot.bot.kordRef.editPresence {
|
Bot.bot.kordRef.editPresence {
|
||||||
this.status = PresenceStatus.DoNotDisturb
|
this.status = PresenceStatus.DoNotDisturb
|
||||||
this.playing(statusList[index])
|
this.competing(statusList[index])
|
||||||
}
|
}
|
||||||
++index
|
++index
|
||||||
if (index >= statusList.size) {
|
if (index >= statusList.size) {
|
||||||
|
|
|
@ -145,6 +145,16 @@ object TimeUtil {
|
||||||
.withMinute(0).withSecond(0)
|
.withMinute(0).withSecond(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun validateDateString(input: String): Boolean {
|
||||||
|
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||||
|
return try {
|
||||||
|
LocalDateTime.parse(input, formatter)
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getDateFromString(input: String): ZonedDateTime {
|
fun getDateFromString(input: String): ZonedDateTime {
|
||||||
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||||
val localDateTime = LocalDateTime.parse(input, formatter)
|
val localDateTime = LocalDateTime.parse(input, formatter)
|
||||||
|
|
Loading…
Reference in a new issue