mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-25 00:15:23 -04:00
make context subclass messageable
This commit is contained in:
@@ -107,6 +107,9 @@ class TextChannel(Channel, Messageable):
|
||||
if role_perms := data.get("role_permissions"):
|
||||
self.role_permissions = {role_id: ChannelPermissions(perms) for role_id, perms in role_perms.items()}
|
||||
|
||||
def _get_channel_id(self) -> str:
|
||||
return self.id
|
||||
|
||||
@property
|
||||
def last_message(self) -> Message:
|
||||
return self.state.get_message(self.last_message_id)
|
||||
|
||||
@@ -14,7 +14,7 @@ __all__ = (
|
||||
"Context",
|
||||
)
|
||||
|
||||
class Context:
|
||||
class Context(revolt.Messageable):
|
||||
"""Stores metadata the commands execution.
|
||||
|
||||
Attributes
|
||||
@@ -38,6 +38,9 @@ class Context:
|
||||
"""
|
||||
__slots__ = ("command", "invoked_with", "args", "message", "server", "channel", "author", "view", "kwargs")
|
||||
|
||||
def _get_channel_id(self) -> str:
|
||||
return self.channel.id
|
||||
|
||||
def __init__(self, command: Optional[Command], invoked_with: str, view: StringView, message: revolt.Message):
|
||||
self.command = command
|
||||
self.invoked_with = invoked_with
|
||||
|
||||
@@ -13,17 +13,19 @@ __all__ = ("Messageable",)
|
||||
|
||||
class Messageable:
|
||||
"""Base class for all channels that you can send messages in
|
||||
|
||||
|
||||
Attributes
|
||||
-----------
|
||||
id: :class:`str`
|
||||
The id of the channel
|
||||
"""
|
||||
id: str
|
||||
state: State
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def _get_channel_id(self) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
async def send(self, content: Optional[str] = None, *, embeds: Optional[list[Embed]] = None, embed: Optional[Embed] = None, attachments: Optional[list[File]] = None, replies: Optional[list[MessageReply]] = None, reply: Optional[MessageReply] = None) -> Message:
|
||||
"""Sends a message in a channel, you must send at least one of either `content`, `embeds` or `attachments`
|
||||
|
||||
@@ -52,5 +54,5 @@ class Messageable:
|
||||
embed_payload = [embed.to_dict() for embed in embeds] if embeds else None
|
||||
reply_payload = [reply.to_dict() for reply in replies] if replies else None
|
||||
|
||||
message = await self.state.http.send_message(self.id, content, embed_payload, attachments, reply_payload)
|
||||
message = await self.state.http.send_message(self._get_channel_id(), content, embed_payload, attachments, reply_payload)
|
||||
return self.state.add_message(message)
|
||||
|
||||
Reference in New Issue
Block a user