@@ -113,7 +113,9 @@ async def execute(self, message: MessageChain, ctx: Contexts):
113113 def command (self , cmd : str , help_text : str | None = None , providers : TProviders | None = None ):
114114 class Command (AlconnaString ):
115115 def __call__ (_cmd_self , func : Callable [..., TM ]) -> Subscriber [TM ]:
116- return self .on (_cmd_self .build (), providers )(func )
116+ wrapper = self .on (_cmd_self .build (), providers )
117+ wrapper ._depth = 1
118+ return wrapper (func )
117119
118120 return Command (cmd , help_text )
119121
@@ -149,10 +151,14 @@ def wrapper(func: Callable[..., TM]) -> Subscriber[TM]:
149151 f" { arg .value .target } " for arg in _command .args if isinstance (arg .value , DirectPattern )
150152 )
151153 if plg :
152- target = plg .dispatch (CommandDispatch ).handle (func , providers = providers )
154+ wpr = plg .dispatch (CommandDispatch ).handle (providers = providers )
155+ wpr ._depth += 1 + getattr (wrapper , "_depth" , 0 )
156+ target = wpr (func )
153157 plg ._extra .setdefault ("commands" , []).append (([], _command .command ))
154158 else :
155- target = self .scope .register (func , CommandDispatch , providers = providers )
159+ wpr = self .scope .register (event = CommandDispatch , providers = providers )
160+ wpr ._depth += 1 + getattr (wrapper , "_depth" , 0 )
161+ target = wpr (func )
156162 target .propagate (AlconnaSuppiler (_command , self ._cache .setdefault (_command ._hash , LRU (10 )), self .block ))
157163 target .propagate (_after_execute , priority = 0 )
158164 self .trie .setdefault (key , []).append (target .id )
@@ -181,10 +187,14 @@ def _remove(_):
181187 keys .append (prefix + _command .command )
182188
183189 if plg :
184- target = plg .dispatch (CommandDispatch ).handle (func , providers = providers )
190+ wpr = plg .dispatch (CommandDispatch ).handle (providers = providers )
191+ wpr ._depth += 1 + getattr (wrapper , "_depth" , 0 )
192+ target = wpr (func )
185193 plg ._extra .setdefault ("commands" , []).append ((_command .prefixes , _command .command ))
186194 else :
187- target = self .scope .register (func , providers = providers )
195+ wpr = self .scope .register (event = CommandDispatch , providers = providers )
196+ wpr ._depth += 1 + getattr (wrapper , "_depth" , 0 )
197+ target = wpr (func )
188198 target .propagate (AlconnaSuppiler (_command , self ._cache .setdefault (_command ._hash , LRU (10 )), self .block ))
189199 target .propagate (_after_execute , priority = 0 )
190200 self .subscribers [target .id ] = target
0 commit comments