Releases: nonebot/plugin-alconna
Releases · nonebot/plugin-alconna
Nonebot Plugin Alconna 0.27.3
- 升级适配 adapter-satori v0.4.0
Full Changelog: v0.27.2...v0.27.3
Nonebot Plugin Alconna 0.27.2
- 修复依赖问题
Full Changelog: v0.27.1...v0.27.2
Nonebot Plugin Alconna 0.27.1
send
,got
的 prompt 若为str,现在直接将递给bot.send
而不是转为UniMessage
Full Changelog: v0.27.0...v0.27.1
Nonebot Plugin Alconna 0.27.0
新增:
- 适配
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
send_hook
改名为send_wrapper
- 增加
receive_wrapper
与parse_wrapper
Full Changelog: v0.26.0...v0.26.1
Nonebot Plugin Alconna 0.26.0
破坏性改动
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
等新增参数extensions
,exclude_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 支持
修复
- 🐛 Discord 斜杠命令正确转换 by @CMHopeSunshine in #9
杂项
- ⬆️ Bump actions/setup-python from 3 to 4 by @dependabot in #8
- ⬆️ auto update by pre-commit hooks by @pre-commit-ci in #10
New Contributors
- @CMHopeSunshine made their first contribution in #9
- @pre-commit-ci made their first contribution in #10
Full Changelog: v0.25.1...v0.26.0
Nonebot Plugin Alconna 0.25.1
- 改进 Argv 对于不同适配器消息的处理
- 现在
uniseg
是alconna
下的子插件
Full Changelog: v0.25.0...v0.25.1
Nonebot Plugin Alconna 0.25.0
新增
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_path
中Union
失效的问题
Full Changelog: v0.24.0...v0.25.0
Nonebot Plugin Alconna 0.24.0
新增
- 为
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
- 适配
Red Protocol
0.4 的改动
Full Changelog: v0.23.0...v0.23.1