Skip to content

Releases: nonebot/plugin-alconna

Nonebot Plugin Alconna 0.27.3

13 Oct 14:37
Compare
Choose a tag to compare
  • 升级适配 adapter-satori v0.4.0

Full Changelog: v0.27.2...v0.27.3

Nonebot Plugin Alconna 0.27.2

11 Oct 08:03
Compare
Choose a tag to compare
  • 修复依赖问题

Full Changelog: v0.27.1...v0.27.2

Nonebot Plugin Alconna 0.27.1

10 Oct 10:51
Compare
Choose a tag to compare
  • sendgot 的 prompt 若为str,现在直接将递给 bot.send 而不是转为 UniMessage
    Full Changelog: v0.27.0...v0.27.1

Nonebot Plugin Alconna 0.27.0

09 Oct 07:56
Compare
Choose a tag to compare

新增:

  • 适配 Satori 适配器
  • 类似 telegram, satori 同样支持富文本解析:
    from nonebot.adapters.satori import Message
    from nonebot_plugin_alconna.adapters.satori import Bold, Underline
    
    msg = Message("/com<b>mand some_arg</b> <u>some_arg</u> some_arg")
    
    alc = Alconna("/command", Args["some_arg", Bold]["some_arg1", Underline]["some_arg2", str])
    
    res = alc.parse(msg)
    assert res.matched
    assert res.some_arg.data["style"] == "b"
    assert res.some_arg1.data["style"] == "u"
    assert isinstance(res.some_arg2, str)

Full Changelog: v0.26.1...v0.27.0

Nonebot Plugin Alconna 0.26.1

05 Oct 13:43
Compare
Choose a tag to compare
  • send_hook 改名为 send_wrapper
  • 增加 receive_wrapperparse_wrapper

Full Changelog: v0.26.0...v0.26.1

Nonebot Plugin Alconna 0.26.0

04 Oct 14:15
Compare
Choose a tag to compare

破坏性改动

  • on_alconna 等删除参数 output_converter, message_provider,用 Extension 替代

新增

  • 新增对象 Extension, 用于自定义 AlconnaMatcher 的部分行为 #7
    例如 LLMExtension,可以用于将自然语言通过llm转为指令:
    from nonebot_plugin_alconna import Extension, Alconna
    
    class LLMExtension(Extension):
        @property
        def priority(self) -> int:
            return 10
    
        @property
        def id(self) -> str:
            return "LLMExt"
        
        def __init__(self, llm):
          self.llm = llm
        
        def post_init(self, alc: Alconna) -> None:
            self.llm.add_context(alc.command, alc.meta.description)
    
        async def message_provider(
            self, event, state, bot, use_origin: bool = False
        ):
            if event.get_type() != "message":
                return 
            resp = await self.llm.input(str(event.get_message()))
            return event.get_message().__class__(resp.content)
    目前 Extension 的功能有:
    • 对于此时事件的来源适配器或bot选择是否接受响应
    • 对输出信息的自定义转换方式
    • 对于事件 -> 消息 的自定义处理方式
    • 对于传入的alc对象的追加的自定义处理
    • 对于 AlconnaMatcher.send 时传入的消息对象的自定义处理方式
    • 自定义额外的matcher api
  • on_alconna 等新增参数 extensionsexclude_ext
    • extensions: 需要加载的匹配扩展, 可以是扩展类或扩展实例
    • exclude_ext: 需要排除的匹配扩展, 可以是扩展类或扩展的id, 可以用来排除预期的全局加载的拓展
  • discord 适配器增加 DiscordSlashExtension,其可自动将 Alconna 对象翻译成 slash指令并注册,且将收到的指令交互事件转为指令供命令解析
  • 新增配置项 ALCONNA_GLOBAL_EXTENSIONS,用来声明全局加载的扩展,例如
     ALCONNA_GLOBAL_EXTENSIONS=["~adapters.discord:DiscordSlashExtension"]
    其值类似于 entry_points 的格式,并且当不指定 ":" 后的属性时自动补全为 ":__extension__"

