[docs]classAction:'''The base class for all Actions Args: func (Callable, *optional*): the function that will be executed kwgs (dict[str, Any], *optional*): additonal arguments for func middleware (Callabe, *optional*): a function to be executed before the main function run fill_vars (bool, *True*): Weither to automatically render vars in kwgs or not, defaults to *true*'''def__init__(self,func:Callable=None,kwgs:dict=None,middleware:Callable=None,fill_vars:bool=True):self.func=funcself.kwgs=kwgsor{}self.middleware=middlewareself.fill_vars=fill_vars
asyncdef__call__(self,u:Update):'''the entry-point to the action here we render vars, run middlewares, and finally executing main funciton'''_vars=self.kwgs.copy()ifself.middleware:try:awaitrun_function(self.middleware,self,u,_vars)exceptStopExecution:returnifself.fill_vars:forvarin_vars:ifisinstance(_vars[var],Callable):_vars[var]=_vars[var](u)ifisinstance(_vars[var],str):_vars[var]=render_vars(_vars[var],u.json,{"cache":self.app.cache})ifnotisinstance(self.func,Callable):raiseValueError(f"{self.__class__.__name__}.func should be callable, not {type(self.func)}")returnawaitrun_function(self.func,**_vars)