diff --git a/example/.env.prod b/example/.env.prod index 9460955..065ae1f 100644 --- a/example/.env.prod +++ b/example/.env.prod @@ -4,4 +4,5 @@ PORT=9555 ALCONNA_AUTO_SEND_OUTPUT=true ALCONNA_USE_COMMAND_START=false RED_AUTO_DETECT=true -LOG_LEVEL=DEBUG \ No newline at end of file +LOG_LEVEL=DEBUG +COMMAND_START=["/", ""] diff --git a/example/plugins/demo.py b/example/plugins/demo.py index f087d29..4e15cc9 100644 --- a/example/plugins/demo.py +++ b/example/plugins/demo.py @@ -98,12 +98,6 @@ class PipResult(Duplication): # auto_send already set in .env pipcmd = on_alconna(pip, comp_config={"timeout": 10}, block=True) # , auto_send_output=True) - ali = on_alconna( - Alconna(["/"], "一言"), - aliases={"hitokoto"}, - skip_for_unmatch=True, - use_origin=True, - ) i18n = on_alconna(Alconna("lang", Args["lang", ["zh_CN", "en_US"]])) login = on_alconna( Alconna( @@ -140,6 +134,15 @@ async def pip_m(): await pipcmd.send("WIP...") +ali = on_alconna( + Alconna("一言"), + aliases={"hitokoto"}, + skip_for_unmatch=True, + use_cmd_start=True, + use_origin=True, +) + + @ali.handle() async def yiyan(res: Arparma): if res.matched: diff --git a/pyproject.toml b/pyproject.toml index f7fbafa..5439dbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ authors = [ {name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com"}, ] dependencies = [ - "arclet-alconna>=1.7.43", + "arclet-alconna>=1.7.44", "arclet-alconna-tools>=0.6.11", "nepattern>=0.5.15", "nonebot2>=2.2.0", diff --git a/src/nonebot_plugin_alconna/__init__.py b/src/nonebot_plugin_alconna/__init__.py index 104e951..17023fb 100644 --- a/src/nonebot_plugin_alconna/__init__.py +++ b/src/nonebot_plugin_alconna/__init__.py @@ -100,7 +100,7 @@ from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT from .extension import add_global_extension as add_global_extension -__version__ = "0.37.0" +__version__ = "0.37.1" __plugin_meta__ = PluginMetadata( name="Alconna 插件", diff --git a/src/nonebot_plugin_alconna/matcher.py b/src/nonebot_plugin_alconna/matcher.py index 81abb72..53dabca 100644 --- a/src/nonebot_plugin_alconna/matcher.py +++ b/src/nonebot_plugin_alconna/matcher.py @@ -893,14 +893,6 @@ def on_alconna( """ if isinstance(command, str): command = AlconnaFormat(command) - if aliases: - aliases = set(aliases) - command_manager.delete(command) - if command.command: - aliases.add(str(command.command)) - command.command = "re:(" + "|".join(aliases) + ")" - command._hash = command._calc_hash() - command_manager.register(command) _rule = alconna( command, skip_for_unmatch, @@ -911,6 +903,7 @@ def on_alconna( use_origin, use_cmd_start, use_cmd_sep, + aliases, ) executor = cast(ExtensionExecutor, list(_rule.checkers)[0].call.executor) # type: ignore params = ( diff --git a/src/nonebot_plugin_alconna/rule.py b/src/nonebot_plugin_alconna/rule.py index 0146d60..6d4dc01 100644 --- a/src/nonebot_plugin_alconna/rule.py +++ b/src/nonebot_plugin_alconna/rule.py @@ -1,8 +1,7 @@ import asyncio import importlib -from typing import Dict, List, Type, Union, Literal, Optional, cast +from typing import Set, Dict, List, Type, Tuple, Union, Literal, Optional, cast -from nonebot import get_driver from nonebot.typing import T_State from tarina import lang, init_spec from nonebot.matcher import Matcher @@ -11,6 +10,7 @@ from nonebot.plugin.on import on_message from nonebot.internal.rule import Rule as Rule from nonebot.adapters import Bot, Event, Message +from nonebot import get_driver, get_plugin_config from arclet.alconna.exceptions import SpecialOptionTriggered from arclet.alconna import Alconna, Arparma, CompSession, output_manager, command_manager @@ -63,12 +63,13 @@ def __init__( use_origin: bool = False, use_cmd_start: bool = False, use_cmd_sep: bool = False, + _aliases: Optional[Union[Set[str], Tuple[str, ...]]] = None, ): self.comp_config = comp_config self.use_origin = use_origin try: global_config = get_driver().config - config = Config.parse_obj(global_config) + config = get_plugin_config(Config) self.auto_send = auto_send_output or config.alconna_auto_send_output if ( not command.prefixes @@ -88,6 +89,9 @@ def __init__( except ValueError: self.auto_send = auto_send_output self.command = command + if _aliases: + for alias in _aliases: + command.shortcut(alias, prefix=True) self.skip = skip_for_unmatch self.executor = ExtensionExecutor(self, extensions, exclude_ext) self.executor.post_init() diff --git a/src/nonebot_plugin_alconna/uniseg/__init__.py b/src/nonebot_plugin_alconna/uniseg/__init__.py index 5b45a51..133702e 100644 --- a/src/nonebot_plugin_alconna/uniseg/__init__.py +++ b/src/nonebot_plugin_alconna/uniseg/__init__.py @@ -35,7 +35,7 @@ from .params import UniversalMessage as UniversalMessage from .params import UniversalSegment as UniversalSegment -__version__ = "0.37.0" +__version__ = "0.37.1" __plugin_meta__ = PluginMetadata( name="Universal Segment 插件",