改进

  • 添加了部分log
  • 为 log与exception 添加了 i18n 支持

修复

杂项

New Contributors

Full Changelog: v0.25.1...v0.26.0

Nonebot Plugin Alconna 0.25.1

27 Sep 11:42
Compare
Choose a tag to compare
  • 改进 Argv 对于不同适配器消息的处理
  • 现在 unisegalconna 下的子插件

Full Changelog: v0.25.0...v0.25.1

Nonebot Plugin Alconna 0.25.0

24 Sep 12:32
Compare
Choose a tag to compare

新增

  • on_alconna 等新增参数 message_provider,其可用于自定义命令消息的获取方式(例如从非消息事件中提前信息构造消息):
     def recall_msg_provider(rule, event, state, bot):
         if not isinstance(event, GroupMessageDeleteEvent):
             return None
         return UniMessage(f"/recall {str(event.group_id)} {str(event.user_id)} {str(event.message_id)}")
    
     recall = on_alconna(
         Alconna( "/recall", Args["group_id", str]["user_id", str]["message_id", int]),
         message_provider=recall_msg_provider,
     )
  • assign 等新增参数 additional ,其可用于添加额外的判断条件 (例如权限判断):
     def permission_checker(permission: str):
     
         async def wrapper(event, bot, state, arp):
             return await check_perm(event, permission)
         return wrapper
     
     group = on_alconna(
         Alconna(
             "group",
             Option("add", Args["group_id", int]["name", str]),
             Option("remove", Args["group_id", int]),
             Option("list"),
         ),
     )
     
     @group.assign("add", additional=permission_checker("group.add"))
     async def group_add(group_id: int, name: str):
         await group.finish(f"add {group_id} {name}")
     
     @group.assign("remove", additional=permission_checker("group.remove"))
     async def group_remove(group_id: int):
         await group.finish(f"remove {group_id}")

改进

  • on_alconna 不再只匹配 type 为 message 的事件
  • assign, got_path 等的 path 参数现在支持 ~XXX 语法,其会把 ~ 替换为可能的父级路径:
     pip = Alconna(
         "pip",
         Subcommand(
             "install",
             Args["pak", str],
             Option("--upgrade|-U"),
             Option("--force-reinstall"),
         ),
         Subcommand("list", Option("--out-dated")),
     )
     
     pipcmd = on_alconna(pip)
     pip_install_cmd = pipcmd.dispatch("install")
     
     
     @pip_install_cmd.assign("~upgrade")
     async def pip1_u(pak: Query[str] = Query("~pak")):
         await pip_install_cmd.finish(f"pip upgrading {pak.result}...")

修复

  • 修复 got_pathUnion 失效的问题

Full Changelog: v0.24.0...v0.25.0

Nonebot Plugin Alconna 0.24.0

18 Sep 13:29
Compare
Choose a tag to compare

新增

  • UniMessage 增加了 UniMessage.template,其与 MessageTemplate 的用法基本相同
    除此之外,UniMessage 对于 {:XXX} 做了一类拓展。其能够识别例如 At(xxx, yyy)Emoji(aaa, bbb)的字符串并执行
    At(...) 为例:
     UniMessage.template("{:At(user, target)}").format(target="123") == UniMessage(At("user", "123"))
     UniMessage.template("{:At(0, 1)}").format("user", "123")  == UniMessage(At("user", "123"))
     UniMessage.template("{:At(type=user, target=id)}").format(id="123") == UniMessage(At("user", "123"))
     UniMessage.template("{:At(type=user, target=123)}").format() == UniMessage(At("user", "123"))
     # 这种写法只能在 AlconnaMatcher 内使用,并且只有 $event 与 $bot
     UniMeesage.template("{:At(user, $event.get_user_id())}").format(...)  == UniMessage(At("user", USER_ID))
  • AlconnaMatcher 内有关prompt的方法现在可以使用 UniMessageTemplate 了

Full Changelog: v0.23.1...v0.24.0

Nonebot Plugin Alconna 0.23.1

18 Sep 10:35
Compare
Choose a tag to compare