From 166ded19cca50f3d46e91704654edd8f68d2a50e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 28 Dec 2020 16:50:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Make=20command.run=20into=20a=20?= =?UTF-8?q?conversation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalnet/engineer/command.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/royalnet/engineer/command.py b/royalnet/engineer/command.py index 4905da3b..59aa0ac8 100644 --- a/royalnet/engineer/command.py +++ b/royalnet/engineer/command.py @@ -10,6 +10,8 @@ import re from . import teleporter from . import bullet +from . import sentry +from . import wrench log = logging.getLogger(__name__) @@ -89,14 +91,15 @@ class Command: return cls(prefix=prefix, name=name, syntax=syntax, conversation=teleporter_f, pattern=pattern, doc=doc) return decorator - async def run(self, _msg: bullet.Message, **original_kwargs) -> t.Optional[t.Conversation]: + async def run(self, _sentry: sentry.Sentry, **original_kwargs) -> t.Optional[t.Conversation]: """ - Run the command. + A conversation which runs the command. + """ + log.debug(f"Waiting for a message...") + msg = await (_sentry | wrench.Type(bullet.Message)) - :param _msg: The the message that was received. - """ - log.debug(f"Getting text of {_msg}...") - text = await _msg.text() + log.debug(f"Getting text of {msg}...") + text = await msg.text() log.debug(f"Matching text {text} to {self.pattern}...") match: re.Match = self.pattern.search(text) @@ -107,8 +110,8 @@ class Command: log.debug(f"Pattern matched, getting named groups...") match_kwargs: t.Dict[str, str] = match.groupdict() - log.debug(f"Running teleported function with args: {match_kwargs}") - return await self.conversation(_msg=_msg, **original_kwargs, **match_kwargs) + log.debug(f"Running teleported function with match kwargs: {match_kwargs}") + return await self.conversation(_sentry=_sentry, _msg=msg, **original_kwargs, **match_kwargs) __all__ = (