async def prepare(self, argname, event, func, bin_stack): captured = bin_stack.command_frame.groupdict() if captured[argname] is None: return self.default if icf(self.elem.factory): return await self.elem.factory(captured[argname]) return self.elem.factory(captured[argname])
async def prepare(self, argname, event, func, bin_stack): vals = re.split( self.sep, bin_stack.command_frame.group(argname).rstrip() ) if icf(self.part.factory): return [await self.part.factory(val) for val in vals] else: return [self.part.factory(val) for val in vals]
async def run(self, comkwargs: dict) -> Union[str, Any, "vkquck.Message"]: """ Запускает код реакции с переданными comkwargs """ if icf(self.code): return await self.code(**comkwargs) else: return self.code(**comkwargs)
async def prepare(self, argname, event, func, bin_stack): if icf(self.factory): return await self.factory(bin_stack.command_frame.group(argname)) return self.factory(bin_stack.command_frame.group(argname))
async def validate( self, event: "vkquick.Event", reaction: "vkquick.Reaction", bin_stack: type, ): """ Валидирует конкретную команду """ # Текстовый блок про реакциию в дебаггере TEXT = click.style(reaction.code.__name__, fg="cyan") + "\n" for validator in reaction.validators: if icf(validator.isvalid): val = await validator.isvalid(event, reaction, bin_stack) else: val = validator.isvalid(event, reaction, bin_stack) if not val[0]: TEXT += f"-- {validator.__class__.__name__}: " + click.style( "not valid\n", fg="red") TEXT += " -> " + click.style(val[1] + "\n", fg="red") current.bot.debug_out(TEXT) break TEXT += f"-- {validator.__class__.__name__}: " + click.style( "valid\n", fg="green") else: comkwargs = {} for name, value in reaction.args.items(): if icf(value.prepare): content = await value.prepare( argname=name, event=event, func=reaction, bin_stack=bin_stack, ) else: content = value.prepare( argname=name, event=event, func=reaction, bin_stack=bin_stack, ) comkwargs.update({name: content}) for key, value in comkwargs.items(): TEXT += ("> " + click.style(key, fg="yellow") + f" = {value!r}\n") current.bot.debug_out(TEXT) response = await reaction.run(comkwargs) if isgeneratorfunction(reaction.code): await self._send_message(event, "".join(response)) elif isasyncgenfunction(reaction.code): await self._send_message( event, "".join([mes async for mes in response])) else: await self._send_message(event, response)
async def run(self, *args, **kwargs): if icf(self.code): return await self.code(*args, **kwargs) else: return self.code(*args, **kwargs)