支持 LoginCommand 指定协议
sayri23 opened this issue · comments
Meltryllis commented
如题
Him188 commented
目前没有支持, 可以自行通过插件调用 MiraiConsole.addBot
实现.
附内置登录指令的实现:
public object LoginCommand : SimpleCommand(
ConsoleCommandOwner, "login", "登录",
description = "登录一个账号",
), BuiltInCommandInternal {
private suspend fun Bot.doLogin() = kotlin.runCatching {
login(); this
}.onFailure { close() }.getOrThrow()
@Handler
@JvmOverloads
public suspend fun CommandSender.handle(
@Name("qq") id: Long,
password: String,
protocol: BotConfiguration.MiraiProtocol? = null,
) {
kotlin.runCatching {
MiraiConsole.addBot(id, password) {
if (protocol != null) {
this.protocol = protocol
}
}.doLogin()
}.fold(
onSuccess = { sendMessage("${it.nick} ($id) Login successful") },
onFailure = { throwable ->
sendMessage(
"Login failed: ${throwable.localizedMessage ?: throwable.message ?: throwable.toString()}" +
if (this is CommandSenderOnMessage<*>) {
CommandManagerImpl.launch(CoroutineName("stacktrace delayer from Login")) {
fromEvent.nextMessageOrNull(60.secondsToMillis) { it.message.contentEquals("stacktrace") }
}
"\n 1 分钟内发送 stacktrace 以获取堆栈信息"
} else ""
)
throw throwable
}
)
}
}
备注: 没有支持是因为 MiraiProtocol
没有对应的 parser.
微莹·纤绫 commented
login 命令是支持指定协议的