Less nesting in config
This commit is contained in:
parent
c72219eabb
commit
80eca6a2af
|
@ -3,7 +3,7 @@ package moe.kageru.kagebot
|
||||||
import com.moandjiezana.toml.Toml
|
import com.moandjiezana.toml.Toml
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Config(val system: System, val commands: Commands) {
|
class Config(val system: System, val commands: List<Command>) {
|
||||||
companion object {
|
companion object {
|
||||||
val config: Config by lazy { read("config.toml") }
|
val config: Config by lazy { read("config.toml") }
|
||||||
val secret = File("secret").readText().replace("\n", "")
|
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)
|
val parsed = rawConfig.to(Config::class.java)
|
||||||
return Config(
|
return Config(
|
||||||
System(parsed.system),
|
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)
|
constructor(system: System) : this(system.serverId, system.admins)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper around [Command]s for TOML deserialization.
|
|
||||||
*/
|
|
||||||
data class Commands(val commands: List<Command>)
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ fun createBot() {
|
||||||
})
|
})
|
||||||
log.info("kagebot Mk II running")
|
log.info("kagebot Mk II running")
|
||||||
api.addMessageCreateListener { event ->
|
api.addMessageCreateListener { event ->
|
||||||
for (command in config.commands.commands) {
|
for (command in config.commands) {
|
||||||
if (command.matches(event.messageContent)) {
|
if (command.matches(event.messageContent)) {
|
||||||
event.channel.sendMessage(command.respond())
|
event.channel.sendMessage(command.respond())
|
||||||
break
|
break
|
||||||
|
|
|
@ -4,15 +4,11 @@ admins = [
|
||||||
"137780880344088576"
|
"137780880344088576"
|
||||||
]
|
]
|
||||||
|
|
||||||
[commands]
|
[[commands]]
|
||||||
commands = [
|
trigger = "!ping"
|
||||||
{
|
response = "pong"
|
||||||
trigger = "!ping",
|
|
||||||
response = "pong"
|
[[commands]]
|
||||||
},
|
trigger = "somewhere"
|
||||||
{
|
response = "found it"
|
||||||
trigger = "somewhere",
|
matchType = "CONTAINS"
|
||||||
response = "found it",
|
|
||||||
matchType = "CONTAINS"
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Reference in New Issue
Block a user