mamoe / mirai-console

mirai 的高效率 QQ 机器人控制台

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

支持 LoginCommand 指定协议

sayri23 opened this issue · comments

如题

目前没有支持, 可以自行通过插件调用 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.

login 命令是支持指定协议的