nonebot / adapter-satori

NoneBot2 Satori 适配器 / Satori Protocol adapter for nonebot2
MIT License
84 stars 5 forks source link

[Bug]: 解析事件 reaction-added 和 reaction-removed 时未处理空消息 #32

Closed wyf7685 closed 1 month ago

wyf7685 commented 1 month ago

确认项

操作系统

Linux

Python 版本

3.12.6

NoneBot 版本

2.3.3

适配器

0.13.0rc1

协议端

wyapx/nekobox

描述问题

接收表态事件时,由于 nekobox 未对该事件提供 message 字段,适配器解析事件时出现错误。

根据对应的 Satori 文档, message 不是该事件的必需资源。

复现步骤

  1. 配置 nonebot+adapter-satori,连接至 nekobox
  2. 在群聊内添加消息回应/删除消息回应

期望的结果

Satori 适配器正确处理该事件

截图或日志

日志 ``` 10-01 22:27:29 [WARNING] nonebot | Satori | Failed to parse event EventPayload(op=, body={'id': 366, 'type': 'reaction-added', 'platform': 'nekobox', 'self_id': '510804961', 'timestamp': 1727792849869, 'guild': {'id': '814181336', 'name': '814181336', 'avatar': 'https://p.qlogo.cn/gh/814181336/814181336/640'}, 'user': {'id': '2642955061', 'name': '2642955061', 'avatar': 'https://q1.qlogo.cn/g?b=qq&nk=2642955061&s=640'}, '_type': 'reaction', '_data': {'message_id': 36388, 'emoji': 'face:424', 'count': 4}}) Traceback (most recent call last): File "/usr/local/bin/gunicorn", line 8, in sys.exit(run()) File "/usr/local/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 66, in run WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]", prog=prog).run() File "/usr/local/lib/python3.12/site-packages/gunicorn/app/base.py", line 235, in run super().run() File "/usr/local/lib/python3.12/site-packages/gunicorn/app/base.py", line 71, in run Arbiter(self).run() File "/usr/local/lib/python3.12/site-packages/gunicorn/arbiter.py", line 201, in run self.manage_workers() File "/usr/local/lib/python3.12/site-packages/gunicorn/arbiter.py", line 570, in manage_workers self.spawn_workers() File "/usr/local/lib/python3.12/site-packages/gunicorn/arbiter.py", line 641, in spawn_workers self.spawn_worker() File "/usr/local/lib/python3.12/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker worker.init_process() File "/usr/local/lib/python3.12/site-packages/uvicorn/workers.py", line 75, in init_process super().init_process() File "/usr/local/lib/python3.12/site-packages/gunicorn/workers/base.py", line 143, in init_process self.run() File "/usr/local/lib/python3.12/site-packages/uvicorn/workers.py", line 107, in run return asyncio.run(self._serve()) File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) File "/usr/local/lib/python3.12/site-packages/nonebot/adapters/satori/adapter.py", line 187, in ws await self._loop(info, ws) > File "/usr/local/lib/python3.12/site-packages/nonebot/adapters/satori/adapter.py", line 233, in _loop event = self.payload_to_event(type_validate_python(Event, payload.body)) File "/usr/local/lib/python3.12/site-packages/nonebot/adapters/satori/adapter.py", line 286, in payload_to_event return type_validate_python(EventClass, model_dump(payload)) File "/usr/local/lib/python3.12/site-packages/nonebot/compat.py", line 225, in type_validate_python return TypeAdapter(type_).validate_python(data) File "/usr/local/lib/python3.12/site-packages/pydantic/type_adapter.py", line 135, in wrapped return func(self, *args, **kwargs) File "/usr/local/lib/python3.12/site-packages/pydantic/type_adapter.py", line 366, in validate_python return self.validator.validate_python(object, strict=strict, from_attributes=from_attributes, context=context) File "/usr/local/lib/python3.12/site-packages/nonebot/adapters/satori/event.py", line 408, in generate_message values["_message"] = Message.from_satori_element(parse(values["message"]["content"])) TypeError: 'NoneType' object is not subscriptable ```

Nonebot 配置项

No response