Git Product home page Git Product logo

nonebot-plugin-send-anything-anywhere's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nonebot-plugin-send-anything-anywhere's Issues

Proposal: 引入 send 方法

send 接口设计

MessageFactory.send()

await msg_factory.send()

MessageFactory.send_to()

# 每个 adapter 有自己的 Target
send_target = Target(message_type="group", group_id=314159) 
await msg_factory.send_to(bot, send_target)

adapter 的 send 适配

SendTarget = TypeVar('SendTarget')

class Sender(Generic[SendTarget]):
    async def do_send(self, bot, target: SendTarget, msg: MessageFactory):
        ...

    def extract_target(self, event) -> SendTarget:
        ...

[Proposal] 消息回执相关功能

目前在整体框架层面最急切的需求是“消息回执”功能 #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:

  • 需要提供 序列化/反序列化 吗

支持 message receipt

这个版本我们添加了 message_receipt #71 ,支持返回 message_id 等信息,并且支持了消息撤回。各个 adapter 的贡献者能不能帮忙支持一下这个功能呢?

[Proposal] Support OpenID

又是因为QQ

因为某些平台回使用 OpenID,即 Bot 看不到真实的用户 ID 和群号,只能看到 OpenID。对于不同的 Bot,对应同一个用户的 OpenID 是不一样的。这种情况下 auto select bot 功能将直接G,原先的 paltform_target 也需要进行改变。

  1. 新建一个 PlatformTarget 的 mixin 或者基类,作为所有 OpenID 的基类
  2. 在这个基类中记录 BotID,auto select bot 时按照这个 BotID 选择对应机器人

以上改动对于用户(下游开发者)来说应该是无感知的

未安装QQ频道适配器时报错ModuleNotFoundError

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'

是否应该支持 Receipt 和 MessageId 的联通

对于这样的一个需要

# 发送第一条消息
receipt = await msg.send(reply=True)
# 回复自己发送的第一条消息
msg = MessageFactory(Reply(...), ...)

符合直觉的行为应该是

msg = MessageFactory(Reply(receipt), ...)

但就目前版本而言,
Reply的构建只能接受 MessageId:

class Reply(MessageSegmentFactory):
"""回复其他消息的消息段"""
data: MessageId
def __init__(self, message_id: MessageId):
"""回复其他消息的消息段
参数:
message_id: 需要回复消息的 MessageId
"""
super().__init__()
self.data = message_id

而 MessageId 和 Receipt 之间缺乏了一个链接的桥梁(以OB11为例)

class OB11MessageId(MessageId):
adapter_name: Literal[adapter] = adapter
message_id: int

class OB11Receipt(Receipt):
message_id: int
adapter_name: Literal[adapter] = adapter
async def revoke(self):
return await cast(BotOB11, self._get_bot()).delete_msg(
message_id=self.message_id
)
@property
def raw(self) -> Any:
return self.message_id

因此不能很好的构建一个自发送消息的回复, 可行的构建方法可能显得非常丑陋

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: # ...表示需要补充的参数,或者无
		...

启动报错,ImportError: cannot import name 'HTTPClientMixin'

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)

AllSupportedPlatformTarget的判断问题

目前 AllSupportedPlatformTarget 是一个泛型

AllSupportedPlatformTarget = Union[
TargetQQGroup,
TargetQQPrivate,
TargetQQGroupOpenId,
TargetQQPrivateOpenId,
TargetQQGuildChannel,
TargetQQGuildDirect,
TargetKaiheilaPrivate,
TargetKaiheilaChannel,
TargetOB12Unknow,
TargetTelegramCommon,
TargetTelegramForum,
TargetFeishuPrivate,
TargetFeishuGroup,
]

无法做到判断 Platfrom.deserialize 结果为 AllSupportedPlatformTarget, 例如:
https://github.com/MountainDash/nonebot-bison/blob/2fc6e253f3488cd6aa7a1f7b5e76b37297be2d04/nonebot_bison/config/subs_io/nbesf_model/v2.py#L36-L41
https://github.com/MountainDash/nonebot-bison/blob/2fc6e253f3488cd6aa7a1f7b5e76b37297be2d04/nonebot_bison/config/subs_io/subs_io.py#L43-L49
能否提供一个

def is_supported_platform_target(target: PlatformTarget) -> TypeGuard[AllSupportedPlatformTarget]:
	...

工具来做到这件事

如何等待适配器启动后获取 Bot 对象

使用: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 对象?

adapter 维护者

正如你所见,随着 saa 所支持的功能越来越多,所支持的 adapter 越来越多。维护整个项目所需要的工作量将是(saa的功能)✖️(saa支持的 adapter),开发者很难适配所有的的 adapter,所以在这里我们必须依赖社区的力量。

如果开发了新的功能,我们可能会请求 adapter 的维护者帮忙在对应的 adapter 上适配新的功能。对于新功能的加入、roadmap的制定都欢迎各位维护者一起讨论。在这个 issue 中将会维护各个 adapter 的维护者信息。

提前感谢大家

【提问】如何获取 消息命令开头,和参数

文档只说明了提取发送目标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())

send_to 主动发送应该怎么用?

    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群

适配请求

请问是否可以做一下satori的适配呢,自己不会写但是挺需要这个的

关于图片发送

img_ur 为我本地图片路径 如 /home/11.jpg
img_al = Image(img_ur)
img_al.send()

报错,提示 aiohttp.client_exceptions.InvalidURL:/home/11.jpg

但是我看代码里面是可以填路径的
image

qq频道无法发送图片

使用的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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.