From dbc58f7ff18ad1277c2f59a97e859640fd63c860 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 23 Aug 2020 23:20:45 +0200 Subject: [PATCH] Fix find_user bug --- pyproject.toml | 2 +- royalnet/commands/commanddata.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 316099de..5641f378 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [tool.poetry] name = "royalnet" -version = "5.11.2" +version = "5.11.3" description = "A multipurpose bot and web framework" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalnet/commands/commanddata.py b/royalnet/commands/commanddata.py index 82c4f040..a3809ee1 100644 --- a/royalnet/commands/commanddata.py +++ b/royalnet/commands/commanddata.py @@ -8,17 +8,18 @@ from .errors import UnsupportedError if TYPE_CHECKING: from .keyboardkey import KeyboardKey + from .command import Command log = logging.getLogger(__name__) class CommandData: - def __init__(self, command): - self.command = command + def __init__(self, command: "Command"): + self.command: "Command" = command @property def loop(self): - return self.command.serf.loop + return self.command.loop @property def alchemy(self): @@ -53,7 +54,7 @@ class CommandData: error_if_none: Raise an exception if this is True and the call has no author.""" raise UnsupportedError(f"'{self.get_author.__name__}' is not supported") - async def delete_invoking(self, error_if_unavailable=False) -> None: + async def delete_invoking(self, error_if_unavailable: bool = False) -> None: """Delete the invoking message, if supported by the interface. The invoking message is the message send by the user that contains the command. @@ -63,13 +64,13 @@ class CommandData: if error_if_unavailable: raise UnsupportedError(f"'{self.delete_invoking.__name__}' is not supported") - async def find_user(self, alias: str) -> Optional["User"]: - """Find the User having a specific Alias. + async def find_user(self, identifier: Union[str, int], *, session) -> Optional["User"]: + """Find the User having a specific identifier. Parameters: - alias: the Alias to search for.""" - async with self.command.alchemy.session_acm() as session: - return await User.find(self.command.serf.alchemy, session, alias) + identifier: the identifier to search for. + session: the session that the user should be returned from""" + return await User.find(alchemy=self.alchemy, session=session, identifier=identifier) @contextlib.asynccontextmanager async def keyboard(self, text, keys: List["KeyboardKey"]):