diff --git a/pyproject.toml b/pyproject.toml index 65b314d0..1944e9b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "royalnet" -version = "6.1.0" +version = "6.1.1" description = "A multipurpose bot framework" authors = ["Stefano Pigozzi "] license = "AGPL-3.0-or-later" diff --git a/royalnet/engineer/bullet/contents/_imports.py b/royalnet/engineer/bullet/contents/_imports.py index fb6d31fe..6c786248 100644 --- a/royalnet/engineer/bullet/contents/_imports.py +++ b/royalnet/engineer/bullet/contents/_imports.py @@ -2,6 +2,7 @@ import royalnet.royaltyping as t import sqlalchemy.orm as so import abc +import async_property as ap from .. import exc from ._base import BulletContents @@ -11,6 +12,7 @@ __all__ = ( "t", "so", "abc", + "ap", "exc", "BulletContents", ) diff --git a/royalnet/engineer/bullet/contents/button.py b/royalnet/engineer/bullet/contents/button.py index 7413e69e..2a620344 100644 --- a/royalnet/engineer/bullet/contents/button.py +++ b/royalnet/engineer/bullet/contents/button.py @@ -7,6 +7,7 @@ class Button(BulletContents, metaclass=abc.ABCMeta): An abstract class representing a clickable button. """ + @ap.async_property async def text(self) -> t.Optional[str]: """ :return: The text displayed on the button. diff --git a/royalnet/engineer/bullet/contents/button_reaction.py b/royalnet/engineer/bullet/contents/button_reaction.py index 54b6ca34..e06c2846 100644 --- a/royalnet/engineer/bullet/contents/button_reaction.py +++ b/royalnet/engineer/bullet/contents/button_reaction.py @@ -13,6 +13,7 @@ class ButtonReaction(Button, metaclass=abc.ABCMeta): An abstract class representing a clickable reaction to a message. """ + @ap.async_property async def reactions(self) -> t.List["Reaction"]: """ :return: The list of reactions generated by this button. It may vary every time this property is accessed, @@ -20,6 +21,7 @@ class ButtonReaction(Button, metaclass=abc.ABCMeta): """ raise exc.NotSupportedError() + @ap.async_property async def count(self) -> int: """ :return: The count of reactions that this button generated. It may vary every time this property is accessed, @@ -27,6 +29,7 @@ class ButtonReaction(Button, metaclass=abc.ABCMeta): """ raise exc.NotSupportedError() + @ap.async_property async def message(self) -> t.Optional["Message"]: """ :return: The message this button is attached to. Can be :data:`None`, if the button hasn't been attached to a diff --git a/royalnet/engineer/bullet/contents/channel.py b/royalnet/engineer/bullet/contents/channel.py index 72890325..6ddb72b9 100644 --- a/royalnet/engineer/bullet/contents/channel.py +++ b/royalnet/engineer/bullet/contents/channel.py @@ -11,18 +11,21 @@ class Channel(BulletContents, metaclass=abc.ABCMeta): An abstract class representing a channel where messages can be sent. """ + @ap.async_property async def name(self) -> t.Optional[str]: """ :return: The name of the message channel, such as the chat title. """ raise exc.NotSupportedError() + @ap.async_property async def topic(self) -> t.Optional[str]: """ :return: The topic (description) of the message channel. """ raise exc.NotSupportedError() + @ap.async_property async def users(self) -> t.List["User"]: """ :return: A :class:`list` of :class:`.User` who can read messages sent in the channel. diff --git a/royalnet/engineer/bullet/contents/message.py b/royalnet/engineer/bullet/contents/message.py index d41138f7..df0969e5 100644 --- a/royalnet/engineer/bullet/contents/message.py +++ b/royalnet/engineer/bullet/contents/message.py @@ -13,36 +13,42 @@ class Message(BulletContents, metaclass=abc.ABCMeta): An abstract class representing a chat message. """ + @ap.async_property async def text(self) -> t.Optional[str]: """ :return: The raw text contents of the message. """ raise exc.NotSupportedError() + @ap.async_property async def timestamp(self) -> t.Optional[datetime.datetime]: """ :return: The :class:`datetime.datetime` at which the message was sent. """ raise exc.NotSupportedError() + @ap.async_property async def reply_to(self) -> t.Optional[Message]: """ :return: The :class:`.Message` this message is a reply to. """ raise exc.NotSupportedError() + @ap.async_property async def channel(self) -> t.Optional["Channel"]: """ :return: The :class:`.Channel` this message was sent in. """ raise exc.NotSupportedError() + @ap.async_property async def files(self) -> t.Optional[t.List[t.BinaryIO]]: """ :return: A :class:`list` of files attached to the message. """ raise exc.NotSupportedError() + @ap.async_property async def reactions(self) -> t.List["ButtonReaction"]: """ :return: A :class:`list` of reaction buttons attached to the message. diff --git a/royalnet/engineer/bullet/contents/user.py b/royalnet/engineer/bullet/contents/user.py index 4253e0f1..19fbc93c 100644 --- a/royalnet/engineer/bullet/contents/user.py +++ b/royalnet/engineer/bullet/contents/user.py @@ -10,12 +10,14 @@ class User(BulletContents, metaclass=abc.ABCMeta): An abstract class representing a user who can read or send messages in the chat. """ + @ap.async_property async def name(self) -> t.Optional[str]: """ :return: The user's name. """ raise exc.NotSupportedError() + @ap.async_property async def database(self, session: so.Session) -> t.Any: """ :param session: A :class:`sqlalchemy.orm.Session` instance to use to fetch the database entry. diff --git a/royalnet/engineer/bullet/projectiles/_imports.py b/royalnet/engineer/bullet/projectiles/_imports.py index 77a4fa79..3809d435 100644 --- a/royalnet/engineer/bullet/projectiles/_imports.py +++ b/royalnet/engineer/bullet/projectiles/_imports.py @@ -2,6 +2,7 @@ import royalnet.royaltyping as t import sqlalchemy.orm as so import abc +import async_property as ap from .. import exc from ._base import Projectile @@ -11,6 +12,7 @@ __all__ = ( "t", "so", "abc", + "ap", "exc", "Projectile", ) diff --git a/royalnet/engineer/bullet/projectiles/message.py b/royalnet/engineer/bullet/projectiles/message.py index 1654ea44..10887148 100644 --- a/royalnet/engineer/bullet/projectiles/message.py +++ b/royalnet/engineer/bullet/projectiles/message.py @@ -10,6 +10,7 @@ class MessageReceived(Projectile, metaclass=abc.ABCMeta): An abstract class representing the reception of a single message. """ + @ap.async_property async def message(self) -> "Message": """ :return: The received Message. @@ -22,6 +23,7 @@ class MessageEdited(Projectile, metaclass=abc.ABCMeta): An abstract class representing the editing of a single message. """ + @ap.async_property async def message(self) -> "Message": """ :return: The edited Message. @@ -34,6 +36,7 @@ class MessageDeleted(Projectile, metaclass=abc.ABCMeta): An abstract class representing the deletion of a single message. """ + @ap.async_property async def message(self) -> "Message": """ :return: The edited Message. diff --git a/royalnet/engineer/bullet/projectiles/reaction.py b/royalnet/engineer/bullet/projectiles/reaction.py index e2320b91..340ed8a2 100644 --- a/royalnet/engineer/bullet/projectiles/reaction.py +++ b/royalnet/engineer/bullet/projectiles/reaction.py @@ -11,12 +11,14 @@ class Reaction(Projectile, metaclass=abc.ABCMeta): An abstract class representing a reaction of a single user to a message, generated by clicking on a ButtonReaction. """ + @ap.async_property async def user(self) -> "User": """ :return: The user who reacted to the message. """ raise exc.NotSupportedError() + @ap.async_property async def button(self) -> "ButtonReaction": """ :return: The ButtonReaction that the user pressed to generate this reaction. diff --git a/royalnet/engineer/bullet/projectiles/user.py b/royalnet/engineer/bullet/projectiles/user.py index 377070cf..e7cb1922 100644 --- a/royalnet/engineer/bullet/projectiles/user.py +++ b/royalnet/engineer/bullet/projectiles/user.py @@ -10,6 +10,7 @@ class UserJoined(Projectile, metaclass=abc.ABCMeta): An abstract class representing an user who just joined the chat channel. """ + @ap.async_property async def user(self) -> "User": """ :return: The user who joined. @@ -22,6 +23,7 @@ class UserLeft(Projectile, metaclass=abc.ABCMeta): An abstract class representing an user who just left the chat channel. """ + @ap.async_property async def user(self) -> "User": """ :return: The user who left. @@ -34,6 +36,7 @@ class UserUpdate(Projectile, metaclass=abc.ABCMeta): An abstract class representing a change in status of an user in the chat channel. """ + @ap.async_property async def user(self) -> "User": """ :return: The user who joined. @@ -42,5 +45,7 @@ class UserUpdate(Projectile, metaclass=abc.ABCMeta): __all__ = ( - "User", + "UserJoined", + "UserLeft", + "UserUpdate", ) diff --git a/royalnet/engineer/command.py b/royalnet/engineer/command.py index 5a2bb404..0f8e5afa 100644 --- a/royalnet/engineer/command.py +++ b/royalnet/engineer/command.py @@ -90,12 +90,12 @@ class Command(c.Conversation): return log.debug(f"Getting message of: {projectile!r}") - if not (msg := await projectile.message()): + if not (msg := await projectile.message): log.warning(f"Returning: {projectile!r} has no message") return log.debug(f"Getting message text of: {msg!r}") - if not (text := await msg.text()): + if not (text := await msg.text): log.debug(f"Returning: {msg!r} has no text") return @@ -112,11 +112,25 @@ class Command(c.Conversation): with _sentry.dispenser().lock(self): log.debug(f"Passing args to function: {message_kwargs!r}") - return await super().run(_sentry=_sentry, _proj=projectile, **base_kwargs, **message_kwargs) + return await super().run( + _sentry=_sentry, + _proj=projectile, + _msg=msg, + _text=text, + **base_kwargs, + **message_kwargs + ) else: log.debug(f"Passing args to function: {message_kwargs!r}") - return await super().run(_sentry=_sentry, _proj=projectile, **base_kwargs, **message_kwargs) + return await super().run( + _sentry=_sentry, + _proj=projectile, + _msg=msg, + _text=text, + **base_kwargs, + **message_kwargs + ) def help(self) -> t.Optional[str]: """