mountaindash / nonebot-plugin-send-anything-anywhere Goto Github PK
View Code? Open in Web Editor NEW一个帮助处理不同 adapter 消息的适配和发送的插件
License: MIT License
一个帮助处理不同 adapter 消息的适配和发送的插件
License: MIT License
说起来有没有必要弄个 extra 呢?安装的时候直接 nonebot-plugin-send-anything-anywhere[qqguild]
。
Originally posted by @he0119 in #13 (review)
文件的上传和下载,也是通讯中很普遍的功能,希望可以实现这个功能辣
文档只说明了提取发送目标extract_target,我并不能知道如何获取消息内容,在源码中我也没能找到相关的注释,所以提个iss问问希望大佬不要骂我。
我应当如何获取匹配的指令和响应参数?类比v11中on_command()匹配的依赖注入CommandStart()或CommandArg()
例如,我在kook使用以下方式,能正确输出dict的log
Event = Union[
V11MessageEvent, V12MessageEvent, kaiheilaMessageEvent, qqguidMessageEvent
]
tests = on_command("测试1")
@tests.handle()
async def _(event: Event):
logger.info(event.dict)
但是我使用如下测试的时候,会发现匹配指令成功但是直接结束,没有任何log输出
tests = on_command("测试1")
@tests.handle()
async def _(event: Event, args: Message = CommandArg()):
logger.info(event.dict)
logger.info(args.extract_plain_text())
follow nonebot/nonebot2#2641
由于 Telegram 官方更新,telegram 适配器回复消息的方式已经改为消息段:
Reply.reply(message_id)
reply_to_message_id
参数已废弃但仍可用,直到 Telegram 官方取消支持。
该补完基本的使用文档了,免得都忘记怎么用了
请问是否可以做一下satori的适配呢,自己不会写但是挺需要这个的
正如你所见,随着 saa 所支持的功能越来越多,所支持的 adapter 越来越多。维护整个项目所需要的工作量将是(saa的功能)✖️(saa支持的 adapter),开发者很难适配所有的的 adapter,所以在这里我们必须依赖社区的力量。
如果开发了新的功能,我们可能会请求 adapter 的维护者帮忙在对应的 adapter 上适配新的功能。对于新功能的加入、roadmap的制定都欢迎各位维护者一起讨论。在这个 issue 中将会维护各个 adapter 的维护者信息。
提前感谢大家
目前 AllSupportedPlatformTarget 是一个泛型
def is_supported_platform_target(target: PlatformTarget) -> TypeGuard[AllSupportedPlatformTarget]:
...
工具来做到这件事
我的新QQbot使用的是walleq:https://github.com/onebot-walle/nonebot_adapter_walleq;
我看SupportedAdapters枚举里是有onebot_v12的
使用:Telegram , APScheduler插件
当前我希望在插件中获取到适配器的 Bot 对象 并使用发送消息命令,代码如下
from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_saa import TargetTelegramCommon, MessageFactory
from nonebot_plugin_saa.utils import enable_auto_select_bot
@driver.on_bot_connect
async def do_something():
enable_auto_select_bot()
@scheduler.scheduled_job("cron", second='*/1', id="job_1")
async def send_message():
await MessageFactory("早上好").send_to(TargetTelegramCommon(chat_id='123456'))
查看 auto_select_bot.py
发现定义了 Hook 在bot 连接后来进行获取,但在以上用例中抛出了 nonebot_plugin_saa.utils.exceptions.NoBotFound
请问如何正确获取 Bot 对象?
又是因为QQ
因为某些平台回使用 OpenID,即 Bot 看不到真实的用户 ID 和群号,只能看到 OpenID。对于不同的 Bot,对应同一个用户的 OpenID 是不一样的。这种情况下 auto select bot 功能将直接G,原先的 paltform_target 也需要进行改变。
以上改动对于用户(下游开发者)来说应该是无感知的
对于这样的一个需要
# 发送第一条消息
receipt = await msg.send(reply=True)
# 回复自己发送的第一条消息
msg = MessageFactory(Reply(...), ...)
符合直觉的行为应该是
msg = MessageFactory(Reply(receipt), ...)
但就目前版本而言,
Reply的构建只能接受 MessageId:
而 MessageId 和 Receipt 之间缺乏了一个链接的桥梁(以OB11为例)
因此不能很好的构建一个自发送消息的回复, 可行的构建方法可能显得非常丑陋
message_id = MessageId.parse_raw(receipt.dict())
msg = MessageFactory(Reply(message_id))
# 或者
msg = MessageFactory(Reply(OB11MessageId(receipt.message_id))) # 非常平台特化
或许 Receipt应该提供一个生成 MessageId 的方法
class Receipt:
def to_message_id(self, ...) -> MessageId: # ...表示需要补充的参数,或者无
...
await MessageFactory([Text(msg), Mention(0)]).send_to(TargetQQGroup(group_id=int(gid)))
使用motion(0)回返回这个
[9873][05-24 23:13:40][W][CH2131] satori: parser: at 目标 undefined 不带有 id,将跳过该元素。
小白求助,谢谢大佬
在 plugin-alconna v0.21.0 中,大部分的 UniSeg不再需要填写 origin 字段,并且 Media 类增加了字段 raw
,意味着现在通用标记模型兼具了收发功能。
那么是否能在原有基础上适配通用消息的发送(
python3.10.6,ubuntu22.04
,pypi包在0.3-0.3.2均有以下报错,启动bot加载插件在require saa插件的时候
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot/plugin/manager.py", line 242, in exec_module
super().exec_module(module)
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot_plugin_vrchat/__init__.py", line 5, in <module>
require("nonebot_plugin_saa")
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot/plugin/load.py", line 173, in require
plugin = manager.load_plugin(name)
> File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot/plugin/manager.py", line 142, in load_plugin
module = importlib.import_module(name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot/plugin/manager.py", line 242, in exec_module
super().exec_module(module)
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/__init__.py", line 6, in <module>
from . import adapters as adapters
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/adapters/__init__.py", line 1, in <module>
from . import red as red
File "/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot_plugin_saa/adapters/red.py", line 7, in <module>
from nonebot.drivers import Request, HTTPClientMixin
ImportError: cannot import name 'HTTPClientMixin' from 'nonebot.drivers' (/root/bot/Nene-bot/.venv/lib/python3.10/site-packages/nonebot/drivers/__init__.py)
使用的adapter-qq,python3.10.11,nonebot2.1.2
saa==0.4.0
当需要qq频道发送一个图片的时候,
File "/home/ubuntu/.local/lib/python3.10/site-packages/nonebot_plugin_saa/abstract_factories.py", line 324, in finish
await self.send(at_sender=at_sender, reply=reply, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/nonebot_plugin_saa/abstract_factories.py", line 301, in send
target = extract_target(event)
File "/home/ubuntu/.local/lib/python3.10/site-packages/nonebot_plugin_saa/registries/platform_send_target.py", line 276, in extract_target
raise RuntimeError(f"event {event.__class__} not supported")
RuntimeError: event <class 'nonebot.adapters.qq.event.AtMessageCreateEvent'> not supported
03-16 13:17:24 [ERROR] nonebot | Failed to import "nonebot_plugin_mahjong_utils"
Traceback (most recent call last):
(前略)
File "C:\Users\huang\PycharmProjects\kuraku-kook\src\nonebot-plugin-mahjong-utils\src\nonebot_plugin_mahjong_utils\mapper\htmlrender\__init__.py", line 10, in <module>
from nonebot_plugin_saa import MessageFactory, Image
File "C:\Users\huang\AppData\Local\pypoetry\Cache\virtualenvs\nonebot-plugin-mahjong-utils-0g3qRG3K-py3.10\lib\site-packages\nonebot_plugin_saa\__init__.py", line 1, in <module>
from . import adapters # noqa: F401
File "C:\Users\huang\AppData\Local\pypoetry\Cache\virtualenvs\nonebot-plugin-mahjong-utils-0g3qRG3K-py3.10\lib\site-packages\nonebot_plugin_saa\adapters\__init__.py", line 1, in <module>
from . import qqguild, onebot_v11, onebot_v12 # noqa: F401
File "C:\Users\huang\AppData\Local\pypoetry\Cache\virtualenvs\nonebot-plugin-mahjong-utils-0g3qRG3K-py3.10\lib\site-packages\nonebot_plugin_saa\adapters\qqguild.py", line 4, in <module>
from nonebot.adapters.qqguild import Message
ModuleNotFoundError: No module named 'nonebot.adapters.qqguild'
由于目前并没有类似的返回值,因此我们无法对已发送的消息进行进一步操作,例如 回复
撤回
修改
等,因此建议添加 message_id 作为返回值,或一个能表示此条消息的对象。
目前在整体框架层面最急切的需求是“消息回执”功能 #69 #65 。
简单来说就是在调用 send 函数后返回一个消息凭据,通过个消息凭据可以完成:
将会提供这样的api:
msg_receipt = await msg.send()
# 撤回这条消息
await msg_receipt.revoke()
# 生成回复这条消息的 Reply message_segment
reply_message_segment_factory = Reply(msg_receipt)
# 得到 send 的原始返回值
returned_val = msg_receipt.raw
TBD:
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.
@docusaurus/core
, @docusaurus/module-type-aliases
, @docusaurus/preset-classic
, @docusaurus/tsconfig
, @docusaurus/types
, pytest-asyncio
, respx
, typescript
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
Gr1N/setup-poetry
, actions/cache
, actions/checkout
, actions/setup-python
, codecov/codecov-action
, nwtgck/actions-netlify
, release-drafter/release-drafter
).devcontainer/Dockerfile
mcr.microsoft.com/vscode/devcontainers/universal 2-focal
.github/actions/setup-node/action.yml
actions/setup-node v4
pnpm/action-setup v2
actions/cache v3
.github/actions/setup-python/action.yml
actions/setup-python v4
Gr1N/setup-poetry v8
.github/workflows/release-drafter.yml
actions/checkout v3
release-drafter/release-drafter v5
.github/workflows/release-trigger.yml
actions/checkout v3
.github/workflows/release.yml
actions/checkout v3
release-drafter/release-drafter v5
.github/workflows/test-no-adapters.yml
actions/checkout v3
codecov/codecov-action v3
.github/workflows/test.yml
actions/checkout v3
codecov/codecov-action v3
.github/workflows/website-deploy.yml
actions/checkout v4
nwtgck/actions-netlify v2
.github/workflows/website-preview.yml
actions/checkout v4
nwtgck/actions-netlify v2
docs/package.json
@docusaurus/core 3.1.0
@docusaurus/preset-classic 3.1.0
@mdx-js/react ^3.0.0
clsx ^1.2.1
prism-react-renderer ^2.1.0
react ^18.2.0
react-dom ^18.2.0
@docusaurus/module-type-aliases 3.1.0
@docusaurus/types 3.1.0
@docusaurus/tsconfig 3.0.0
typescript ~5.2.2
@types/react ^18.2.29
node >=18.0
package.json
pyproject.toml
pyproject.toml
nonebot2 ^2.3.0
strenum ^0.4.8
pydantic >=1.10.0,<3.0.0,!=2.5.0,!=2.5.1
anyio >=3.3.0,<5.0.0
filetype ^1.2.0
pytest-asyncio ^0.20.2
ipdb ^0.13.9
pip ^23.0
pytest-cov ^5.0.0
nonebug ^0.3.1
nonebot2 ^2.0.0rc4
ruff >=0.4.0
pytest-mock ^3.10.0
respx ^0.20.2
nonebot-adapter-onebot ^2.4.0
nonebot-adapter-kaiheila ^0.3.1
nonebot-adapter-feishu ^2.4.0
nonebot-adapter-red ^0.9.0
nonebot-adapter-dodo ^0.2.0
nonebot-adapter-qq ^1.4.1
nonebot-adapter-satori ^0.12.3
nonebot-adapter-discord ^0.1.7
await msg_factory.send()
# 每个 adapter 有自己的 Target
send_target = Target(message_type="group", group_id=314159)
await msg_factory.send_to(bot, send_target)
SendTarget = TypeVar('SendTarget')
class Sender(Generic[SendTarget]):
async def do_send(self, bot, target: SendTarget, msg: MessageFactory):
...
def extract_target(self, event) -> SendTarget:
...
例如:网页分享
例如用户的命令触发了事件,命令里还at了机器人以外的其他用户,如果可以提供统一的方法获取at信息,会更方便。
其他像图片数据之类的常见数据可能也可以。
enable_auto_select_bot()
for qq_group in read_qq_groups:
target = TargetQQGroup(group_id=qq_group)
msg_builder = MessageFactory([
Text("今日60S读世界已送达\n"),Image(msg)
])
await msg_builder.send_to(target)
这么写提示找不到bot
发到qq群
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.