From c0531acab706219d084b1c04a407806cf69e76e9 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 12 Jan 2021 17:37:56 +0800 Subject: [PATCH] Do not kill backend if auto-login failed --- .../src/internal/MiraiConsoleImplementationBridge.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index e1c7d62f1..65d73fb5d 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -16,7 +16,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.runBlocking import net.mamoe.mirai.Bot -import net.mamoe.mirai.alsoLogin import net.mamoe.mirai.console.MalformedMiraiConsoleImplementationError import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription @@ -236,9 +235,10 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI } } } - when (account.password.kind) { + + val bot = when (account.password.kind) { PLAIN -> { - MiraiConsole.addBot(id, account.password.value, BotConfiguration::configBot).alsoLogin() + MiraiConsole.addBot(id, account.password.value, BotConfiguration::configBot) } MD5 -> { val md5 = kotlin.runCatching { @@ -246,9 +246,13 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI }.getOrElse { error("Bad auto-login md5: '${account.password.value}' for account $id") } - MiraiConsole.addBot(id, md5, BotConfiguration::configBot).alsoLogin() + MiraiConsole.addBot(id, md5, BotConfiguration::configBot) } } + + runCatching { bot.login() }.getOrElse { + mainLogger.error(it) + } } }