From 36d41006ef226745b7d0eb0698df36f814b27250 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 27 Dec 2020 22:31:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=B0=20Log=20command=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalnet/engineer/command.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/royalnet/engineer/command.py b/royalnet/engineer/command.py index cdb08441..36d3bdb9 100644 --- a/royalnet/engineer/command.py +++ b/royalnet/engineer/command.py @@ -67,14 +67,25 @@ class Command: """ The decorator interface of the command. """ - @functools.wraps(f) + log.debug("Making function {f} a teleporter...") + teleported: t.Callable = teleporter.teleport(is_async=True, validate_output=False)(f) + + @functools.wraps(teleported) async def decorated(_msg: bullet.Message, **original_kwargs) -> t.Optional[t.Conversation]: + log.debug("Getting message text...") text: str = await _msg.text() + + log.debug(f"Matching text {text} to {self.pattern}...") match: re.Match = self.pattern.search(text) + if match is None: + log.debug(f"Pattern didn't match, returning...") return + + log.debug(f"Pattern matched, getting named groups...") match_kwargs: dict = match.groupdict() - teleported: t.Callable = teleporter.teleport(is_async=True, validate_output=False)(f) + + log.debug(f"Running teleported function with args: {match_kwargs}") return await teleported(_msg=_msg, **original_kwargs, **match_kwargs) return decorated