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 ? ,
@SerializedName ( " command " ) val commands : List < RawCommand > ? ,
@SerializedName ( " feature " ) val features : RawFeatures ?
) {
companion object {
const val DEFAULT _CONFIG _PATH = " config.toml "
2019-06-14 21:23:17 +02:00
fun readFromString ( tomlContent : String ) = Toml ( ) . read ( tomlContent ) . to ( RawConfig :: class . java )
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 ? )
class RawCommand (
val trigger : String ? ,
val response : String ? ,
val matchType : String ? ,
val permissions : RawPermissions ? ,
2019-07-07 10:54:20 +02:00
@SerializedName ( " action " ) val actions : RawMessageActions ? ,
val embed : Map < String , String > ?
2019-06-12 23:43:36 +02:00
)
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 )
2019-06-15 14:15:34 +02:00
class RawFeatures ( val welcome : RawWelcomeFeature ? , val debug : RawDebugFeatures ? )
2019-06-12 23:43:36 +02:00
class RawWelcomeFeature (
val enabled : Boolean ,
val content : Map < String , String > ? ,
val fallbackChannel : String ? ,
val fallbackMessage : String ?
2019-06-15 14:15:34 +02:00
)
class RawDebugFeatures ( var enabled : Boolean )