Tian-que / nonebot-adapter-kaiheila

Kaiheila adapter for nonebot2
MIT License
27 stars 8 forks source link

调用 `direct-message/view` 出错 #60

Closed MeetWq closed 7 months ago

MeetWq commented 8 months ago

问题描述: nonebot-plugin-alconna 插件提取 UniMsg 时会调用 extract_reply 函数: https://github.com/nonebot/plugin-alconna/blob/e162207a0ad887d6893b1705edb24254fd879c75/src/nonebot_plugin_alconna/uniseg/adapters/kook/builder.py#L168-L180 其中会调用 direct-message/viewmessage/view api 在调用 direct-message/view 时会报错(message/view 没问题)

环境:

日志:

03-21 16:42:50 [DEBUG] nonebot | Kaiheila | {'post_type': 'message', 'channel_type': 'PERSON', 'type_': 9, 'target_id': '381647208', 'author_id': '143543771', 'content': 'gif分解', 'msg_id': 'eac0aafd-3113-46da-b50f-54d2622718c1', 'msg_timestamp': 1711010569452, 'nonce': 'BpVYfGXTH4PcYAbIEeWkVvOb', 'extra': {'type_': 9, 'guild_id': None, 'channel_name': None, 'mention': [], 'mention_all': False, 'mention_roles': [], 'mention_here': False, 'author': {'id_': '143543771', 'username': 'CC', 'nickname': 'CC', 'identify_num': '2492', 'online': True, 'bot': False, 'os': 'Websocket', 'status': 1, 'avatar': 'https://img.kookapp.cn/assets/avatar_5.jpg?x-oss-process=style/icon', 'vip_avatar': 'https://img.kookapp.cn/assets/avatar_5.jpg?x-oss-process=style/icon', 'mobile_verified': None, 'roles': [], 'joined_at': None, 'active_time': None}, 'body': None, 'attachments': None, 'code': '96b848e73efc8be0a263e62211a44357'}, 'user_id': '143543771', 'self_id': '381647208', 'message_type': 'private', 'sub_type': 'kmarkdown', 'event': {'type': 9, 'guild_id': None, 'channel_name': None, 'mention': [], 'mention_all': False, 'mention_roles': [], 'mention_here': False, 'nav_channels': [], 'author': {'id_': '143543771', 'username': 'CC', 'nickname': 'CC', 'identify_num': '2492', 'online': True, 'bot': False, 'os': 'Websocket', 'status': 1, 'avatar': 'https://img.kookapp.cn/assets/avatar_5.jpg?x-oss-process=style/icon', 'vip_avatar': 'https://img.kookapp.cn/assets/avatar_5.jpg?x-oss-process=style/icon', 'mobile_verified': None, 'roles': [], 'joined_at': None, 'active_time': None}, 'kmarkdown': {'raw_content': 'gif分解', 'mention_part': [], 'mention_role_part': []}, 'code': '96b848e73efc8be0a263e62211a44357', 'attachments': None, 'content': [{'type': 'text', 'data': {'text': 'gif分解'}}]}, 'to_me': False, 'from_type': 1, 'group_id': '381647208', 'time': 1711010569452, 'message_id': 'eac0aafd-3113-46da-b50f-54d2622718c1'}
03-21 16:42:50 [SUCCESS] nonebot | Kaiheila 381647208 | [message.private.kmarkdown]: Message eac0aafd-3113-46da-b50f-54d2622718c1 from 143543771 "gif分解"
03-21 16:42:50 [DEBUG] nonebot | Checking for matchers in priority 1...
03-21 16:42:50 [DEBUG] nonebot | Checking for matchers in priority 12...
03-21 16:42:50 [INFO] nonebot | Event will be handled by Matcher(type='message', module=nonebot_plugin_imagetools, lineno=102)
03-21 16:42:50 [DEBUG] nonebot | Running Matcher(type='message', module=nonebot_plugin_imagetools, lineno=102)
03-21 16:42:50 [DEBUG] nonebot | Running handler Dependent(call=handle)
03-21 16:42:50 [DEBUG] nonebot | Kaiheila | Calling API direct-message/view
03-21 16:42:50 [DEBUG] nonebot | Kaiheila | API result {'code': 0, 'message': '操作成功', 'data': {'id': 'eac0aafd-3113-46da-b50f-54d2622718c1', 'type': 9, 'content': 'gif分解', 'embeds': [], 'attachments': False, 'create_at': 1711010569452, 'updated_at': 0, 'reactions': [], 'author_id': '143543771', 'image_name': '', 'mention_info': {'mention_part': [], 'channel_part': [], 'item_part': []}, 'from_type': 1, 'msg_icon': '', 'quote': ''}}
03-21 16:42:50 [DEBUG] nonebot | Running CalledAPI hooks...
03-21 16:42:50 [INFO] nonebot | Matcher(type='message', module=nonebot_plugin_imagetools, lineno=102) running complete
03-21 16:42:50 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_imagetools, lineno=102) failed.
Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\__init__.py", line 334, in run
    get_driver().run(*args, **kwargs)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 186, in run
    uvicorn.run(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\uvicorn\main.py", line 575, in run
    server.run()
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\uvicorn\server.py", line 62, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1899, in _run_once
    handle._run()
  File "C:\Users\wangqian\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher
    await _run_matcher(
> File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 842, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 817, in simple_run
    await handler(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 102, in __call__
    values = await self.solve(**kwargs)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 198, in solve
    values = await asyncio.gather(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 186, in _solve_field
    value = await param._solve(**params)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\params.py", line 192, in _solve
    sub_values = await sub_dependent.solve(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 198, in solve
    values = await asyncio.gather(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 186, in _solve_field
    value = await param._solve(**params)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\params.py", line 192, in _solve
    sub_values = await sub_dependent.solve(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 198, in solve
    values = await asyncio.gather(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 186, in _solve_field
    value = await param._solve(**params)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\params.py", line 216, in _solve
    return await task
  File "F:\Temp\bot\testbot\nonebot_plugin_imagetools\depends.py", line 21, in dependency
    reply = await reply_fetch(event, bot)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot_plugin_alconna\uniseg\tools.py", line 23, in reply_fetch
    return await fn.extract_reply(event, bot)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot_plugin_alconna\uniseg\adapters\kook\builder.py", line 174, in extract_reply
    message = await bot.call_api(
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\adapters\kaiheila\bot.py", line 204, in call_api
    return await super().call_api(api, **data)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 122, in call_api
    raise exception
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 97, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\adapters\kaiheila\adapter.py", line 136, in _call_api
    return await self._do_call_api(api, data, bot.token)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\adapters\kaiheila\adapter.py", line 190, in _do_call_api
    raise e
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\adapters\kaiheila\adapter.py", line 188, in _do_call_api
    return type_validate_python(result_type, result) if result_type else None
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\nonebot\compat.py", line 215, in type_validate_python
    return TypeAdapter(type_).validate_python(data)
  File "F:\Temp\bot\testbot\.venv\lib\site-packages\pydantic\type_adapter.py", line 256, in validate_python
    return self.validator.validate_python(__object, strict=strict, from_attributes=from_attributes, context=context)
pydantic_core._pydantic_core.ValidationError: 1 validation error for DirectMessage
quote
  Input should be a valid dictionary or instance of Quote [type=model_type, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/model_type
03-21 16:42:50 [DEBUG] nonebot | Stop event propagation
03-21 16:42:50 [DEBUG] nonebot | Checking for matchers completed
Tian-que commented 7 months ago

已修复,请使用 v0.3.4

居然返回了两个奇怪的默认值