11from __future__ import annotations
22
33from typing import Any
4+ from typing_extensions import deprecated
45
56from arclet .alconna import Alconna , command_manager
67from arclet .letoderea import define , deref , use
1920# fmt: off
2021
2122
23+ class _ExecuteDispatcher (PluginDispatcher ):
24+ def __init__ (self , plugin : Plugin , supplier : AlconnaSuppiler ):
25+ super ().__init__ (plugin , CommandExecute )
26+ plugin .collect (self .propagators .append (supplier ))
27+
28+ def assign (self , path : str , value : Any = _seminal , or_not : bool = False , priority : int = 16 , providers : TProviders | None = None ): # noqa: E501
29+ assign = Assign (path , value , or_not )
30+ return self .register (priority = priority , providers = providers , propagators = [assign ])
31+
32+
2233class AlconnaPluginDispatcher (PluginDispatcher ):
2334 def __init__ (self , plugin : Plugin , command : Alconna , need_reply_me : bool = False , need_notice_me : bool = False , use_config_prefix : bool = True , block : bool = True , skip_for_unmatch : bool = True ): # noqa: E501
2435 plugin ._extra .setdefault ("commands" , []).append ((command .prefixes , command .command ))
2536 self .cache = LRU (10 )
2637 self .supplier = AlconnaSuppiler (command , self .cache , block , skip_for_unmatch )
2738 super ().__init__ (plugin , MessageCreatedEvent , command .path )
28- self .propagators .append (
29- MessageJudges (need_reply_me , need_notice_me , use_config_prefix , None ),
39+ plugin .collect (
40+ self .propagators .append (
41+ MessageJudges (need_reply_me , need_notice_me , use_config_prefix , None ),
42+ ),
43+ self .propagators .append (self .supplier ),
44+ self .providers .append (AlconnaProviderFactory ())
3045 )
31- self .propagators .append (self .supplier )
32- self .providers .append (AlconnaProviderFactory ())
3346
3447 @plugin .collect
3548 def dispose ():
@@ -41,6 +54,10 @@ def assign(self, path: str, value: Any = _seminal, or_not: bool = False, priorit
4154 assign = Assign (path , value , or_not )
4255 return self .register (priority = priority , providers = providers , propagators = [assign ])
4356
57+ def as_execute (self ):
58+ return _ExecuteDispatcher (self .plugin , self .supplier )
59+
60+ @deprecated ("`on_execute` is deprecated. Use `as_execute` instead." )
4461 def on_execute (self , priority : int = 16 , providers : TProviders | None = None ):
4562 with self .plugin ._scope .context ():
4663 return use (exec_pub , priority = priority , providers = providers , propagators = [self .supplier ])
0 commit comments