diff --git a/.gitignore b/.gitignore index 32e643c..addaa79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # This contains secrets -app/config/botConfig.yml +app/config/botConfig.json # Created by https://www.toptal.com/developers/gitignore/api/kotlin,osx,windows,linux,intellij,gradle # Edit at https://www.toptal.com/developers/gitignore?templates=kotlin,osx,windows,linux,intellij,gradle diff --git a/app/config/botConfig-example.json b/app/config/botConfig-example.json new file mode 100644 index 0000000..56dbdfd --- /dev/null +++ b/app/config/botConfig-example.json @@ -0,0 +1,14 @@ +{ + "discord_token": "", + "pterodactyl_token": "", + "pterodactyl_url": "", + "whitelist": { + "enabled": true, + "whitelist_channel_id": 1183054905913655399, + "whitelist_authorized_role_id": 1143743030541680664 + }, + "backup_download": { + "enabled": false + }, + "is_dev_env": true +} diff --git a/app/config/botConfig-example.yml b/app/config/botConfig-example.yml deleted file mode 100644 index b580920..0000000 --- a/app/config/botConfig-example.yml +++ /dev/null @@ -1,8 +0,0 @@ -token: -pterodactylToken: -pterodactylUrl: -whitelist: - enabled: true - whitelistChannelId: 1144376300790890567 - whitelistAuthorizedRoleId: 1143743030541680664 # Server Operators -enableBackupDownloads: true \ No newline at end of file diff --git a/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/App.kt b/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/App.kt index e8c0110..e63621e 100644 --- a/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/App.kt +++ b/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/App.kt @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.module.kotlin.KotlinFeature import com.fasterxml.jackson.module.kotlin.KotlinModule +import com.google.gson.Gson import dev.kord.common.annotation.KordPreview import dev.kord.gateway.Intents import dev.kord.x.emoji.Emojis @@ -24,12 +25,13 @@ import me.jakejmattson.discordkt.dsl.ListenerException import me.jakejmattson.discordkt.dsl.bot import me.jakejmattson.discordkt.locale.Language import java.awt.Color +import java.io.Reader import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.Path -private val configPath = FileSystems.getDefault().getPath("config", "botConfig.yml") -private val botConfig: BotConfig = loadConfigFromFile(configPath) +private val configPath = FileSystems.getDefault().getPath("config", "botConfig.json") +private val botConfig: BotConfig = loadBotConfig(configPath) private val pterodactyl: Pterodactyl = Pterodactyl(botConfig.pterodactylToken, botConfig.pterodactylUrl) @@ -145,22 +147,9 @@ suspend fun main(args: Array) { } } -private fun loadConfigFromFile(path: Path): BotConfig { - val mapper = ObjectMapper(YAMLFactory()) - mapper.registerModule( - KotlinModule.Builder() - .withReflectionCacheSize(512) - .configure(KotlinFeature.NullToEmptyCollection, false) - .configure(KotlinFeature.NullToEmptyMap, false) - .configure(KotlinFeature.NullIsSameAsDefault, false) - .configure(KotlinFeature.SingletonSupport, true) - .configure(KotlinFeature.StrictNullChecks, false) - .build(), - ) - - return Files.newBufferedReader(path).use { - mapper.readValue(it, BotConfig::class.java) - } +private fun loadBotConfig(path: Path): BotConfig { + val reader: Reader = Files.newBufferedReader(path) + return Gson().fromJson(reader, BotConfig::class.java) } fun botConfig(): BotConfig { diff --git a/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/data/config/BotConfig.kt b/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/data/config/BotConfig.kt index 57eb6dc..0964892 100644 --- a/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/data/config/BotConfig.kt +++ b/app/src/main/kotlin/ca/fireball1725/lcs/discordbot/data/config/BotConfig.kt @@ -11,28 +11,35 @@ import com.google.gson.annotations.SerializedName data class BotConfig( @SerializedName("discord_token") val discordToken: String, + @SerializedName("pterodactyl_token") val pterodactylToken: String, + @SerializedName("pterodactyl_url") val pterodactylUrl: String, + @SerializedName("is_dev_env") val isDevelopmentEnvironment: Boolean, + @SerializedName("whitelist") - val whitelist: BotConfigConfigWhitelist? = BotConfigConfigWhitelist(), + val whitelist: BotConfigConfigWhitelist, + @SerializedName("backup_download") val backupDownload: BotConfigConfigBackupDownload, ) data class BotConfigConfigWhitelist( @SerializedName("enabled") - val enabled: Boolean = false, + val enabled: Boolean, + @SerializedName("whitelist_channel_id") - val channelId: Long? = null, + val channelId: Long, + @SerializedName("whitelist_authorized_role_id") - val authorizedRoleId: Long? = null, + val authorizedRoleId: Long, ) data class BotConfigConfigBackupDownload( - @SerializedName("allow_backup_downloads") + @SerializedName("enabled") val enabled: Boolean, )