From 772d96a994e56f824f6443039029ebbfb27cc5f0 Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt Date: Mon, 30 Sep 2024 13:43:19 +0800 Subject: [PATCH] :bug: fix `remove_tome` default --- arclet/entari/command/__init__.py | 12 ++++++------ arclet/entari/command/plugin.py | 4 ++-- arclet/entari/event.py | 30 ++++++++++++++++-------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/arclet/entari/command/__init__.py b/arclet/entari/command/__init__.py index 0d4088e..dabcd58 100644 --- a/arclet/entari/command/__init__.py +++ b/arclet/entari/command/__init__.py @@ -36,7 +36,7 @@ class EntariCommands: __namespace__ = "Entari" - def __init__(self, need_tome: bool = False, remove_tome: bool = False): + def __init__(self, need_tome: bool = False, remove_tome: bool = True): self.trie: CharTrie = CharTrie() self.publisher = Publisher("EntariCommands", MessageCreatedEvent) self.publisher.providers.append(AlconnaProviderFactory()) @@ -114,7 +114,7 @@ def command( command: str, help_text: Optional[str] = None, need_tome: bool = False, - remove_tome: bool = False, + remove_tome: bool = True, auxiliaries: Optional[list[BaseAuxiliary]] = None, providers: Optional[ list[Union[Provider, type[Provider], ProviderFactory, type[ProviderFactory]]] @@ -131,7 +131,7 @@ def on( self, command: Alconna, need_tome: bool = False, - remove_tome: bool = False, + remove_tome: bool = True, auxiliaries: Optional[list[BaseAuxiliary]] = None, providers: Optional[ list[Union[Provider, type[Provider], ProviderFactory, type[ProviderFactory]]] @@ -143,7 +143,7 @@ def on( self, command: str, need_tome: bool = False, - remove_tome: bool = False, + remove_tome: bool = True, auxiliaries: Optional[list[BaseAuxiliary]] = None, providers: Optional[ list[Union[Provider, type[Provider], ProviderFactory, type[ProviderFactory]]] @@ -157,7 +157,7 @@ def on( self, command: Union[Alconna, str], need_tome: bool = False, - remove_tome: bool = False, + remove_tome: bool = True, auxiliaries: Optional[list[BaseAuxiliary]] = None, providers: Optional[ list[Union[Provider, type[Provider], ProviderFactory, type[ProviderFactory]]] @@ -209,7 +209,7 @@ def wrapper(func: TCallable) -> TCallable: _commands = EntariCommands() -def config_commands(need_tome: bool = False, remove_tome: bool = False): +def config_commands(need_tome: bool = False, remove_tome: bool = True): _commands.need_tome = need_tome _commands.remove_tome = remove_tome diff --git a/arclet/entari/command/plugin.py b/arclet/entari/command/plugin.py index aa7aa72..cb14ee3 100644 --- a/arclet/entari/command/plugin.py +++ b/arclet/entari/command/plugin.py @@ -18,7 +18,7 @@ def __init__( plugin: Plugin, command: Alconna, need_tome: bool = False, - remove_tome: bool = False, + remove_tome: bool = True, ): self.supplier = AlconnaSuppiler(command, need_tome, remove_tome) super().__init__(plugin, MessageCreatedEvent) @@ -49,7 +49,7 @@ def dispose(self): Query = Query -def mount(cmd: Alconna, need_tome: bool = False, remove_tome: bool = False): +def mount(cmd: Alconna, need_tome: bool = False, remove_tome: bool = True): if not (plugin := Plugin.current()): raise LookupError("no plugin context found") disp = AlconnaPluginDispatcher(plugin, cmd, need_tome, remove_tome) diff --git a/arclet/entari/event.py b/arclet/entari/event.py index aa4f6ba..8599f33 100644 --- a/arclet/entari/event.py +++ b/arclet/entari/event.py @@ -55,6 +55,19 @@ class Event: role: Role | None = attr() user: User | None = attr() + _attrs: ClassVar[set[str]] = { + "argv", + "button", + "channel", + "guild", + "login", + "member", + "message", + "operator", + "role", + "user", + } + def __init__(self, account: Account, origin: SatoriEvent): self.account = account self._origin = origin @@ -67,21 +80,10 @@ async def gather(self, context: Contexts): context["$account"] = self.account context["$origin_event"] = self._origin - for attrname in { - "argv", - "button", - "channel", - "guild", - "login", - "member", - "message", - "operator", - "role", - "user", - }: - value = getattr(self, attrname) + for name in self.__class__._attrs: + value = getattr(self, name) if value is not None: - context["$message_origin" if attrname == "message" else attrname] = value + context["$message_origin" if name == "message" else name] = value class AccountProvider(Provider[Account]): async def __call__(self, context: Contexts):