nonebot / adapter-red Goto Github PK
View Code? Open in Web Editor NEWNoneBot2 基于 Red 协议 的 QQNT 适配器
License: MIT License
NoneBot2 基于 Red 协议 的 QQNT 适配器
License: MIT License
Windows
3.8.16
2.1.1
0.6.1
0.0.52
使用on_notice,监控MemberAddEvent消息
1.on_notice注册一个事件
2.消息函数中处理MemberAddEvent对应event参数
可以正确处理MemberAddEvent
10-28 21:20:25 [ERROR] nonebot | RedProtocol | Error while process data from websocket ws://127.0.0.1:16531/. Trying to reconnect...
Traceback (most recent call last):
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 150, in _handle_event
event = target.convert(event_data)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\event.py", line 295, in convert
raise ValueError("Invalid legacy invite message.")
ValueError: Invalid legacy invite message.
No response
有时候bot退群需要清理一些数据,以及别人退群之类的需要做一些记录,希望可以实装一下这个群成员减少逻辑~
希望可以实装群成员减少的消息通知
如堆栈所示,实际的响应体缺少了Profile的一些字段
堆栈如下:
File "C:\Users\huang\PycharmProjects\nonebot-adapter-onebot-pretender\src\nonebot_adapter_onebot_pretender\v11\impl\red\pretender.py", line 286, in get_login_info
profile = await bot.get_self_profile()
File "C:\Users\huang\AppData\Local\pypoetry\Cache\virtualenvs\nonebot-adapter-onebot-pretender-zxJ0cCXU-py3.10\lib\site-packages\nonebot\adapters\red\bot.py", line 234, in get_self_profile
return Profile.parse_obj(resp)
File "pydantic\main.py", line 526, in pydantic.main.BaseModel.parse_obj
return cls(**obj)
File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
raise validation_error
pydantic.error_wrappers.ValidationError: 5 validation errors for Profile
extStatus
field required (type=value_error.missing)
vipFlag
field required (type=value_error.missing)
yearVipFlag
field required (type=value_error.missing)
svipFlag
field required (type=value_error.missing)
vipLevel
field required (type=value_error.missing)
响应体如下:
{'uid': 'u_we7******_Q****', 'qid': '', 'uin': '135******7', 'nick': 'bot_******', 'remark': '', 'longNick': '女生******', 'avatarUrl': 'http://qh.qlogo.cn/g?b=qq&ek=AQ********', 'birthday_year': 1900, 'birthday_month': 1, 'birthday_day': 1, 'sex': 2, 'topTime': '0', 'isBlock': False, 'isMsgDisturb': False, 'isSpecialCareOpen': False, 'isSpecialCareZone': False, 'ringId': '', 'status': 10, 'categoryId': 0, 'onlyChat': False, 'qzoneNotWatch': False, 'qzoneNotWatched': False}
profile = await bot.get_self_profile()
不报错(
BetterQQNT
: YCalling API get_friends 时有些qqnt的版本(日志使用的是Linux版本的3.1.2-13107)不同返回的参数会有不同,导致有些版本因为数据缺失而报错
调用get_friend API
BetterQQNT
: 是09-25 20:01:29 [DEBUG] nonebot | RedProtocol | Calling API get_friends
09-25 20:01:29 [ERROR] nonebot | Error when running WebSocketConnection hook. Running cancelled!
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 331, in run
get_driver().run(*args, **kwargs)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 201, in run
uvicorn.run(
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 587, in run
server.run()
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 61, in run
return asyncio.run(self.serve(sockets=sockets))
File "/Users/ukm/.pyenv/versions/3.10.11/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
> File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/internal/driver/driver.py", line 169, in _run_hook
await asyncio.gather(*coros)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/utils.py", line 187, in run_coro_with_catch
return await coro
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/utils/auto_select_bot.py", line 31, in _
await refresh_bots()
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/utils/auto_select_bot.py", line 62, in refresh_bots
targets = await list_targets(bot)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/adapters/red.py", line 184, in list_targets
users = await bot.get_friends()
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/adapters/red/bot.py", line 239, in get_friends
return [Profile.parse_obj(data) for data in resp]
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/adapters/red/bot.py", line 239, in <listcomp>
return [Profile.parse_obj(data) for data in resp]
File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
return cls(**obj)
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
raise validation_error
pydantic.error_wrappers.ValidationError: 5 validation errors for Profile
extStatus
field required (type=value_error.missing)
vipFlag
field required (type=value_error.missing)
yearVipFlag
field required (type=value_error.missing)
svipFlag
field required (type=value_error.missing)
vipLevel
field required (type=value_error.missing)
直接调用API返回如下
[{'uid': 'u_6CQkgdZjkfikjKbuOkSbdw', 'qid': '', 'uin': '66600000', 'nick': 'babyQ', 'remark': '', 'longNick': 'Hi,我是babyQ,你的智能小伙伴~ (注意认证标识,可别认错人哦\\(^o^)/)', 'avatarUrl': '', 'birthday_year': 0, 'birthday_month': 0, 'birthday_day': 0, 'sex': 1, 'topTime': '0', 'isBlock': False, 'isMsgDisturb': False, 'isSpecialCareOpen': False, 'isSpecialCareZone': False, 'ringId': '', 'status': 0, 'categoryId': 0, 'onlyChat': False, 'qzoneNotWatch': False, 'qzoneNotWatched': False}, {'uid': 'u_xxxx, 'qid': '', 'uin': 'xxxxx', 'nick': 'UKM', 'remark': '', 'longNick': 'xxxxx', 'avatarUrl': 'xxx', 'birthday_year': 20xx, 'birthday_month': xx, 'birthday_day': x, 'sex': 1, 'topTime': '0', 'isBlock': False, 'isMsgDisturb': False, 'isSpecialCareOpen': False, 'isSpecialCareZone': False, 'ringId': '', 'status': 0, 'categoryId': 0, 'onlyChat': False, 'qzoneNotWatch': False, 'qzoneNotWatched': False}, {'uid': 'u_xxx', 'qid': '', 'uin': 'xxx', 'nick': 'カンナ', 'remark': '', 'longNick': '', 'avatarUrl': 'x', 'birthday_year': 0, 'birthday_month': 0, 'birthday_day': 0, 'sex': 0, 'topTime': '0', 'isBlock': False, 'isMsgDisturb': False, 'isSpecialCareOpen': False, 'isSpecialCareZone': False, 'ringId': '', 'status': 10, 'categoryId': 0, 'onlyChat': False, 'qzoneNotWatch': False, 'qzoneNotWatched': False}]
chronocat已重新public:
https://github.com/chrononeko/chronocat
cc v0.2版本后不再支持red协议
若仍然使用red协议请使用cc v0.1版本
使用v0.2以上的cc清更换适配器为satori:https://github.com/nonebot/adapter-satori
Windows
python 3.8.16
nonebot 2.1.1
0.5.2
0.0.52
有人进群后无法正常处理MemberAddEvent
1.on_notice添加一个处理器
group_increase_handler = on_notice(priority=5)
2.在@handle里执行如下处理函数:
@group_increase_handler.handle()
async def _(event: MemberAddEvent):
3.有人进群时观察log
可以正常处理MemberAddEvent
10-13 18:48:38 [INFO] nonebot | Application startup completed.
10-13 18:48:47 [ERROR] nonebot | RedProtocol | Error while process data from websocket ws://127.0.0.1:16530/. Trying to reconnect...
Traceback (most recent call last):
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 147, in _handle_event
event = target.convert(event_data)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\event.py", line 290, in convert
mat := cls.legacy_invite_message.match(
AttributeError: type object 'MemberAddEvent' has no attribute 'legacy_invite_message'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1/plugins/python-ce/helpers/pydev\pydevd.py", line 2195, in
main()
File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1/plugins/python-ce/helpers/pydev\pydevd.py", line 2177, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1/plugins/python-ce/helpers/pydev\pydevd.py", line 1489, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1/plugins/python-ce/helpers/pydev\pydevd.py", line 1496, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:\kmrbot\kmrbot", line 8, in
sys.exit(main())
File "D:\kmrbot\venv\lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
File "D:\kmrbot\venv\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "D:\kmrbot\venv\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "D:\kmrbot\venv\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "D:\kmrbot\venv\lib\site-packages\click\core.py", line 783, in invoke
return callback(*args, **kwargs)
File "D:\kmrbot\haruka_bot\cli_init.py", line 16, in run
run()
File "D:\kmrbot\haruka_bot\cli\bot.py", line 37, in run
nonebot.run(app="haruka_bot.cli.bot:app")
File "D:\kmrbot\venv\lib\site-packages\nonebot_init.py", line 331, in run
get_driver().run(*args, **kwargs)
File "D:\kmrbot\venv\lib\site-packages\nonebot\drivers\none.py", line 70, in run
loop.run_until_complete(self._serve())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete
self.run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\windows_events.py", line 316, in run_forever
super().run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 570, in run_forever
self._run_once()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1859, in _run_once
handle._run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 108, in _forward_ws
await self._loop(bot, ws)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 220, in _loop
_handle_message(msg)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 205, in _handle_message
_handle_event(_data, MemberAddEvent)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 149, in _handle_event
log(
File "D:\kmrbot\venv\lib\site-packages\nonebot\utils.py", line 261, in log
logger.opt(colors=True, exception=exception).log(
File "D:\kmrbot\venv\lib\site-packages\loguru_colorizer.py", line 369, in prepare_simple_message
parser.feed(string)
File "D:\kmrbot\venv\lib\site-packages\loguru_colorizer.py", line 245, in feed
raise ValueError('Closing tag "%s" has no corresponding opening tag' % markup)
ValueError: Closing tag "" has no corresponding opening tag
10-13 18:48:47 [DEBUG] nonebot | RedProtocol | WebSocket Connection to ws://127.0.0.1:16530/ established
10-13 18:48:47 [INFO] nonebot | RedProtocol | Bot 1145141919810 connected, Chronocat Version: 0.0.52
进程已结束,退出代码-1
No response
Windows
3.8.16
2.1.1
0.6.0
0.0.52
发送语音时,通过编码器正常编码至silk格式后,发送至群组里会呈现出图片的样式(安卓QQ和NTQQ正常)
1.使用ffmpeg+编码器将wav编码转换至pcm再转换为silk
2.读取silk字节流并发送
可以正常发送语音
No response
希望可以增加类似于nonebot.adapters.onebot.v11.permission.GROUP_OWNER, GROUP_ADMIN功能
from nonebot.adapters.red.permission import GROUP_OWNER, GROUP_ADMIN
...
open = on_regex(r"^(开启淫趴|禁止淫趴)", permission=SUPERUSER |
GROUP_ADMIN | GROUP_OWNER, flags=I, priority=20, block=True)
...
Linux
3.11.2
^2.1.1
^0.6.0
0.0.52
无法获得图片的二进制数据
获取图片的二进制数据
No response
如题
result = await bot.get_members(int(event.scene))
for member in result:
print(member)
DRIVER=~httpx+~websockets
DRIVER=~aiohttp
Windows
3.8.16
2.1.1
0.5.2
0.0.52
使用MessageSegment.voice无法发送语音
1.使用MessageSegment.voice发送语音
(语音路径是正确的
这里是可以成功读取到语音文件的数据的)
语音格式为wav
之前在gocq上用CQ码发送是正常的
期望可以正确发送语音
日志没有报错
但在NTQQ侧显示发送了一条语音(但点开会提示InitFromFile Fail)
在群聊侧会显示为一张无法打开的图片
10-13 20:21:24 [INFO] nonebot | Event will be handled by Matcher(type='message', module=plugins.t.t, lineno=17)
10-13 20:21:24 [DEBUG] nonebot | Running Matcher(type='message', module=plugins.t.t, lineno=17)
10-13 20:21:24 [DEBUG] nonebot | Running handler Dependent(call=handle)
10-13 20:21:24 [DEBUG] nonebot | Running handler Dependent(call=handle_get_param)
10-13 20:21:24 [DEBUG] nonebot | Handler Dependent(call=handle_get_param) skipped
10-13 20:21:24 [DEBUG] nonebot | Running handler Dependent(call=_)
10-13 20:21:24 [DEBUG] nonebot | RedProtocol | Calling API send_message
10-13 20:21:25 [INFO] nonebot | Matcher(type='message', module=plugins.t.t, lineno=17) running complete
10-13 20:21:25 [DEBUG] nonebot | Stop event propagation
10-13 20:21:25 [DEBUG] nonebot | Checking for matchers completed
No response
在 Bot 发送消息时出现 Unauthorized,接收消息正常
BetterQQNT
: 是 B* 0.3.17chronocat.yml
配置
# yaml-language-server: $schema=https://chronocat.vercel.app/config-v0.schema.json
#
################################################################
# Chronocat 配置文件
################################################################
#
# 你好!
#
# 这是 Chronocat 的配置文件。Chronocat 的所有配置以及每个账号
# 的独立配置都存放在这个文件里。
#
# 这是 Chronocat 配置的文档:
# https://chronocat.vercel.app/config
# 如果还没有看过的话,请先看一下!
#
# 如果你现在并不是使用完整功能的编辑器编辑此文件的话,
# 我们推荐你使用一款完整功能的编辑器来编辑!
# 这样的编辑器在你不小心改错配置的时候会智能地给出提示。
# 想要了解更多请查看上面的文档 ↑
#
################################################################
# 全局配置
################################################################
#
# 下面的配置是通用的!如果你只登录一个账号,
# 那么只需修改下面这部分配置即可!
#
################################################################
# servers:服务配置
#
# 配置 Chronocat 开启的服务。需要尤其注意服务列表的格式哦~
#
################################################################
# 账号配置
################################################################
overrides:
##############################################################
#
# 下面的配置是每个账号专属的!修改下面的配置会覆盖上面的配置哦~
# 修改的时候要特别注意:账号前空两格,账号内配置要空四格哦!
#
##############################################################
已替换为某个账号:
servers:
- type: red
token: "与qq号一致"
port: 16531
none bot 日志
2023-10-02 23:14:16 10-02 15:14:16 [SUCCESS] nonebot | RedProtocol 3356715156 | [message.private]: Message from 0: 查看 123456
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 1...
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 2...
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 5...
2023-10-02 23:14:16 10-02 15:14:16 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.tsdm, lineno=13)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running handler Dependent(call=handle_first_get)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running handler Dependent(call=handle_tid, parameterless=(Depends(Dependent(call=_key_getter)),))
2023-10-02 23:14:17 10-02 15:14:17 [INFO] tsdm | Get forum data successful.
2023-10-02 23:14:17 10-02 15:14:17 [INFO] tsdm | Get forum data successful.
2023-10-02 23:14:21 10-02 15:14:21 [INFO] tsdm | {'status': 0, 'id': '...', 'url': '/?...', 'deletetoken': '...', 'full_url': 'https://.../?...#...', 'passcode': '6f9UvqC3MRpkG3RxNtoekjTfrEoNwdotxJZBAAtsS9zr'}
2023-10-02 23:14:25 10-02 15:14:25 [INFO] tsdm | {'status': 0, 'id': '...', 'url': '/?...', 'deletetoken': '...', 'full_url': 'https://.../?...#...', 'passcode': 'GkGqC5UGpZea4tgRJghukJESt3zavza67Z1igSKh8a75'}
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | RedProtocol | Calling API send_message
2023-10-02 23:14:25 10-02 15:14:25 [INFO] nonebot | Matcher(type='message', module=src.plugins.tsdm, lineno=13) running complete
2023-10-02 23:14:25 10-02 15:14:25 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13) failed.
2023-10-02 23:14:25 Traceback (most recent call last):
2023-10-02 23:14:25 File "/app/bot.py", line 39, in <module>
2023-10-02 23:14:25 nonebot.run(app="__mp_main__:app")
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/__init__.py", line 331, in run
2023-10-02 23:14:25 get_driver().run(*args, **kwargs)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/drivers/none.py", line 70, in run
2023-10-02 23:14:25 loop.run_until_complete(self._serve())
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/asyncio/base_events.py", line 634, in run_until_complete
2023-10-02 23:14:25 self.run_forever()
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
2023-10-02 23:14:25 self._run_once()
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1905, in _run_once
2023-10-02 23:14:25 handle._run()
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
2023-10-02 23:14:25 self._context.run(self._callback, *self._args)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
2023-10-02 23:14:25 await _run_matcher(
2023-10-02 23:14:25 > File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 428, in _run_matcher
2023-10-02 23:14:25 await matcher.run(bot, event, state, stack, dependency_cache)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run
2023-10-02 23:14:25 await self.simple_run(bot, event, state, stack, dependency_cache)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 821, in simple_run
2023-10-02 23:14:25 await handler(
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
2023-10-02 23:14:25 return await cast(Callable[..., Awaitable[R]], self.call)(**values)
2023-10-02 23:14:25 File "/app/src/plugins/tsdm/__init__.py", line 91, in handle_tid
2023-10-02 23:14:25 await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 554, in send
2023-10-02 23:14:25 return await bot.send(event=event, message=_message, **kwargs)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/bot.py", line 223, in send
2023-10-02 23:14:25 resp = await self.call_api(
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
2023-10-02 23:14:25 raise exception
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
2023-10-02 23:14:25 result = await self.adapter._call_api(self, api, **data)
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 265, in _call_api
2023-10-02 23:14:25 return json.loads((await self.request(request)).content) # type: ignore
2023-10-02 23:14:25 File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 271, in request
2023-10-02 23:14:25 raise NetworkError("Unauthorized!")
2023-10-02 23:14:25 nonebot.exception.NetworkError: NetworkError()
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | Checking for matchers in priority 10...
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | Checking for matchers completed
处理消息代码:
tsdm_get = on_command("tsdm_get", aliases={"查看"}, priority=5)
@tsdm_get.handle()
async def handle_first_get(matcher: Matcher, args: Message = CommandArg()):
global status
if not status:
await tsdm_get.finish("未登录")
else:
tid = args.extract_plain_text()
if tid:
matcher.set_arg("tid", args)
@tsdm_get.got("tid", prompt="请输入帖子ID")
async def handle_tid(tid: Message = Arg(), tid_id=ArgPlainText("tid")):
# account.purchase(tid_id)
forum_data = account.get_forum_data(tid_id)
if forum_data:
link_raw = utils.pastebin_send(forum_data, False)
link_html = utils.pastebin_send(forum_data, True)
await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
else:
await tsdm_get.finish("获取失败")
.env
配置
RED_BOTS='
[
{
"port": "16531",
"token": "与qq号一致",
"host": "host.docker.internal"
}
]
'
DRIVER=~httpx+~websockets
Windows
3.10
2.0.1
0.5.1
0.0.52
MessageSegment.image()中使用url发送会报错
url = baidu.com #只是举个例子
MessageSegment.image(url)
这样会报错errno22
正常发送图片
Traceback (most recent call last): File "C:\shenmeshenme\__init__.py", line 247, in func_ var = MessageSegment.image(Path(i)) File "C:\Program Files\Python310\lib\site-packages\nonebot\adapters\red\message.py", line 57, in image file = file.read_bytes() File "C:\Program Files\Python310\lib\pathlib.py", line 1126, in read_bytes with self.open(mode='rb') as f: File "C:\Program Files\Python310\lib\pathlib.py", line 1119, in open return self._accessor.open(self, mode, buffering, encoding, errors, OSError: [Errno 22] Invalid argument: 'https:\\www.shenmeshenmewangzhan\\shenme.jpeg'
No response
bot.get_members返回空列表
已传入正确群号
私聊或群聊一有消息就报日志中的错误,希望大佬们帮忙看一下,谢谢!
09-18 12:39:49 [INFO] nonebot | red | Bot XXXX connected, Chronocat Version: 0.0.42
09-18 12:39:55 [ERROR] nonebot | red | Error while process data from websocket ws://localhost:16530/. Trying to reconnect...
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 331, in run
get_driver().run(*args, **kwargs)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/drivers/none.py", line 70, in run
loop.run_until_complete(self._serve())
File "/Users/ukm/.pyenv/versions/3.10.11/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete
self.run_forever()
File "/Users/ukm/.pyenv/versions/3.10.11/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
self._run_once()
File "/Users/ukm/.pyenv/versions/3.10.11/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
handle._run()
File "/Users/ukm/.pyenv/versions/3.10.11/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
> File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/adapters/red/adapter.py", line 118, in _forward_ws
await self._loop(bot, ws)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/adapters/red/adapter.py", line 222, in _loop
_handle_message(msg)
File "/Users/ukm/Developer/Python/NoneBot/red/.venv/lib/python3.10/site-packages/nonebot/adapters/red/adapter.py", line 168, in _handle_message
_data = MessageModel.parse_obj(message)
File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
return cls(**obj)
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
raise validation_error
pydantic.error_wrappers.ValidationError: 5 validation errors for Message
senderUid
field required (type=value_error.missing)
avatarPendant
field required (type=value_error.missing)
feedId
field required (type=value_error.missing)
nameType
field required (type=value_error.missing)
avatarFlag
field required (type=value_error.missing)
服务器为 debian 12,使用 pip install nonebot-adapter-red[auto_detect]
安装了 red 适配器,docker 运行 Chronocat,并将配置文件映射到了家目录,但是 red 无法自动读取到 Chronocat 配置
BetterQQNT
: 未对 docker 容器进行任何修改,应该未使用10-11 11:55:16 [DEBUG] nonebot | Loaded adapters: RedProtocol
10-11 11:55:16 [ERROR] nonebot | Error when running startup function. Ignored!
Traceback (most recent call last):
File "<string>", line 15, in <module>
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/__init__.py", line 331, in run
get_driver().run(*args, **kwargs)
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/drivers/none.py", line 70, in run
loop.run_until_complete(self._serve())
File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
self.run_forever()
File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
self._run_once()
File "/usr/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
handle._run()
File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/drivers/none.py", line 74, in _serve
await self._startup()
> File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/drivers/none.py", line 82, in _startup
await self._lifespan.startup()
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/drivers/_lifespan.py", line 36, in startup
await self._run_lifespan_func(self._startup_funcs)
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/drivers/_lifespan.py", line 30, in _run_lifespan_func
await cast(ASYNC_LIFESPAN_FUNC, func)()
File "/root/nb2/.venv/lib/python3.11/site-packages/nonebot/adapters/red/adapter.py", line 67, in startup
raise RuntimeError(
RuntimeError: No bots found in config!
Please check your config file and make sure it's correct.
10-11 11:55:16 [INFO] nonebot | Application startup completed.
直接 cat ~/.chronocat/config/chronocat.yml
文件能读取到
Windows
3.11.4
2.1.1
0.5.1
0.0.49
1.版本:
QQNT: 9.9.0.14619(64 位)windows
LiteLoaderQQNT: 0.5.3
框架: nonebot
协议适配器: adapter-red
2.问题:
使用bot.send_group_message(group_id, MessageSegment.file(Path(file_path)))向qq群发送文件会直接导致QQNT本体崩溃
使用bot.send_group_message(group_id, MessageSegment.file(Path(file_path)))向qq群发送文件会直接导致QQNT本体崩溃
No response
No response
No response
希望可以增加类似onebot.v11 MessageEvent下的event.group_id功能和event.time功能。
希望可以增加类似onebot.v11 MessageEvent下的event.group_id功能和event.time功能。
pydantic.error_wrappers.ValidationError: 4 validation errors for UploadResponse
imageInfo -> type
field required (type=value_error.missing)
imageInfo -> mime
field required (type=value_error.missing)
imageInfo -> wUnits
field required (type=value_error.missing)
imageInfo -> hUnits
field required (type=value_error.missing)
Windows
3.8.16
2.1.1
0.7.2
0.0.52
使用.finish()发送消息报错
my_msg.finish()发送文字消息
No response
File "D:\kmrbot\venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 570, in finish
await cls.send(message, **kwargs)
File "D:\kmrbot\venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 554, in send
return await bot.send(event=event, message=_message, **kwargs)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\bot.py", line 239, in send
resp = await self.call_api(
File "D:\kmrbot\venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api
raise exception
File "D:\kmrbot\venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
result = await self.adapter._call_api(self, api, **data)
File "D:\kmrbot\venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 238, in call_api
content=json.dumps(platform_data),
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json_init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type coroutine is not JSON serializable
10-30 11:19:09 [WARNING] apscheduler | Run time of job "live_sched (trigger: interval[0:00:05], next run at: 2023-10-30 11:19:13 CST)" was missed by 0:00:01.804977
10-30 11:19:09 [WARNING] apscheduler | Run time of job "DBManager.__save (trigger: interval[0:00:05], next run at: 2023-10-30 11:19:10 CST)" was missed by 0:00:04.735746
C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py:353: RuntimeWarning: coroutine 'Message.export' was never awaited
obj, end = self.scan_once(s, idx)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
No response
部分兑换码功能需要私聊发送,请问能否实现。
从群里面私聊玩家,临时对话功能
配置系统代理后无法发送消息,不配置可以正常发送
设置代理后任意一条消息也无法发送
from pathlib import Path
from nonebot import on_command
from nonebot.adapters.red import Bot
from nonebot.adapters.red.event import MessageEvent
from nonebot.adapters.red.message import MessageSegment
matcher = on_command("test")
@matcher.handle()
async def handle_receive(bot: Bot, event: MessageEvent):
await matcher.finish("aaaaaaaaaaa")
配置setup.proxy还是会出502,预期是正常发送消息
12-03 19:36:06 [ERROR] nonebot | Running Matcher(type='message', module=red.plugins.pixiv.pixiv_from_library, lineno=9) failed.
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\__init__.py", line 331, in run
get_driver().run(*args, **kwargs)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\drivers\none.py", line 70, in run
loop.run_until_complete(self._serve())
File "C:\Users\crosa\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 628, in run_until_complete
self.run_forever()
File "C:\Users\crosa\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 316, in run_forever
super().run_forever()
File "C:\Users\crosa\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 595, in run_forever
self._run_once()
File "C:\Users\crosa\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1881, in _run_once
handle._run()
File "C:\Users\crosa\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher
await _run_matcher(
> File "D:\bot\red\red\.venv\lib\site-packages\nonebot\message.py", line 428, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 846, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 821, in simple_run
await handler(
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 113, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "D:\bot\red\red\red\plugins\pixiv\pixiv_from_library.py", line 13, in handle_receive
await matcher.finish("aaaaaaaaaaa")
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 570, in finish
await cls.send(message, **kwargs)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 554, in send
return await bot.send(event=event, message=_message, **kwargs)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\adapters\red\bot.py", line 239, in send
resp = await self.call_api(
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api
raise exception
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
result = await self.adapter._call_api(self, api, **data)
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 250, in _call_api
return json.loads((await self.request(request)).content) # type: ignore
File "D:\bot\red\red\.venv\lib\site-packages\nonebot\adapters\red\adapter.py", line 265, in request
raise ActionFailed(
nonebot.exception.ActionFailed: ActionFailed("HTTP status code 502 response body: b''")
vps上安装的Chronocat 最新版
我使用
img = Message(MessageSegment.image(img_path))
然后bot.send(img)
发送一直无响应
这个img我打印出来大概是 [image: {'file': '地址.jpg'}]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.