Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneBot12Adapter 做正向 WS 适配时,遇到的容器 Bug #354

Open
crazywhalecc opened this issue May 20, 2023 · 0 comments
Open

OneBot12Adapter 做正向 WS 适配时,遇到的容器 Bug #354

crazywhalecc opened this issue May 20, 2023 · 0 comments
Assignees
Labels
bug 意外行为或意外问题

Comments

@crazywhalecc
Copy link
Member

crazywhalecc commented May 20, 2023

受影响版本

3.1.9

描述

我在做正向 WS 适配的时候,对 OneBot12Adapter 做一些通用型适配,例如注册机器人状态,更新机器人状态的部分。

我使用所在容器不同来适配正反向 WS,下面是我修改的部分代码,在 OneBot12Adapter 的 handleStatusUpdate() 方法内:

if (container()->has(WebSocketMessageEvent::class)) {
                    $message_event = container()->get(WebSocketMessageEvent::class);
                    BotMap::registerBotWithFd(
                        bot_id: $bot['self']['user_id'],
                        platform: $bot['self']['platform'],
                        status: $bot['good'] ?? false,
                        fd: $message_event->getFd(),
                        flag: $message_event->getSocketFlag()
                    );
                }

我在使用正向 WS 的时候,使用正向适配器,注册了 BotEvent 的调用,打算直接复用 OneBot12Adapter 的状态更新器和框架内置的机器人 BotMap。正向适配器代码如下:https://gist.github.com/crazywhalecc/7b86584a659ea2622d87f281b6b22a4b

有关适配正向 WS 的代码见分支 ob12-ws-adapter,但这里的核心问题是容器的问题,我在当前上下文的容器里并没有注册 WebSocketMessageEvent 对象,但是 has() 返回的是 true,这样我就没办法判断是否是正向 WS 环境了。(正向 WS 在注册容器时并没有填入 WebSocketMessageEvent

复现步骤

同上。

解决方案

No response

附加信息

No response

@crazywhalecc crazywhalecc added the bug 意外行为或意外问题 label May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 意外行为或意外问题
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants