2019-06-12 23:43:36 +02:00
package moe.kageru.kagebot.config
import com.google.gson.annotations.SerializedName
import com.moandjiezana.toml.Toml
2019-10-06 16:14:01 +02:00
import com.uchuhimo.konf.ConfigSpec
import moe.kageru.kagebot.config.Config.config
import java.awt.Color
2019-06-12 23:43:36 +02:00
import java.io.File
class RawConfig (
val localization : RawLocalization ? ,
2019-07-13 14:52:05 +02:00
@SerializedName ( " command " )
val commands : List < RawCommand > ? ,
@SerializedName ( " feature " )
val features : RawFeatures ?
2019-06-12 23:43:36 +02:00
) {
companion object {
2019-07-14 17:14:23 +02:00
const val DEFAULT _CONFIG _PATH = " config.toml "
2019-06-12 23:43:36 +02:00
2019-07-13 14:52:05 +02:00
fun readFromString ( tomlContent : String ) : RawConfig = Toml ( ) . read ( tomlContent ) . to ( RawConfig :: class . java )
2019-06-14 21:23:17 +02:00
2019-10-06 16:14:01 +02:00
fun getFile ( path : String ) : File {
2019-07-17 22:51:36 +02:00
val file = File ( path )
if ( file . isFile ) {
return file
}
println ( " Config not found, falling back to defaults... " )
return File ( this :: class . java . classLoader . getResource ( path ) !! . toURI ( ) )
}
2019-06-12 23:43:36 +02:00
fun read ( path : String = DEFAULT _CONFIG _PATH ) : RawConfig {
2019-07-17 22:51:36 +02:00
val toml : Toml = Toml ( ) . read ( getFile ( path ) )
2019-06-12 23:43:36 +02:00
return toml . to ( RawConfig :: class . java )
}
}
}
2019-10-06 16:14:01 +02:00
object SystemSpec : ConfigSpec ( ) {
private val rawColor by optional ( " #1793d0 " , name = " color " )
val serverId by required < String > ( )
val color by kotlin . lazy { Color . decode ( config [ rawColor ] ) !! }
}
2019-07-25 21:24:46 +02:00
class RawLocalization (
val permissionDenied : String ? ,
val redirectedMessage : String ? ,
val messageDeleted : String ? ,
val timeout : String ?
)