2019-06-12 23:43:36 +02:00
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 ? ,
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-06-12 23:43:36 +02:00
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 ? )