Fix builtin command Login

This commit is contained in:
Him188 2020-08-20 13:51:59 +08:00
parent 657c2ac613
commit 2843f91d02

View File

@ -122,34 +122,34 @@ public object BuiltInCommands {
} }
exitProcess(0) exitProcess(0)
} }
}
public object Login : SimpleCommand( public object Login : SimpleCommand(
ConsoleCommandOwner, "login", ConsoleCommandOwner, "login",
description = "Log in a bot account." description = "Log in a bot account."
), BuiltInCommand { ), BuiltInCommand {
@Handler @Handler
public suspend fun CommandSender.handle(id: Long, password: String) { public suspend fun CommandSender.handle(id: Long, password: String) {
kotlin.runCatching { kotlin.runCatching {
MiraiConsole.addBot(id, password).alsoLogin() MiraiConsole.addBot(id, password).alsoLogin()
}.fold( }.fold(
onSuccess = { sendMessage("${it.nick} ($id) Login succeed") }, onSuccess = { sendMessage("${it.nick} ($id) Login succeed") },
onFailure = { throwable -> onFailure = { throwable ->
sendMessage( sendMessage(
"Login failed: ${throwable.localizedMessage ?: throwable.message ?: throwable.toString()}" + "Login failed: ${throwable.localizedMessage ?: throwable.message ?: throwable.toString()}" +
if (this is MessageEventContextAware<*>) { if (this is MessageEventContextAware<*>) {
this.fromEvent.selectMessagesUnit { this.fromEvent.selectMessagesUnit {
"stacktrace" reply { "stacktrace" reply {
throwable.stackTraceToString() throwable.stackTraceToString()
}
} }
"test" }
} else "") "test"
} else "")
throw throwable throw throwable
} }
) )
}
} }
} }
} }