forked from DiscordBots/lilJudd
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 net.moonleay.lilJudd.buttons.component.EditButtonManager
|
||||
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.extensions.*
|
||||
import net.moonleay.lilJudd.features.AvailabilityManager
|
||||
import net.moonleay.lilJudd.features.MatchManager
|
||||
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.Logger
|
||||
import net.moonleay.lilJudd.util.MessageUtil
|
||||
|
@ -158,12 +164,12 @@ object Bot {
|
|||
AvailabilityManager.runThread() // Update Availabilities
|
||||
MatchManager.update() // Update Matches
|
||||
// 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
|
||||
// Splatoon3ApiCache.updateData(ApiDataType.SCHEDULES, ApiRequestType.AUTOMATIC_CACHE_CREATION_AT_STARTUP)
|
||||
// JobManager.addJob(Splatoon3ApiScheduleUpdateScheduler)
|
||||
Splatoon3ApiCache.updateData(ApiDataType.SCHEDULES, ApiRequestType.AUTOMATIC_CACHE_CREATION_AT_STARTUP)
|
||||
JobManager.addJob(Splatoon3ApiScheduleUpdateScheduler)
|
||||
/*
|
||||
Other caches will be added when implemented
|
||||
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")
|
||||
return
|
||||
}
|
||||
val json = Json.parseToJsonElement(apiResponse)
|
||||
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
||||
cachedCoopRewardsData = mutableListOf()
|
||||
cachedCoopRewardsData.add(
|
||||
CoopGearData(
|
||||
data["name"]!!.jsonPrimitive.content,
|
||||
Url(data["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||
data["__typename"]!!.jsonPrimitive.content
|
||||
try {
|
||||
val json = Json.parseToJsonElement(apiResponse)
|
||||
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
||||
cachedCoopRewardsData = mutableListOf()
|
||||
cachedCoopRewardsData.add(
|
||||
CoopGearData(
|
||||
data["name"]!!.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) {
|
||||
|
@ -214,205 +218,236 @@ object Splatoon3ApiCache {
|
|||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||
val data = json["data"]!!.jsonObject
|
||||
|
||||
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedMapData = mutableMapOf()
|
||||
mapList.forEach {
|
||||
val obj = it as JsonObject
|
||||
val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||
val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int
|
||||
cachedMapData[id] = MapData(
|
||||
id,
|
||||
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"
|
||||
try {
|
||||
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedMapData = mutableMapOf()
|
||||
mapList.forEach {
|
||||
val obj = it as JsonObject
|
||||
val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content)
|
||||
val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int
|
||||
cachedMapData[id] = MapData(
|
||||
id,
|
||||
imageURL,
|
||||
it.jsonObject["name"]!!.jsonPrimitive.content
|
||||
)
|
||||
)
|
||||
}
|
||||
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
|
||||
cachedCompetitiveSeriesModeData = mutableListOf()
|
||||
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
|
||||
)
|
||||
try {
|
||||
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"
|
||||
)
|
||||
} 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 Regular match data")
|
||||
} catch (e: Exception) {
|
||||
Logger.out("Error getting regular match data: ${e.cause}")
|
||||
}
|
||||
|
||||
try {
|
||||
val compMatches = data["bankaraSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedCompetitiveSeriesModeData = mutableListOf()
|
||||
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
|
||||
cachedXModeData = mutableListOf()
|
||||
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"
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Logger.out("Error getting competitive match data: ${e.cause}")
|
||||
}
|
||||
Logger.out("Updated X match data")
|
||||
|
||||
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedChallengesData = mutableListOf()
|
||||
challengeData.forEach {
|
||||
val obj = it as JsonObject
|
||||
val tpd = obj["timePeriods"]!!.jsonArray
|
||||
val setting = obj["leagueMatchSetting"]!!.jsonObject
|
||||
val event = setting["leagueMatchEvent"]!!.jsonObject
|
||||
cachedChallengesData.add(
|
||||
ChallengeModeData(
|
||||
event["leagueMatchEventId"]!!.jsonPrimitive.content,
|
||||
event["name"]!!.jsonPrimitive.content,
|
||||
event["desc"]!!.jsonPrimitive.content,
|
||||
event["regulation"]!!.jsonPrimitive.content,
|
||||
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||
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
|
||||
try {
|
||||
val xMatches = data["xSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedXModeData = mutableListOf()
|
||||
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 Challenge data")
|
||||
|
||||
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 X match data")
|
||||
} catch (e: Exception) {
|
||||
Logger.out("Error getting X match data: ${e.cause}")
|
||||
}
|
||||
|
||||
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)
|
||||
try {
|
||||
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedChallengesData = mutableListOf()
|
||||
challengeData.forEach {
|
||||
val obj = it as JsonObject
|
||||
val tpd = obj["timePeriods"]!!.jsonArray
|
||||
val setting = obj["leagueMatchSetting"]!!.jsonObject
|
||||
val event = setting["leagueMatchEvent"]!!.jsonObject
|
||||
cachedChallengesData.add(
|
||||
ChallengeModeData(
|
||||
event["leagueMatchEventId"]!!.jsonPrimitive.content,
|
||||
event["name"]!!.jsonPrimitive.content,
|
||||
event["desc"]!!.jsonPrimitive.content,
|
||||
event["regulation"]!!.jsonPrimitive.content,
|
||||
cachedMapData[setting["vsStages"]!!.jsonArray[0].jsonObject["vsStageId"]!!.jsonPrimitive.int],
|
||||
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 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")
|
||||
}
|
||||
|
@ -423,113 +458,118 @@ object Splatoon3ApiCache {
|
|||
Logger.out("Error getting splatfest data: $apiResponse")
|
||||
return
|
||||
}
|
||||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||
val festivals = json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedSplatfestData = mutableListOf()
|
||||
festivals.forEach {
|
||||
val fest = it as JsonObject
|
||||
val teams = fest.jsonObject["teams"]!!.jsonArray
|
||||
val team1 = teams[0].jsonObject
|
||||
val team1Color = team1["color"]!!.jsonObject
|
||||
var team1Result: JsonObject? = null
|
||||
if (team1["result"] !is JsonNull) {
|
||||
team1Result = team1["result"]!!.jsonObject
|
||||
}
|
||||
val team2 = teams[1].jsonObject
|
||||
val team2Color = team2["color"]!!.jsonObject
|
||||
var team2Result: JsonObject? = null
|
||||
if (team2["result"] !is JsonNull) {
|
||||
team2Result = team2["result"]!!.jsonObject
|
||||
}
|
||||
val team3 = teams[2].jsonObject
|
||||
val team3Color = team3["color"]!!.jsonObject
|
||||
var team3Result: JsonObject? = null
|
||||
if (team3["result"] !is JsonNull) {
|
||||
team3Result = team3["result"]!!.jsonObject
|
||||
}
|
||||
cachedSplatfestData.add(
|
||||
SplatfestData(
|
||||
fest.jsonObject["id"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["state"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["endTime"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["title"]!!.jsonPrimitive.content,
|
||||
Url(fest.jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||
SplatfestTeamData(
|
||||
team1["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team1Color["a"]!!.jsonPrimitive.int,
|
||||
team1Color["b"]!!.jsonPrimitive.double,
|
||||
team1Color["g"]!!.jsonPrimitive.double,
|
||||
team1Color["r"]!!.jsonPrimitive.double
|
||||
try {
|
||||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||
val festivals =
|
||||
json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
||||
cachedSplatfestData = mutableListOf()
|
||||
festivals.forEach {
|
||||
val fest = it as JsonObject
|
||||
val teams = fest.jsonObject["teams"]!!.jsonArray
|
||||
val team1 = teams[0].jsonObject
|
||||
val team1Color = team1["color"]!!.jsonObject
|
||||
var team1Result: JsonObject? = null
|
||||
if (team1["result"] !is JsonNull) {
|
||||
team1Result = team1["result"]!!.jsonObject
|
||||
}
|
||||
val team2 = teams[1].jsonObject
|
||||
val team2Color = team2["color"]!!.jsonObject
|
||||
var team2Result: JsonObject? = null
|
||||
if (team2["result"] !is JsonNull) {
|
||||
team2Result = team2["result"]!!.jsonObject
|
||||
}
|
||||
val team3 = teams[2].jsonObject
|
||||
val team3Color = team3["color"]!!.jsonObject
|
||||
var team3Result: JsonObject? = null
|
||||
if (team3["result"] !is JsonNull) {
|
||||
team3Result = team3["result"]!!.jsonObject
|
||||
}
|
||||
cachedSplatfestData.add(
|
||||
SplatfestData(
|
||||
fest.jsonObject["id"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["state"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["startTime"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["endTime"]!!.jsonPrimitive.content,
|
||||
fest.jsonObject["title"]!!.jsonPrimitive.content,
|
||||
Url(fest.jsonObject["image"]!!.jsonObject["url"]!!.jsonPrimitive.content),
|
||||
SplatfestTeamData(
|
||||
team1["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team1Color["a"]!!.jsonPrimitive.int,
|
||||
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)
|
||||
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,
|
||||
)
|
||||
),
|
||||
SplatfestTeamData(
|
||||
team2["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team2Color["a"]!!.jsonPrimitive.int,
|
||||
team2Color["b"]!!.jsonPrimitive.double,
|
||||
team2Color["g"]!!.jsonPrimitive.double,
|
||||
team2Color["r"]!!.jsonPrimitive.double
|
||||
SplatfestTeamData(
|
||||
team2["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team2Color["a"]!!.jsonPrimitive.int,
|
||||
team2Color["b"]!!.jsonPrimitive.double,
|
||||
team2Color["g"]!!.jsonPrimitive.double,
|
||||
team2Color["r"]!!.jsonPrimitive.double
|
||||
),
|
||||
if (team2Result.isNullOrEmpty() || team2Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
||||
null
|
||||
else SplatfestTeamResults(
|
||||
team2Result["isWinner"]!!.jsonPrimitive.boolean,
|
||||
team2Result["horagaiRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["voteRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
)
|
||||
),
|
||||
if (team2Result.isNullOrEmpty() || team2Result["tricolorContributionRatio"]!!.jsonPrimitive.doubleOrNull == null)
|
||||
null
|
||||
else SplatfestTeamResults(
|
||||
team2Result["isWinner"]!!.jsonPrimitive.boolean,
|
||||
team2Result["horagaiRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isHoragaiRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["voteRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isVoteRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["regularContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isRegularContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["challengeContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isChallengeContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
team2Result["tricolorContributionRatio"]!!.jsonPrimitive.double,
|
||||
team2Result["isTricolorContributionRatioTop"]!!.jsonPrimitive.boolean,
|
||||
)
|
||||
),
|
||||
SplatfestTeamData(
|
||||
team3["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team3Color["a"]!!.jsonPrimitive.int,
|
||||
team3Color["b"]!!.jsonPrimitive.double,
|
||||
team3Color["g"]!!.jsonPrimitive.double,
|
||||
team3Color["r"]!!.jsonPrimitive.double
|
||||
SplatfestTeamData(
|
||||
team3["teamName"]!!.jsonPrimitive.content,
|
||||
SplatfestColor(
|
||||
team3Color["a"]!!.jsonPrimitive.int,
|
||||
team3Color["b"]!!.jsonPrimitive.double,
|
||||
team3Color["g"]!!.jsonPrimitive.double,
|
||||
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,
|
||||
)
|
||||
),
|
||||
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
|
||||
get() = "StatusUpdater"
|
||||
override val jobIncoming: String
|
||||
get() = "/5 * * * * * 0o *" //Every 5 seconds
|
||||
get() = "/10 * * * * * 0o *" //Every 5 seconds
|
||||
override val jobType: CronjobType
|
||||
get() = CronjobType.INFINITE
|
||||
override val continueJob: Boolean
|
||||
|
@ -45,7 +45,7 @@ object StatusUpdater : ICronjob {
|
|||
refreshStatusList(System.currentTimeMillis())
|
||||
Bot.bot.kordRef.editPresence {
|
||||
this.status = PresenceStatus.DoNotDisturb
|
||||
this.playing(statusList[index])
|
||||
this.competing(statusList[index])
|
||||
}
|
||||
++index
|
||||
if (index >= statusList.size) {
|
||||
|
|
|
@ -145,6 +145,16 @@ object TimeUtil {
|
|||
.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 {
|
||||
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||
val localDateTime = LocalDateTime.parse(input, formatter)
|
||||
|
|
Loading…
Reference in a new issue