From 6c1d4147864c9aad4ffc4a4b0d7673df2016f4a9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 20 Feb 2021 02:53:36 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20Reactions=20bullets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalnet/engineer/bullet.py | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/royalnet/engineer/bullet.py b/royalnet/engineer/bullet.py index 14ce0dc7..e4864043 100644 --- a/royalnet/engineer/bullet.py +++ b/royalnet/engineer/bullet.py @@ -94,6 +94,12 @@ class Message(Bullet, metaclass=abc.ABCMeta): """ raise exc.NotSupportedError() + @ap.async_cached_property + async def reactions(self) -> t.List[ReactionButton]: + """ + :return: A :class:`list` of reaction buttons attached to the message. + """ + async def reply(self, *, text: str = None, files: t.List[t.BinaryIO] = None) -> t.Optional[Message]: @@ -179,9 +185,75 @@ class User(Bullet, metaclass=abc.ABCMeta): raise exc.NotSupportedError() +class Button(Bullet, metaclass=abc.ABCMeta): + """ + An abstract class representing a clickable button. + """ + + @ap.async_cached_property + async def text(self) -> t.Optional[str]: + """ + :return: The text displayed on the button. + """ + raise exc.NotSupportedError() + + +class ReactionButton(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, + based on the users who have reacted to the button at the time of access. + """ + 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, + based on how many users have reacted to the button at the time of access. + """ + raise exc.NotSupportedError() + + @ap.async_cached_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 + message yet. + """ + raise exc.NotSupportedError() + + +class Reaction(Bullet, metaclass=abc.ABCMeta): + """ + An abstract class representing a reaction of a single user to a message, generated by clicking on a ReactionButton. + """ + + @ap.async_cached_property + async def user(self) -> User: + """ + :return: The user who reacted to the message. + """ + raise exc.NotSupportedError() + + @ap.async_cached_property + async def button(self) -> ReactionButton: + """ + :return: The ReactionButton that the user pressed to generate this reaction. + """ + raise exc.NotSupportedError() + + __all__ = ( "Bullet", "Message", "Channel", "User", + "Button", + "ReactionButton", + "Reaction", )