AliceBotProject/alicebot

收到好友撤回事件后出现报错

Closed this issue · 0 comments

comiee commented

报错信息如下:

  File "D:\Python310\lib\site-packages\alicebot\bot.py", line 173, in run
    asyncio.run(self._run())
    │       │   │    └ <function Bot._run at 0x0000021A5CC930A0>
    │       │   └ <alicebot.bot.Bot object at 0x0000021A5C97D4B0>
    │       └ <function run at 0x0000021A5B8BE9E0>
    └ <module 'asyncio' from 'D:\\Python310\\lib\\asyncio\\__init__.py'>
  File "D:\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
           │    │                  └ <coroutine object Bot._run at 0x0000021A5CC5C580>
           │    └ <function BaseEventLoop.run_until_complete at 0x0000021A5B99F0A0>
           └ <ProactorEventLoop running=True closed=False debug=False>
  File "D:\Python310\lib\asyncio\base_events.py", line 633, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x0000021A5B9F1240>
    └ <ProactorEventLoop running=True closed=False debug=False>
  File "D:\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "D:\Python310\lib\asyncio\base_events.py", line 600, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x0000021A5B9A0B80>
    └ <ProactorEventLoop running=True closed=False debug=False>
  File "D:\Python310\lib\asyncio\base_events.py", line 1896, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x0000021A5B9105E0>
    └ <Handle Task.task_wakeup(<Future finished result=None>)>
  File "D:\Python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle Task.task_wakeup(<Future finished result=None>)>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle Task.task_wakeup(<Future finished result=None>)>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle Task.task_wakeup(<Future finished result=None>)>
> File "D:\Python310\lib\site-packages\alicebot\adapter\__init__.py", line 78, in safe_run
    await self.run()
          │    └ <function WebSocketAdapter.run at 0x0000021A5E15A440>
          └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\adapter\utils.py", line 207, in run
    await self.websocket_connect()
          │    └ <function MiraiAdapter.websocket_connect at 0x0000021A5E18E440>
          └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\adapter\mirai\__init__.py", line 90, in websocket_connect
    await self.handle_websocket()
          │    └ <function WebSocketAdapter.handle_websocket at 0x0000021A5E15A710>
          └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\adapter\utils.py", line 266, in handle_websocket
    await self.handle_websocket_msg(msg)
          │    │                    └ WSMessage(type=<WSMsgType.TEXT: 1>, data='{"syncId":"-1","data":{"type":"FriendRecallEvent","authorId":123456789,"messageId"...
          │    └ <function MiraiAdapter.handle_websocket_msg at 0x0000021A5E18E4D0>
          └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\adapter\mirai\__init__.py", line 119, in handle_websocket_msg
    await self.handle_mirai_event(msg_dict.get("data"))
          │    │                  │        └ <method 'get' of 'dict' objects>
          │    │                  └ {'syncId': '-1', 'data': {'type': 'FriendRecallEvent', 'authorId': 123456789, 'messageId': 26036, 'time': 1691243648, 'opera...
          │    └ <function MiraiAdapter.handle_mirai_event at 0x0000021A5E18E680>
          └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\adapter\mirai\__init__.py", line 153, in handle_mirai_event
    mirai_event = self.get_event_model(msg["type"])(adapter=self, **msg)
                  │    │               │                    │       └ {'type': 'FriendRecallEvent', 'authorId': 123456789, 'messageId': 26036, 'time': 1691243648, 'operator': 123456789}
                  │    │               │                    └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
                  │    │               └ {'type': 'FriendRecallEvent', 'authorId': 123456789, 'messageId': 26036, 'time': 1691243648, 'operator': 123456789}
                  │    └ <classmethod(<function MiraiAdapter.get_event_model at 0x0000021A5E18E5F0>)>
                  └ <alicebot.adapter.mirai.MiraiAdapter object at 0x0000021A5E3420E0>
  File "D:\Python310\lib\site-packages\alicebot\event.py", line 48, in __init__
    super().__init__(**data)
                       └ {'type': 'FriendRecallEvent', 'authorId': 123456789, 'messageId': 26036, 'time': 1691243648, 'operator': 123456789}
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for FriendRecallEvent
friend
  field required (type=value_error.missing)

原因为FriendRecallEvent继承自FriendEvent,FriendEvent中有类成员friend: FriendInfo,导致FriendRecallEvent初始化也必须传一个该字段,而mirai传来的事件中没有该字段

#alicebot\adapter\mirai\event\notice.py
class FriendEvent(NoticeEvent):
    """好友事件"""

    friend: FriendInfo

class FriendRecallEvent(FriendEvent):
    """好友消息撤回"""

    type: Literal["FriendRecallEvent"]
    authorId: int
    messageId: int
    time: int
    operator: int