43 lines
1.4 KiB
Kotlin
43 lines
1.4 KiB
Kotlin
package moe.kageru.kagebot
|
|
|
|
import com.google.gson.annotations.SerializedName
|
|
import com.moandjiezana.toml.Toml
|
|
import org.javacord.api.DiscordApi
|
|
import org.javacord.api.entity.server.Server
|
|
import java.io.File
|
|
|
|
class Config(
|
|
val system: System,
|
|
val localization: Localization,
|
|
@SerializedName("command") val commands: List<Command>
|
|
) {
|
|
companion object {
|
|
val config: Config by lazy { read("config.toml") }
|
|
val secret = File("secret").readText().replace("\n", "")
|
|
var server: Server? = null
|
|
get() = field!!
|
|
var api: DiscordApi? = null
|
|
get() = field!!
|
|
|
|
private fun read(path: String): Config {
|
|
val rawConfig: 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())
|
|
})
|
|
val parsed = rawConfig.to(Config::class.java)
|
|
return Config(
|
|
parsed.system,
|
|
parsed.localization,
|
|
parsed.commands.map { Command(it) }
|
|
)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
data class System(val serverId: String, val color: String)
|
|
data class Localization(val permissionDenied: String, val redirectedMessage: String, val messageDeleted: String) |