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,6 +192,7 @@ object Splatoon3ApiCache {
|
||||||
Logger.out("Error getting coop data: $apiResponse")
|
Logger.out("Error getting coop data: $apiResponse")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
val json = Json.parseToJsonElement(apiResponse)
|
val json = Json.parseToJsonElement(apiResponse)
|
||||||
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
val data = json.jsonObject["data"]!!.jsonObject["coopResult"]!!.jsonObject["monthlyGear"]!!.jsonObject
|
||||||
cachedCoopRewardsData = mutableListOf()
|
cachedCoopRewardsData = mutableListOf()
|
||||||
|
@ -203,6 +204,9 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
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,6 +218,7 @@ 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
|
||||||
|
|
||||||
|
try {
|
||||||
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
val mapList = data["vsStages"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedMapData = mutableMapOf()
|
cachedMapData = mutableMapOf()
|
||||||
mapList.forEach {
|
mapList.forEach {
|
||||||
|
@ -227,7 +232,11 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated maplist data")
|
Logger.out("Updated maplist data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting maplist data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
val regularMatches = data["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
val regularMatches = data["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedRegularModeData = mutableListOf()
|
cachedRegularModeData = mutableListOf()
|
||||||
regularMatches.forEach {
|
regularMatches.forEach {
|
||||||
|
@ -247,7 +256,11 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated Regular match data")
|
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
|
val compMatches = data["bankaraSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedCompetitiveSeriesModeData = mutableListOf()
|
cachedCompetitiveSeriesModeData = mutableListOf()
|
||||||
cachedCompetitiveOpenModeData = mutableListOf()
|
cachedCompetitiveOpenModeData = mutableListOf()
|
||||||
|
@ -288,6 +301,10 @@ object Splatoon3ApiCache {
|
||||||
}
|
}
|
||||||
Logger.out("Updated Competitive match data")
|
Logger.out("Updated Competitive match data")
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting competitive match data: ${e.cause}")
|
||||||
|
}
|
||||||
|
try {
|
||||||
val xMatches = data["xSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
val xMatches = data["xSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedXModeData = mutableListOf()
|
cachedXModeData = mutableListOf()
|
||||||
xMatches.forEach {
|
xMatches.forEach {
|
||||||
|
@ -307,7 +324,11 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated X match data")
|
Logger.out("Updated X match data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting X match data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
val challengeData = data["eventSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedChallengesData = mutableListOf()
|
cachedChallengesData = mutableListOf()
|
||||||
challengeData.forEach {
|
challengeData.forEach {
|
||||||
|
@ -342,8 +363,13 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated Challenge data")
|
Logger.out("Updated Challenge data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting Challenge data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
val shiftData = data["coopGroupingSchedule"]!!.jsonObject["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
try {
|
||||||
|
val shiftData =
|
||||||
|
data["coopGroupingSchedule"]!!.jsonObject["regularSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedShiftData = mutableListOf()
|
cachedShiftData = mutableListOf()
|
||||||
shiftData.forEach {
|
shiftData.forEach {
|
||||||
val obj = it as JsonObject
|
val obj = it as JsonObject
|
||||||
|
@ -377,8 +403,14 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Logger.out("Updated shift data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting coopGrouping data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
val bigRunData = data["coopGroupingSchedule"]!!.jsonObject["bigRunSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
try {
|
||||||
|
val bigRunData =
|
||||||
|
data["coopGroupingSchedule"]!!.jsonObject["bigRunSchedules"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedBigRunShiftData = mutableListOf()
|
cachedBigRunShiftData = mutableListOf()
|
||||||
bigRunData.forEach {
|
bigRunData.forEach {
|
||||||
val obj = it as JsonObject
|
val obj = it as JsonObject
|
||||||
|
@ -413,6 +445,9 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated big run data")
|
Logger.out("Updated big run data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting big run data: ${e.cause}")
|
||||||
|
}
|
||||||
|
|
||||||
Logger.out("Updated all Schedules")
|
Logger.out("Updated all Schedules")
|
||||||
}
|
}
|
||||||
|
@ -423,8 +458,10 @@ object Splatoon3ApiCache {
|
||||||
Logger.out("Error getting splatfest data: $apiResponse")
|
Logger.out("Error getting splatfest data: $apiResponse")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
val json = Json.decodeFromString(apiResponse) as JsonObject
|
val json = Json.decodeFromString(apiResponse) as JsonObject
|
||||||
val festivals = json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
val festivals =
|
||||||
|
json["US"]!!.jsonObject["data"]!!.jsonObject["festRecords"]!!.jsonObject["nodes"]!!.jsonArray
|
||||||
cachedSplatfestData = mutableListOf()
|
cachedSplatfestData = mutableListOf()
|
||||||
festivals.forEach {
|
festivals.forEach {
|
||||||
val fest = it as JsonObject
|
val fest = it as JsonObject
|
||||||
|
@ -531,5 +568,8 @@ object Splatoon3ApiCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Logger.out("Updated Splatfest data")
|
Logger.out("Updated Splatfest data")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logger.out("Error getting splatfest data: ${e.cause}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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