From e6f73bb1787c5d3b4b60ca11a1a58aa3d2a58729 Mon Sep 17 00:00:00 2001 From: kageru Date: Wed, 17 Jul 2019 22:56:31 +0200 Subject: [PATCH] Minor cleanup in SetConfigFeature --- .../kagebot/features/SetConfigFeature.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/moe/kageru/kagebot/features/SetConfigFeature.kt b/src/main/kotlin/moe/kageru/kagebot/features/SetConfigFeature.kt index 8716e51..a3bdf81 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/SetConfigFeature.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/SetConfigFeature.kt @@ -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 + } }