mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-26 21:14:19 +00:00
🔧 Make most bullet properties async_cached_property
This commit is contained in:
parent
afa9706e98
commit
6c70e6e006
1 changed files with 17 additions and 12 deletions
|
@ -23,6 +23,7 @@ import royalnet.royaltyping as t
|
||||||
import abc
|
import abc
|
||||||
import datetime
|
import datetime
|
||||||
import sqlalchemy.orm
|
import sqlalchemy.orm
|
||||||
|
import async_property as ap
|
||||||
|
|
||||||
from . import exc
|
from . import exc
|
||||||
|
|
||||||
|
@ -58,37 +59,42 @@ class Message(Bullet, metaclass=abc.ABCMeta):
|
||||||
An abstract class representing a chat message.
|
An abstract class representing a chat message.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def text(self) -> t.Optional[str]:
|
async def text(self) -> t.Optional[str]:
|
||||||
"""
|
"""
|
||||||
:return: The raw text contents of the message.
|
:return: The raw text contents of the message.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def timestamp(self) -> t.Optional[datetime.datetime]:
|
async def timestamp(self) -> t.Optional[datetime.datetime]:
|
||||||
"""
|
"""
|
||||||
:return: The :class:`datetime.datetime` at which the message was sent.
|
:return: The :class:`datetime.datetime` at which the message was sent.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def reply_to(self) -> t.Optional[Message]:
|
async def reply_to(self) -> t.Optional[Message]:
|
||||||
"""
|
"""
|
||||||
:return: The :class:`.Message` this message is a reply to.
|
:return: The :class:`.Message` this message is a reply to.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def channel(self) -> t.Optional[Channel]:
|
async def channel(self) -> t.Optional[Channel]:
|
||||||
"""
|
"""
|
||||||
:return: The :class:`.Channel` this message was sent in.
|
:return: The :class:`.Channel` this message was sent in.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def files(self) -> t.Optional[t.List[t.BinaryIO]]:
|
async def files(self) -> t.Optional[t.List[t.BinaryIO]]:
|
||||||
"""
|
"""
|
||||||
:return: A :class:`list` of files attached to the message.
|
:return: A :class:`list` of files attached to the message.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
async def send_reply(self, *,
|
async def reply(self, *,
|
||||||
text: str = None,
|
text: str = None,
|
||||||
files: t.List[t.BinaryIO] = None) -> t.Optional[Message]:
|
files: t.List[t.BinaryIO] = None) -> t.Optional[Message]:
|
||||||
"""
|
"""
|
||||||
|
@ -108,18 +114,21 @@ class Channel(Bullet, metaclass=abc.ABCMeta):
|
||||||
An abstract class representing a channel where messages can be sent.
|
An abstract class representing a channel where messages can be sent.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def name(self) -> t.Optional[str]:
|
async def name(self) -> t.Optional[str]:
|
||||||
"""
|
"""
|
||||||
:return: The name of the message channel, such as the chat title.
|
:return: The name of the message channel, such as the chat title.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def topic(self) -> t.Optional[str]:
|
async def topic(self) -> t.Optional[str]:
|
||||||
"""
|
"""
|
||||||
:return: The topic (description) of the message channel.
|
:return: The topic (description) of the message channel.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def users(self) -> t.List[User]:
|
async def users(self) -> t.List[User]:
|
||||||
"""
|
"""
|
||||||
:return: A :class:`list` of :class:`.User` who can read messages sent in the channel.
|
:return: A :class:`list` of :class:`.User` who can read messages sent in the channel.
|
||||||
|
@ -146,12 +155,14 @@ class User(Bullet, metaclass=abc.ABCMeta):
|
||||||
An abstract class representing a user who can read or send messages in the chat.
|
An abstract class representing a user who can read or send messages in the chat.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def name(self) -> t.Optional[str]:
|
async def name(self) -> t.Optional[str]:
|
||||||
"""
|
"""
|
||||||
:return: The user's name.
|
:return: The user's name.
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
@ap.async_cached_property
|
||||||
async def database(self, session: sqlalchemy.orm.Session) -> t.Any:
|
async def database(self, session: sqlalchemy.orm.Session) -> t.Any:
|
||||||
"""
|
"""
|
||||||
:param session: A :class:`sqlalchemy.orm.Session` instance to use to fetch the database entry.
|
:param session: A :class:`sqlalchemy.orm.Session` instance to use to fetch the database entry.
|
||||||
|
@ -159,17 +170,11 @@ class User(Bullet, metaclass=abc.ABCMeta):
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
async def send_message(self, *,
|
async def slide(self) -> Channel:
|
||||||
text: str = None,
|
|
||||||
files: t.List[t.BinaryIO] = None) -> t.Optional[Message]:
|
|
||||||
"""
|
"""
|
||||||
Send a private message to the user.
|
Slide into the DMs of the user and get the private channel they share with with the bot.
|
||||||
|
|
||||||
:param text: The text to send in the message.
|
:return: The private channel where you can talk to the user.
|
||||||
:param files: A :class:`list` of files to attach to the message. The file type should be detected automatically
|
|
||||||
by the frontend, and sent in the best format possible (if all files are photos, they should be
|
|
||||||
sent as a photo album, etc.).
|
|
||||||
:return: The sent message.
|
|
||||||
"""
|
"""
|
||||||
raise exc.NotSupportedError()
|
raise exc.NotSupportedError()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue