Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions kick/chatroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from datetime import datetime
from typing import TYPE_CHECKING, AsyncIterator, Optional

from kick.http import HTTPClient
from .http import HTTPClient
from .message import Message

from .emotes import Emote
from .enums import ChatroomChatMode
Expand Down Expand Up @@ -162,7 +163,7 @@ async def disconnect(self) -> None:
await self.http.ws.unsubscribe_to_chatroom(self.id)
self.http.client._chatrooms.pop(self.id)

async def send(self, content: str, /) -> None:
async def send(self, content: str, /) -> Message:
"""
|coro|

Expand All @@ -181,9 +182,15 @@ async def send(self, content: str, /) -> None:
Sending the message failed
Forbidden
You are unauthorized from sending the message
"""

await self.http.send_message(self.id, content)
Returns
-----------
Message
The message
"""
data = await self.http.send_message(self.id, content)
message = Message(data=data["data"], http=self.http)
return message

async def fetch_chatter(self, chatter_name: str, /) -> Chatter:
"""
Expand Down Expand Up @@ -212,7 +219,7 @@ async def fetch_chatter(self, chatter_name: str, /) -> Chatter:
from .chatter import Chatter

data = await self.http.get_chatter(self.streamer_name, chatter_name)
chatter = Chatter(data=data, http=self.http, chatroom=self)
chatter = Chatter(data=data["data"], http=self.http, chatroom=self)
return chatter

async def fetch_rules(self) -> str:
Expand Down
20 changes: 10 additions & 10 deletions kick/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
MessagePayload,
ReplyOriginalMessage,
ReplyOriginalSender,
V1MessageSentPayload,
V2MessageSentPayload,
)
from .types.user import (
ChatterPayload,
Expand Down Expand Up @@ -214,7 +214,7 @@ async def start(self) -> None:
self.__session = ClientSession()

actual_ws = await self.__session.ws_connect(
f"wss://ws-us2.pusher.com/app/eb1d5f283081a78b932c?protocol=7&client=js&version=7.6.0&flash=false"
f"wss://ws-us2.pusher.com/app/32cbd69e4b950bf97679?protocol=7&client=js&version=8.4.0-rc2&flash=false"
)
self.ws = PusherWebSocket(actual_ws, http=self)
self.client.dispatch("ready")
Expand Down Expand Up @@ -264,7 +264,7 @@ async def request(self, route: Route, **kwargs) -> Any:
await asyncio.sleep(2)

LOGGER.debug(
f"Making request to {route.method} {url}. headers: {headers}, params: {kwargs.get('params', None)}, json: {kwargs.get('json', None)}"
f"Making request to {route.method} {url}. headers: {headers}, params: {kwargs.get('params', None)}, json: {kwargs.get('json', None)}, data: {kwargs.get('data', None)}"
)
try:
res = await self.__session.request(
Expand Down Expand Up @@ -337,15 +337,15 @@ async def request(self, route: Route, **kwargs) -> Any:
raise RuntimeError("Unreachable situation occured in http handling")

def send_message(
self, chatroom: int, content: str
) -> Response[V1MessageSentPayload]:
# We use the V1 api here since I havn't gotten it to work with V2.
# Unfortunatly V1 only returns a confirmation, and not the message (unlike V2)

route = Route.root("POST", "/api/v1/chat-messages")
self, chatroom: int, content: str, metadata: None | dict = None, msg_type: str = "message"
) -> Response[V2MessageSentPayload]:
route = Route.root("POST", f"/api/v2/messages/send/{chatroom}")
data = {"content": content, "type": msg_type}
if metadata is not None:
data["metadata"] = metadata
return self.request(
route,
data={"message": content, "chatroom_id": chatroom},
json=data,
)

def delete_message(self, chatroom: int, message_id: str) -> Response[Any]:
Expand Down
52 changes: 52 additions & 0 deletions kick/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,58 @@ def author(self) -> Author:

return Author(data=self._data["sender"], http=self.http)

@property
def reply_metadata(self) -> ReplyMetaData:
"""
The metadata from message to reply
"""
original_sender = {
"id": self.author.id,
"username": self.author.username
}
original_message = {
"id": self.id,
"content": self.content
}

return {
"original_message": original_message,
"original_sender": original_sender,
}

async def reply(self, content: str, /) -> Message:
"""
|coro|

Reply to a current message in the chatroom

Parameters
-----------
content: str
The message's content

Raises
-----------
NotFound
Streamer or chatter not found
HTTPException
Sending the message failed
Forbidden
You are unauthorized from sending the message

Returns
-----------
Message
The message
"""
data = await self.http.send_message(self.chatroom.id,
content,
metadata=self.reply_metadata,
msg_type="reply")
message = Message(data=data["data"], http=self.http)
return message


def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and other.id == self.id

Expand Down
5 changes: 3 additions & 2 deletions kick/types/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ class FetchMessagesPayload(TypedDict):
data: FetchMessagesDataPayload


class V1MessageSentPayload(StatusPayload):
...
class V2MessageSentPayload(StatusPayload):
status: StatusPayload
data: BaseMessagePayload
2 changes: 1 addition & 1 deletion kick/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def poll_event(self) -> None:

match raw_data["event"]:
case "App\\Events\\ChatMessageEvent":
msg = Message(data=data["livestream"], http=self.http)
msg = Message(data=data, http=self.http)
self.http.client.dispatch("message", msg)
case "App\\Events\\StreamerIsLive":
livestream = PartialLivestream(data=data, http=self.http)
Expand Down