discord-kagebot/src/main/kotlin/moe/kageru/kagebot/config/RawConfig.kt
kageru 7ebafc9958
Completely rewrote config
Added a rawconfig as an intermediate step when parsing the TOML.
This will make nullability much more reliable and also gives me lots of
options in the future. It also broke all tests because reading the
config (not the raw config) now depends on the discord API. :tehe:
2019-06-12 23:43:36 +02:00

50 lines
1.7 KiB
Kotlin

package moe.kageru.kagebot.config
import com.google.gson.annotations.SerializedName
import com.moandjiezana.toml.Toml
import java.io.File
class RawConfig(
val system: RawSystemConfig?,
val localization: RawLocalization?,
@SerializedName("command") val commands: List<RawCommand>?,
@SerializedName("feature") val features: RawFeatures?
) {
companion object {
const val DEFAULT_CONFIG_PATH = "config.toml"
fun read(path: String = DEFAULT_CONFIG_PATH): RawConfig {
val toml: Toml = Toml().read(run {
val file = File(path)
if (file.isFile) {
return@run file
}
println("Config not found, falling back to defaults...")
File(this::class.java.classLoader.getResource(path)!!.toURI())
})
return toml.to(RawConfig::class.java)
}
}
}
class RawSystemConfig(val serverId: String?, val color: String?)
class RawLocalization(val permissionDenied: String?, val redirectedMessage: String?, val messageDeleted: String?)
class RawCommand(
val trigger: String?,
val response: String?,
val matchType: String?,
val permissions: RawPermissions?,
@SerializedName("action") val actions: RawMessageActions?
)
class RawPermissions(val hasOneOf: List<String>?, val hasNoneOf: List<String>?, val onlyDM: Boolean)
class RawMessageActions(val delete: Boolean, val redirect: RawRedirect?)
class RawRedirect(val target: String?, val anonymous: Boolean)
class RawFeatures(val welcome: RawWelcomeFeature?)
class RawWelcomeFeature(
val enabled: Boolean,
val content: Map<String, String>?,
val fallbackChannel: String?,
val fallbackMessage: String?
)