2019-07-13 15:39:50 +02:00
package moe.kageru.kagebot.config
import moe.kageru.kagebot.Globals
2019-10-06 16:14:01 +02:00
import moe.kageru.kagebot.config.SystemSpec.serverId
2019-07-13 15:39:50 +02:00
import moe.kageru.kagebot.features.Features
2019-07-14 17:14:23 +02:00
import java.io.File
2019-07-13 15:39:50 +02:00
object ConfigParser {
2019-07-14 17:14:23 +02:00
val configFile : File = File ( RawConfig . DEFAULT _CONFIG _PATH )
2019-10-06 16:14:01 +02:00
fun initialLoad ( file : String ) {
val rawConfig = RawConfig . read ( file )
2019-10-18 19:34:41 +02:00
val configFile = RawConfig . getFile ( file )
val config = Config . systemSpec . file ( configFile )
Config . system = config
2019-10-06 16:14:01 +02:00
Config . server = Globals . api . getServerById ( config [ serverId ] )
2019-07-25 21:24:46 +02:00
. orElseThrow { IllegalArgumentException ( " Invalid server configured. " ) }
2019-10-18 19:34:41 +02:00
Config . localization = Config . localeSpec . file ( configFile )
2019-07-13 15:39:50 +02:00
reloadFeatures ( rawConfig )
2019-10-18 20:48:43 +02:00
Config . commandConfig = Config . commandSpec . file ( configFile )
2019-07-13 15:39:50 +02:00
}
fun reloadFeatures ( rawConfig : RawConfig ) {
Config . features = rawConfig . features ?. let ( :: Features )
2019-07-23 21:50:55 +02:00
?: Features ( RawFeatures ( null , null ) )
2019-07-13 15:39:50 +02:00
}
}