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
2019-10-18 19:34:41 +02:00
import moe.kageru.kagebot.config.Config.system
2019-10-06 16:14:01 +02:00
import java.awt.Color
2019-06-12 23:43:36 +02:00
import java.io.File
class RawConfig (
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 > ( )
2019-10-18 19:34:41 +02:00
val color by kotlin . lazy { Color . decode ( system [ rawColor ] ) !! }
2019-10-06 16:14:01 +02:00
}
2019-10-18 19:34:41 +02:00
object LocalizationSpec : ConfigSpec ( ) {
val permissionDenied by optional ( " You do not have the permission to use this command. " )
val redirectedMessage by optional ( " says " )
val messageDeleted by optional ( " Your message was deleted. " )
val timeout by optional ( " You have been timed out for @@ minutes. " )
}