Do not kill backend if auto-login failed

This commit is contained in:
Him188 2021-01-12 17:37:56 +08:00
parent 0b957d6475
commit c0531acab7

View File

@ -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)
}
}
}