Less nesting in config

This commit is contained in:
kageru 2019-06-08 13:03:33 +02:00
parent c72219eabb
commit 80eca6a2af
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
3 changed files with 11 additions and 19 deletions

View File

@ -3,7 +3,7 @@ package moe.kageru.kagebot
import com.moandjiezana.toml.Toml
import java.io.File
class Config(val system: System, val commands: Commands) {
class Config(val system: System, val commands: List<Command>) {
companion object {
val config: Config by lazy { read("config.toml") }
val secret = File("secret").readText().replace("\n", "")
@ -20,7 +20,7 @@ class Config(val system: System, val commands: Commands) {
val parsed = rawConfig.to(Config::class.java)
return Config(
System(parsed.system),
Commands(parsed.commands.commands.map { Command(it) })
parsed.commands.map { Command(it) }
)
}
@ -34,7 +34,3 @@ data class System(val serverId: String, val admins: List<String>) {
constructor(system: System) : this(system.serverId, system.admins)
}
/**
* Wrapper around [Command]s for TOML deserialization.
*/
data class Commands(val commands: List<Command>)

View File

@ -23,7 +23,7 @@ fun createBot() {
})
log.info("kagebot Mk II running")
api.addMessageCreateListener { event ->
for (command in config.commands.commands) {
for (command in config.commands) {
if (command.matches(event.messageContent)) {
event.channel.sendMessage(command.respond())
break

View File

@ -4,15 +4,11 @@ admins = [
"137780880344088576"
]
[commands]
commands = [
{
trigger = "!ping",
response = "pong"
},
{
trigger = "somewhere",
response = "found it",
matchType = "CONTAINS"
}
]
[[commands]]
trigger = "!ping"
response = "pong"
[[commands]]
trigger = "somewhere"
response = "found it"
matchType = "CONTAINS"