nonebot / adapter-feishu

NoneBot2 飞书适配器 / FeiShu (LarkSuite) adapter for nonebot2
https://feishu.adapters.nonebot.dev
MIT License
27 stars 6 forks source link

Feature: Post富文本消息需要更新 #76

Closed NeoACCG closed 10 months ago

NeoACCG commented 11 months ago

是否在使用中遇到某些问题而需要新的特性?请描述: 在message.py的原代码段中,对于富文本的请求构造无法满足官方要求,从而无法发出

    @staticmethod
    def post(title: str, content: list) -> "MessageSegment":
        return MessageSegment("post", {"title": title, "content": content})

image

描述你所需要的特性:

临时解决方案是在外层加上语言配置,或加入参数,希望作者在下一次更新中更新该功能

    @staticmethod
    def post(title: str, content: list) -> "MessageSegment":
        return MessageSegment("post", {"zh_cn":{"title": title, "content": content}})
StarHeartHunt commented 11 months ago

如果过了 MessageSerializer 的话是可以发出来的,之前考虑到 nonebot 没有相关的 i18n 支持所以直接默认 zh_cn 了。

可以考虑把语言配置项暴露出来,但是为了外部调用方便可能要像 telegram adapter 一样继承 MessageSegment。

https://github.com/nonebot/adapter-feishu/blob/017efc4d5d7c34ee091ed8ccb19ca13391669f76/nonebot/adapters/feishu/message.py#L210-L211

NeoACCG commented 11 months ago

如果过了 MessageSerializer 的话是可以发出来的,之前考虑到 nonebot 没有相关的 i18n 支持所以直接默认 zh_cn 了。

可以考虑把语言配置项暴露出来,但是为了外部调用方便可能要像 telegram adapter 一样继承 MessageSegment。

https://github.com/nonebot/adapter-feishu/blob/017efc4d5d7c34ee091ed8ccb19ca13391669f76/nonebot/adapters/feishu/message.py#L210-L211

好的,感谢大佬!

StarHeartHunt commented 10 months ago

在 d3f8508 重构了相关部分,在我的 bot 上实验通过之后应该会发版

StarHeartHunt commented 10 months ago

现在支持指定 language,例如

from nonebot.plugin import on_command
from nonebot.params import CommandArg
from nonebot.adapters import Message
from nonebot.typing import T_State
from nonebot.adapters.feishu import Bot as FeishuBot, MessageEvent, MessageSegment
from nonebot.adapters.feishu.message import PostA

helper = on_command("say")

@helper.handle()
async def feishu_helper(
    bot: FeishuBot,
    event: MessageEvent,
    state: T_State,
    command_arg: Message = CommandArg(),
):
    await helper.finish(
        MessageSegment.post(
            title="测试",
            content=[[PostA(tag="a", text="123", href="https://baka.icu")]],
            language="zh_cn",
        ),
        at_sender=True,
    )