nonebot/adapter-onebot

Bug: 无法正确响应私聊时的poke事件

yaowan233 opened this issue · 4 comments

描述问题:

在响应私聊戳一戳事件时会把它误当成群聊事件

如何复现?

from nonebot.adapters.onebot.v11 import PokeNotifyEvent
from nonebot import on_notice


poke = on_notice()


@poke.handle()
async def _(event: PokeNotifyEvent):
    await poke.send('111')

私聊戳bot后 报错如下

> File "F:\env\miyuki\lib\site-packages\nonebot\message.py", line 196, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "F:\env\miyuki\lib\site-packages\nonebot\internal\matcher.py", line 668, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "F:\env\miyuki\lib\site-packages\nonebot\internal\matcher.py", line 635, in simple_run
    await handler(
  File "F:\env\miyuki\lib\site-packages\nonebot\dependencies\__init__.py", line 92, in __call__
    return await self.call(**values)
  File "E:\bot\bot\bot\miyuki\.\miyuki\plugins\poke\__init__.py", line 10, in _
    await poke.send('111')
  File "F:\env\miyuki\lib\site-packages\nonebot\internal\matcher.py", line 449, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "F:\env\miyuki\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 220, in send
    return await self.__class__.send_handler(self, event, message, **kwargs)
  File "F:\env\miyuki\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 175, in send
    return await bot.send_msg(**params)
  File "F:\env\miyuki\lib\site-packages\nonebot\internal\adapter\bot.py", line 117, in call_api
    raise exception
  File "F:\env\miyuki\lib\site-packages\nonebot\internal\adapter\bot.py", line 94, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "F:\env\miyuki\lib\site-packages\nonebot\adapters\onebot\v11\adapter.py", line 131, in _call_api
    return handle_api_result(
  File "F:\env\miyuki\lib\site-packages\nonebot\adapters\onebot\utils.py", line 45, in handle_api_result
    raise ActionFailed(**result)
nonebot.adapters.onebot.exception.ActionFailed: <ActionFailed data=None, echo=1, msg=GROUP_NOT_FOUND, retcode=100, status=failed, wording=群聊不存在>

环境信息:

  • OS: Windows
  • Python : 3.9
  • Nonebot : v2.0.0-beta.4
  • nonebot-adapter-onebot: 2.1.1 (v11)

协议端信息:

  • 协议端: go-cqhttp
  • 协议端版本: 1.0.0-rc3

可能下面这行出了问题,发送消息时event_dict有“group_id”的键但他的值为None,误把这个事件当群聊事件处理了

if "group_id" in event_dict: # copy the group_id to the API params if exists

group_id为None并不会影响发送,本来默认值就是None,私聊发送。这个报错是gocq的问题,或者你可以打开gocq的debug查看api调用具体信息。

可是后面因为params没有message_type又有group_id会设置message_type为group 导致gocq尝试发送群消息

if "message_type" not in params: # guess the message_type
if "group_id" in params:
params["message_type"] = "group"

可以加个非none判断

已在master分支修改