mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-26 21:14:19 +00:00
🔧 Stuff is actually working now?!
This commit is contained in:
parent
af5d1ace94
commit
3d055e2495
12 changed files with 49 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "royalnet"
|
||||
version = "6.1.0"
|
||||
version = "6.1.1"
|
||||
description = "A multipurpose bot framework"
|
||||
authors = ["Stefano Pigozzi <me@steffo.eu>"]
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
|
|
|
@ -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]:
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue