Files
python-client-sdk/revolt/message.py
T
2021-08-29 17:05:28 +01:00

32 lines
1.1 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from .asset import Asset
from .embed import Embed
from .channel import TextChannel, PartialTextChannel, Messageable
if TYPE_CHECKING:
from .state import State
from .types import Message as MessagePayload
class Message:
def __init__(self, data: MessagePayload, state: State):
self.state = state
self.id = data["_id"]
self.content = data["content"]
self.attachments = [Asset(attachment, state) for attachment in data.get("attachments", [])]
self.embeds = [Embed.from_dict(embed) for embed in data.get("embeds", [])]
channel = state.get_channel(data["channel"]) or PartialTextChannel(data["channel"], state)
assert isinstance(channel, Messageable)
self.channel = channel
self.server = self.channel and self.channel.server
if isinstance(self.channel, TextChannel) and self.server:
self.author = state.get_member(self.server.id, data["author"])
else:
self.author = state.get_user(data["author"])