mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-21 01:55:23 -04:00
32 lines
1.1 KiB
Python
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"])
|