Compare commits

...

3 commits

Author SHA1 Message Date
734ac1b74c
WIP: started working on lilJuddApi implementation
Some checks failed
Build Gradle project / build-gradle-project (push) Has been cancelled
Signed-off-by: moonleay <contact@moonleay.net>
2024-01-01 04:12:23 +01:00
e6803f6474
fix: finished removing useless paths from the refactor
Signed-off-by: moonleay <contact@moonleay.net>
2024-01-01 04:11:49 +01:00
f3b28ac392
refactor: splatoon3ink api
Signed-off-by: moonleay <contact@moonleay.net>
2023-12-31 22:02:59 +01:00
24 changed files with 103 additions and 54 deletions

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,9 +32,9 @@ 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.splatoon3ink.Splatoon3ApiCache
import net.moonleay.lilJudd.data.api.type.ApiDataType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiDataType
import net.moonleay.lilJudd.data.api.type.ApiRequestType import net.moonleay.lilJudd.data.api.splatoon3ink.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
@ -74,6 +74,11 @@ object Bot {
exitProcess(3) exitProcess(3)
} }
if (CredentialManager.apiDomain == "empty" || CredentialManager.apiToken == "empty") {
Logger.out("The config does not contain the whole API credentials.")
exitProcess(3)
}
// Connect to the database // Connect to the database
DB.connect( DB.connect(
CredentialManager.dbDomain, CredentialManager.dbDomain,

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -29,6 +29,8 @@ object CredentialManager {
lateinit var dbName: String lateinit var dbName: String
lateinit var dbUser: String lateinit var dbUser: String
lateinit var dbPassword: String lateinit var dbPassword: String
lateinit var apiDomain: String
lateinit var apiToken: String
///Load the needed credentials, generate a config if there is none ///Load the needed credentials, generate a config if there is none
fun load() { fun load() {
@ -51,6 +53,8 @@ object CredentialManager {
dbName = prop.getProperty("dbName") dbName = prop.getProperty("dbName")
dbUser = prop.getProperty("dbUser") dbUser = prop.getProperty("dbUser")
dbPassword = prop.getProperty("dbPassword") dbPassword = prop.getProperty("dbPassword")
apiDomain = prop.getProperty("apiDomain")
apiToken = prop.getProperty("apiToken")
input.close() input.close()
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
@ -83,6 +87,8 @@ object CredentialManager {
prop.setProperty("dbName", "empty") prop.setProperty("dbName", "empty")
prop.setProperty("dbUser", "empty") prop.setProperty("dbUser", "empty")
prop.setProperty("dbPassword", "empty") prop.setProperty("dbPassword", "empty")
prop.setProperty("apiDomain", "empty")
prop.setProperty("apiToken", "empty")
prop.store(output, null) prop.store(output, null)
output.close() output.close()

View file

@ -0,0 +1,36 @@
/*
* lilJudd
* Copyright (C) 2024 moonleay
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.api.liljudd
import net.moonleay.lilJudd.data.CredentialManager
object LilJuddApi {
val CONFIG_BASE = "${CredentialManager.apiDomain}/config/"
val MATCH_BASE = "${CredentialManager.apiDomain}/match/"
val TIMEPLANNINGMESSAGES_BASE = "${CredentialManager.apiDomain}/tp_messages/"
// GET https://liljudd.ink/api/config/<guild_id>/
// DELETE https://liljudd.ink/api/config/<guild_id>/
// GET https://liljudd.ink/api/tp_messages/<guild_id>/
// PUT https://liljudd.ink/api/tp_messages/<guild_id>/
// POST https://liljudd.ink/api/match/<guild_id>/<channel_id>/
// PUT https://liljudd.ink/api/match/<guild_id>/<channel_id>/<match_message_id>/
// GET https://liljudd.ink/api/match/<guild_id>/
}

View file

@ -16,9 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api package net.moonleay.lilJudd.data.api.splatoon3ink
import net.moonleay.lilJudd.data.api.entry.schedule.ModeData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule.ModeData
import net.moonleay.lilJudd.util.TimeUtil import net.moonleay.lilJudd.util.TimeUtil
object Splatoon3Api { object Splatoon3Api {

View file

@ -16,21 +16,21 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api package net.moonleay.lilJudd.data.api.splatoon3ink
import io.ktor.http.* import io.ktor.http.*
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
import net.moonleay.lilJudd.data.api.entry.coop.CoopGearData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.coop.CoopGearData
import net.moonleay.lilJudd.data.api.entry.schedule.* import net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule.*
import net.moonleay.lilJudd.data.api.entry.splatfest.SplatfestColor import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest.SplatfestColor
import net.moonleay.lilJudd.data.api.entry.splatfest.SplatfestData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest.SplatfestData
import net.moonleay.lilJudd.data.api.entry.splatfest.SplatfestTeamData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest.SplatfestTeamData
import net.moonleay.lilJudd.data.api.entry.splatfest.SplatfestTeamResults import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest.SplatfestTeamResults
import net.moonleay.lilJudd.data.api.entry.splatnet.BrandData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet.BrandData
import net.moonleay.lilJudd.data.api.entry.splatnet.GearAbilityData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet.GearAbilityData
import net.moonleay.lilJudd.data.api.entry.splatnet.SplatnetItemData import net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet.SplatnetItemData
import net.moonleay.lilJudd.data.api.type.ApiDataType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiDataType
import net.moonleay.lilJudd.data.api.type.ApiRequestType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiRequestType
import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.NetUtil import net.moonleay.lilJudd.util.NetUtil
import net.moonleay.liljudd.build.BuildConstants import net.moonleay.liljudd.build.BuildConstants
@ -49,13 +49,14 @@ object Splatoon3ApiCache {
internal var cachedChallengesData = mutableListOf<ChallengeModeData>() internal var cachedChallengesData = mutableListOf<ChallengeModeData>()
internal var cachedShiftData = mutableListOf<ShiftData>() internal var cachedShiftData = mutableListOf<ShiftData>()
internal var cachedBigRunShiftData = mutableListOf<ShiftData>() internal var cachedBigRunShiftData = mutableListOf<ShiftData>()
internal var cachedCoopRewardsData = mutableListOf<CoopGearData>() internal var cachedCoopRewardsData =
mutableListOf<CoopGearData>()
internal var cachedSplatnetItemData = mutableListOf<SplatnetItemData>() internal var cachedSplatnetItemData = mutableListOf<SplatnetItemData>()
internal var cachedSplatnetLimitedItemData = mutableListOf<SplatnetItemData>() internal var cachedSplatnetLimitedItemData = mutableListOf<SplatnetItemData>()
internal lateinit var splatnetShopBrandData: BrandData internal lateinit var splatnetShopBrandData: BrandData
internal lateinit var splatnetShopNextBrandData: BrandData internal lateinit var splatnetShopNextBrandData: BrandData
fun updateData(dataType: ApiDataType, requestType: ApiRequestType) { fun updateData(dataType: ApiDataType, requestType: ApiRequestType) {
Logger.out("Updating data for $dataType with USER-AGENT: $user_agent") Logger.out("Updating data for $dataType with USER-AGENT: ${user_agent}")
Logger.out("Reason for update: $requestType") Logger.out("Reason for update: $requestType")
when (dataType) { when (dataType) {
ApiDataType.SCHEDULES -> { ApiDataType.SCHEDULES -> {
@ -225,11 +226,12 @@ object Splatoon3ApiCache {
val obj = it as JsonObject val obj = it as JsonObject
val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content) val imageURL = Url(obj.jsonObject["originalImage"]!!.jsonObject["url"]!!.jsonPrimitive.content)
val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int val id = obj.jsonObject["vsStageId"]!!.jsonPrimitive.int
cachedMapData[id] = MapData( cachedMapData[id] =
id, MapData(
imageURL, id,
it.jsonObject["name"]!!.jsonPrimitive.content imageURL,
) it.jsonObject["name"]!!.jsonPrimitive.content
)
} }
Logger.out("Updated maplist data") Logger.out("Updated maplist data")
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.coop package net.moonleay.lilJudd.data.api.splatoon3ink.entry.coop
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
data class ChallengeModeData( data class ChallengeModeData(
val leagueMatchEventId: String, val leagueMatchEventId: String,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
data class ModeData( data class ModeData(
val startTime: String, val startTime: String,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
data class TimePeriodData( data class TimePeriodData(
val startTime: String, val startTime: String,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.schedule package net.moonleay.lilJudd.data.api.splatoon3ink.entry.schedule
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatfest package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest
data class SplatfestColor( data class SplatfestColor(
val a: Int, val a: Int,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatfest package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatfest package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest
data class SplatfestTeamData( data class SplatfestTeamData(
val teamName: String, val teamName: String,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatfest package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatfest
data class SplatfestTeamResults( data class SplatfestTeamResults(
val isWinner: Boolean, val isWinner: Boolean,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatnet package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatnet package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.entry.splatnet package net.moonleay.lilJudd.data.api.splatoon3ink.entry.splatnet
import io.ktor.http.* import io.ktor.http.*

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.type package net.moonleay.lilJudd.data.api.splatoon3ink.type
enum class ApiDataType { enum class ApiDataType {
SCHEDULES, SCHEDULES,

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.moonleay.lilJudd.data.api.type package net.moonleay.lilJudd.data.api.splatoon3ink.type
enum class ApiRequestType(val nameToDisplay: String) { enum class ApiRequestType(val nameToDisplay: String) {
AUTOMATIC_CACHE_UPDATE("automatic request to update the cache"), AUTOMATIC_CACHE_UPDATE("automatic request to update the cache"),

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,9 +20,9 @@ package net.moonleay.lilJudd.jobs
import dev.inmo.krontab.KronScheduler import dev.inmo.krontab.KronScheduler
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import net.moonleay.lilJudd.data.api.Splatoon3ApiCache import net.moonleay.lilJudd.data.api.splatoon3ink.Splatoon3ApiCache
import net.moonleay.lilJudd.data.api.type.ApiDataType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiDataType
import net.moonleay.lilJudd.data.api.type.ApiRequestType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiRequestType
import net.moonleay.lilJudd.jobs.component.CronjobType import net.moonleay.lilJudd.jobs.component.CronjobType
import net.moonleay.lilJudd.jobs.component.ICronjob import net.moonleay.lilJudd.jobs.component.ICronjob
import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.Logger

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,9 +20,9 @@ package net.moonleay.lilJudd.jobs
import dev.inmo.krontab.KronScheduler import dev.inmo.krontab.KronScheduler
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import net.moonleay.lilJudd.data.api.Splatoon3ApiCache import net.moonleay.lilJudd.data.api.splatoon3ink.Splatoon3ApiCache
import net.moonleay.lilJudd.data.api.type.ApiDataType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiDataType
import net.moonleay.lilJudd.data.api.type.ApiRequestType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiRequestType
import net.moonleay.lilJudd.jobs.component.CronjobType import net.moonleay.lilJudd.jobs.component.CronjobType
import net.moonleay.lilJudd.jobs.component.ICronjob import net.moonleay.lilJudd.jobs.component.ICronjob
import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.Logger

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,9 +20,9 @@ package net.moonleay.lilJudd.jobs
import dev.inmo.krontab.KronScheduler import dev.inmo.krontab.KronScheduler
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import net.moonleay.lilJudd.data.api.Splatoon3ApiCache import net.moonleay.lilJudd.data.api.splatoon3ink.Splatoon3ApiCache
import net.moonleay.lilJudd.data.api.type.ApiDataType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiDataType
import net.moonleay.lilJudd.data.api.type.ApiRequestType import net.moonleay.lilJudd.data.api.splatoon3ink.type.ApiRequestType
import net.moonleay.lilJudd.jobs.component.CronjobType import net.moonleay.lilJudd.jobs.component.CronjobType
import net.moonleay.lilJudd.jobs.component.ICronjob import net.moonleay.lilJudd.jobs.component.ICronjob
import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.Logger