Minor cleanup in SetConfigFeature

This commit is contained in:
kageru 2019-07-17 22:56:31 +02:00
parent 31c5cd7135
commit e6f73bb178
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -4,6 +4,7 @@ import moe.kageru.kagebot.Log
import moe.kageru.kagebot.MessageUtil.sendEmbed
import moe.kageru.kagebot.config.ConfigParser
import moe.kageru.kagebot.config.RawConfig
import org.javacord.api.entity.channel.TextChannel
import org.javacord.api.event.message.MessageCreateEvent
class SetConfigFeature : MessageFeature() {
@ -17,13 +18,7 @@ class SetConfigFeature : MessageFeature() {
val rawConfig = try {
RawConfig.readFromString(newConfig)
} catch (e: IllegalStateException) {
message.channel.sendEmbed {
addField(
"An unexpected error occured. This is probably caused by a malformed config file. Perhaps this can help:",
"```$e: ${e.message}"
)
}
Log.info("Could not parse new config: $e: ${e.message}")
reportError(message.channel, e)
return
}
try {
@ -38,4 +33,15 @@ class SetConfigFeature : MessageFeature() {
}
}
}
private fun reportError(message: TextChannel, e: IllegalStateException) {
message.sendEmbed {
addField(
"An unexpected error occured. This is probably caused by a malformed config file. Perhaps this can help:",
"```$e: ${e.message}"
)
}
Log.info("Could not parse new config: $e: ${e.message}")
return
}
}