diff --git a/pyproject.toml b/pyproject.toml index b047730..2728888 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-plugin-alconna" -version = "0.6.0" +version = "0.6.1" description = "Alconna Adapter for Nonebot" authors = [ {name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com"}, diff --git a/src/nonebot_plugin_alconna/matcher.py b/src/nonebot_plugin_alconna/matcher.py index 9b14ce4..e23b577 100644 --- a/src/nonebot_plugin_alconna/matcher.py +++ b/src/nonebot_plugin_alconna/matcher.py @@ -1,18 +1,15 @@ from __future__ import annotations -from typing import Callable, Awaitable - from arclet.alconna import Alconna, command_manager from arclet.alconna.tools import AlconnaString from nonebot.matcher import Matcher -from nonebot.adapters import Message from nonebot.plugin.on import on_message from nonebot.rule import Rule from nonebot.typing import T_RuleChecker from .rule import alconna from .model import CompConfig -from .typings import OutputType +from .typings import TConvert def on_alconna( @@ -20,7 +17,7 @@ def on_alconna( rule: Rule | T_RuleChecker | None = None, skip_for_unmatch: bool = True, auto_send_output: bool = False, - output_converter: Callable[[OutputType, str], Message | Awaitable[Message]] | None = None, + output_converter: TConvert | None = None, aliases: set[str | tuple[str, ...]] | None = None, comp_config: CompConfig | None = None, *args, @@ -50,7 +47,7 @@ def on_alconna( if aliases and command.command: command_manager.delete(command) aliases.add(str(command.command)) - command.command = "(" + "|".join(aliases) + ")" + command.command = "re:(" + "|".join(aliases) + ")" command._hash = command._calc_hash() command_manager.register(command) return on_message( diff --git a/src/nonebot_plugin_alconna/matcher.pyi b/src/nonebot_plugin_alconna/matcher.pyi index 854eb12..aa85df8 100644 --- a/src/nonebot_plugin_alconna/matcher.pyi +++ b/src/nonebot_plugin_alconna/matcher.pyi @@ -1,16 +1,14 @@ from __future__ import annotations from datetime import datetime, timedelta -from typing import Awaitable, Callable -from arclet.alconna import Alconna, Arparma -from nonebot.adapters import Message +from arclet.alconna import Alconna from nonebot.dependencies import Dependent from nonebot.matcher import Matcher from nonebot.permission import Permission from nonebot.rule import Rule from nonebot.typing import T_Handler, T_PermissionChecker, T_RuleChecker, T_State -from nonebot_plugin_alconna.typings import OutputType +from nonebot_plugin_alconna.typings import TConvert from nonebot_plugin_alconna.model import CompConfig @@ -19,7 +17,7 @@ def on_alconna( rule: Rule | T_RuleChecker | None = None, skip_for_unmatch: bool = True, auto_send_output: bool = False, - output_converter: Callable[[OutputType, str], Message | Awaitable[Message]] | None = None, + output_converter: TConvert | None = None, aliases: set[str | tuple[str, ...]] | None = None, comp_config: CompConfig | None = None, permission: Permission | T_PermissionChecker | None = ..., diff --git a/src/nonebot_plugin_alconna/rule.py b/src/nonebot_plugin_alconna/rule.py index 49340bf..d62f11e 100644 --- a/src/nonebot_plugin_alconna/rule.py +++ b/src/nonebot_plugin_alconna/rule.py @@ -1,5 +1,5 @@ import asyncio -from typing import Awaitable, Callable, ClassVar, Optional, Union, Dict +from typing import ClassVar, Optional, Union, Dict from arclet.alconna import ( Alconna, @@ -26,7 +26,7 @@ from .config import Config from .consts import ALCONNA_RESULT from .model import CommandResult, CompConfig -from .typings import OutputType +from .typings import TConvert class AlconnaRule: @@ -40,9 +40,7 @@ class AlconnaRule: comp_config: 自动补全配置 """ - default_converter: ClassVar[ - Callable[[OutputType, str], Union[Message, Awaitable[Message]]] - ] = lambda _, x: Message(x) + default_converter: ClassVar[TConvert] = lambda _, x: Message(x) __slots__ = ( "command", @@ -57,9 +55,7 @@ def __init__( command: Alconna, skip_for_unmatch: bool = True, auto_send_output: bool = False, - output_converter: Optional[ - Callable[[OutputType, str], Union[Message, Awaitable[Message]]] - ] = None, + output_converter: Optional[TConvert] = None, comp_config: Optional[CompConfig] = None, ): self.comp_config = comp_config @@ -210,9 +206,7 @@ def alconna( command: Alconna, skip_for_unmatch: bool = True, auto_send_output: bool = False, - output_converter: Optional[ - Callable[[OutputType, str], Union[Message, Awaitable[Message]]] - ] = None, + output_converter: Optional[TConvert] = None, comp_config: Optional[CompConfig] = None, ) -> Rule: return Rule( @@ -226,5 +220,5 @@ def alconna( ) -def set_output_converter(fn: Callable[[OutputType, str], Union[Message, Awaitable[Message]]]): +def set_output_converter(fn: TConvert): AlconnaRule.default_converter = fn diff --git a/src/nonebot_plugin_alconna/typings.py b/src/nonebot_plugin_alconna/typings.py index 8b40806..639561b 100644 --- a/src/nonebot_plugin_alconna/typings.py +++ b/src/nonebot_plugin_alconna/typings.py @@ -1,10 +1,10 @@ from __future__ import annotations -from typing import Callable, Any, TypeVar, Generic, Literal -from typing_extensions import ParamSpec +from typing import Callable, Any, TypeVar, Generic, Literal, Awaitable, Union +from typing_extensions import ParamSpec, TypeAlias from tarina import lang from nepattern import BasePattern, PatternModel, MatchFailed -from nonebot.internal.adapter.message import MessageSegment +from nonebot.internal.adapter.message import MessageSegment, Message TMS = TypeVar("TMS", bound=MessageSegment) P = ParamSpec("P") @@ -44,6 +44,7 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> TMS: OutputType = Literal["help", "shortcut", "completion"] +TConvert: TypeAlias = Callable[[OutputType, str], Union[Message, Awaitable[Message]]] def _isinstance(seg: MessageSegment, accepts: set[str]):