Agnes4m / nonebot_plugin_friends

Nonebot2查询,好友添加事件处理
MIT License
7 stars 2 forks source link

自动同意加群出错 #5

Closed dmnoobcoder closed 1 month ago

dmnoobcoder commented 1 month ago

nonebot2, onebot11, fastAPI 请求大佬有空的时候帮忙看一眼,万分感谢!

发送加群邀请后,报错如下: 10-30 20:30:46 [ERROR] nonebot | Running Matcher(type='request', module=nonebot_plugin_friends.matcher, lineno=27) failed. Traceback (most recent call last): File "", line 15, in File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/init.py", line 335, in run get_driver().run(*args, **kwargs) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 186, in run uvicorn.run( File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/uvicorn/main.py", line 579, in run server.run() File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run return asyncio.run(self.serve(sockets=sockets)) File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/message.py", line 476, in check_and_run_matcher await _run_matcher(

File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/message.py", line 428, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/matcher/matcher.py", line 850, in run await self.simple_run(bot, event, state, stack, dependency_cache) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/matcher/matcher.py", line 825, in simple_run await handler( File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/dependencies/init.py", line 94, in call return await cast(Callable[..., Awaitable[R]], self.call)(values) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot_pluginfriends/matcher.py", line 89, in await bot.send_group_msg( File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/adapter/bot.py", line 122, in call_api raise exception File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/adapter/bot.py", line 97, in call_api result = await self.adapter._call_api(self, api, data) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 147, in _call_api return handle_api_result(await self._result_store.fetch(seq, timeout)) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/utils.py", line 58, in handle_api_result raise ActionFailed(**result) nonebot.adapters.onebot.v11.exception.ActionFailed: ActionFailed(status='failed', retcode=1200, data=None, message='Error: EventChecker Failed: NTEvent serviceAndMethod:NodeIKernelMsgService/sendMsg ListenerName:NodeIKernelMsgListener/onMsgInfoListUpdate EventRet:\n{\n "result": 110,\n "errMsg": "发送失败,你已被移出该群,请重新加群。"\n}\n\n at file:///opt/QQ/resources/app/app_launcher/napcat/napcat.mjs:7727:13', wording='Error: EventChecker Failed: NTEvent serviceAndMethod:NodeIKernelMsgService/sendMsg ListenerName:NodeIKernelMsgListener/onMsgInfoListUpdate EventRet:\n{\n "result": 110,\n "errMsg": "发送失败,你已被移出该群,请重新加群。"\n}\n\n at file:///opt/QQ/resources/app/app_launcher/napcat/napcat.mjs:7727:13', echo='3')

以下是我试图揣摩这个issue的过程,或许有帮助,也发出来供参考: 我的python水平很差,猜测可能是89行这里试图给将要加但还没加的这个群聊发消息出错了: logger.info(f"发送到群聊{add_group}") add_message: int = ( await bot.send_group_msg( group_id=int(add_group), message=Message( f"QQ:{add_qq} 请求请入本群!\n请求添加时间:{realtime}\n验证信息为:{add_comment}", ), ) )["message_id"] 遂改group_id为一个已经加过的群聊重新尝试,报错如下: 10-30 20:40:17 [ERROR] nonebot | Running Matcher(type='request', module=nonebot_plugin_friends.matcher, lineno=27) failed. Traceback (most recent call last): File "", line 15, in File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/init.py", line 335, in run get_driver().run(*args, **kwargs) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 186, in run uvicorn.run( File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/uvicorn/main.py", line 579, in run server.run() File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run return asyncio.run(self.serve(sockets=sockets)) File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/message.py", line 476, in check_and_run_matcher await _run_matcher(

File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/message.py", line 428, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/matcher/matcher.py", line 850, in run await self.simple_run(bot, event, state, stack, dependency_cache) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/internal/matcher/matcher.py", line 825, in simple_run await handler( File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot/dependencies/init.py", line 94, in call return await cast(Callable[..., Awaitable[R]], self.call)(**values) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot_pluginfriends/matcher.py", line 107, in await save_group_msg(friendrequest, str(add_group)) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot_plugin_friends/event.py", line 127, in save_group_msg await save_group_request_data(friend_requests) File "/home/su/qqbot/nl_annon/.venv/lib/python3.12/site-packages/nonebot_plugin_friends/event.py", line 109, in save_group_request_data json.dump( File "/usr/lib/python3.12/json/init.py", line 179, in dump for chunk in iterable: File "/usr/lib/python3.12/json/encoder.py", line 432, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/usr/lib/python3.12/json/encoder.py", line 406, in _iterencode_dict yield from chunks File "/usr/lib/python3.12/json/encoder.py", line 326, in _iterencode_list yield from chunks File "/usr/lib/python3.12/json/encoder.py", line 439, in _iterencode o = _default(o) File "/usr/lib/python3.12/json/encoder.py", line 180, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type GroupFriendRequest is not JSON serializable 然后我就看不懂了。。

顿首再拜

Agnes4m commented 1 month ago

没看太懂啊,你这个是让bot申请进群的操作?为什么会出现group_id是属于bot的情况?如果不在一个群组bot也收不到消息吧

dmnoobcoder commented 1 month ago

就是给bot发送加群邀请,期待bot自动同意进群

Agnes4m commented 1 month ago

这个功能我确实me没有做,因为我功能描述是标注了,权限为管理员/群主下,自动处理流程,而不是对于主动添加进群聊的流程处理。

因为这个操作曾导致我一个账号永久封禁,我理由是短时间内太多加群请求加上之前累计的操作,所以出于安全考虑,我只做了比较安全合理的操作请求,进群邀请等等容易被系统鉴定为传销等等的,个人建议自己登录Bot设置进群邀请的权限来控制,或者自行修改,作为开源项目我不应该编写容易导致他人封禁的行为 image

dmnoobcoder commented 1 month ago

好吧 不好意思 我理解错了,打扰了。我以为是远程同意进群邀请