diff --git a/kick/client.py b/kick/client.py index 70c24db..c883aec 100644 --- a/kick/client.py +++ b/kick/client.py @@ -235,6 +235,32 @@ async def fetch_stream_url_and_key(self) -> DestinationInfo: data = await self.http.fetch_stream_destination_url_and_key() return DestinationInfo(data=data) + async def get_messages(self, chatroom_id: int, /) -> list[Message]: + """ + |coro| + + Fetches messages from a chatroom. + + Parameters + ----------- + chatroom_id: int + The ID of the chatroom to fetch messages from + + Raises + ----------- + HTTPException + Failed to fetch messages + NotFound + Chatroom with provided ID was not found + + Returns + ----------- + list[Message] + List of messages from the chatroom + """ + data = await self.http.get_messages(chatroom_id) + return [Message(data=msg, http=self.http) for msg in data["data"]["messages"]] + def dispatch(self, event_name: str, *args, **kwargs) -> None: event_name = f"on_{event_name}" diff --git a/kick/message.py b/kick/message.py index 186a592..1d991b2 100644 --- a/kick/message.py +++ b/kick/message.py @@ -47,7 +47,7 @@ def slug(self) -> str: """ return self._data["slug"] - + @property def username(self) -> str: """ @@ -201,12 +201,12 @@ def references(self) -> PartialMessage | None: return PartialMessage(data=data, http=self.http) @property - def chatroom_id(self) -> int: + def chat_id(self) -> int: """ The id of the chatroom the message was sent in """ - return self._data["chatroom_id"] + return self._data["chat_id"] @property def chatroom(self) -> Chatroom | PartialChatroom | None: @@ -214,7 +214,7 @@ def chatroom(self) -> Chatroom | PartialChatroom | None: The chatroom the message was sent in. """ - return self.http.client.get_chatroom(self.chatroom_id) + return self.http.client.get_chatroom(self.chat_id) @property def content(self) -> str: @@ -244,4 +244,4 @@ def __eq__(self, other: object) -> bool: return isinstance(other, self.__class__) and other.id == self.id def __repr__(self) -> str: - return f"" + return f"" diff --git a/kick/types/message.py b/kick/types/message.py index 40f9667..a73a642 100644 --- a/kick/types/message.py +++ b/kick/types/message.py @@ -19,7 +19,7 @@ class AuthorPayload(TypedDict): class BaseMessagePayload(TypedDict): id: str - chatroom_id: int + chat_id: int content: str created_at: str sender: AuthorPayload