From 3a56877c19e2ee3ee29aae1aa233cd64b02081b3 Mon Sep 17 00:00:00 2001 From: Wilbur Jaywright Date: Tue, 24 Dec 2024 19:09:47 -0500 Subject: [PATCH] Added raid command - Added ServicePHP.raid_confirm() - Added ChatAPI.command() --- src/cocorum/chatapi.py | 18 +++++++++++++++++- src/cocorum/servicephp.py | 7 +++++++ src/cocorum/static.py | 21 +++++---------------- src/cocorum/uploadphp.py | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/cocorum/chatapi.py b/src/cocorum/chatapi.py index b6ae1ba..b413ff4 100644 --- a/src/cocorum/chatapi.py +++ b/src/cocorum/chatapi.py @@ -430,11 +430,27 @@ def send_message(self, text: str, channel_id: int = None): ) if r.status_code != 200: - print("Error: Sending message failed,", r, r.content.decode(static.Misc.text_encoding)) + print("Error: Sending message failed,", r, r.text) return return int(r.json()["data"]["id"]), ChatAPIUser(r.json()["data"]["user"], self) + def command(self, command_message: str): + """Send a native chat command, returns response JSON""" + assert command_message.startswith(static.Message.command_prefix), "Not a command message" + r = requests.post( + static.URI.ChatAPI.command, + data = { + "video_id" : self.stream_id_b10, + "message" : command_message, + }, + cookies = self.session_cookie, + headers = static.RequestHeaders.user_agent, + timeout = static.Delays.request_timeout, + ) + assert r.status_code == 200, f"Command failed: {r}\n{r.text}" + return r.json() + def delete_message(self, message): """Delete a message in chat message: Object which when converted to integer is the target message ID""" diff --git a/src/cocorum/servicephp.py b/src/cocorum/servicephp.py index 8b61e50..e604d20 100644 --- a/src/cocorum/servicephp.py +++ b/src/cocorum/servicephp.py @@ -1136,3 +1136,10 @@ def playlist_delete(self, playlist_id: str): "playlist.delete", data = {"playlist_id" : utils.ensure_b36(playlist_id)}, ).text) + + def raid_confirm(self, stream_id: int): + """Confirm a raid set up in the chat of the given livestream""" + self.sphp_request( + "raid.confirm", + data = {"video_id" : utils.ensure_b10(stream_id)}, + ) diff --git a/src/cocorum/static.py b/src/cocorum/static.py index e45adcb..a680f03 100644 --- a/src/cocorum/static.py +++ b/src/cocorum/static.py @@ -66,23 +66,9 @@ class ChatAPI: #Message actions message = base + "/message" - # #For getting password salts - # get_salts = base + "?name=user.get_salts" + #Chat commands (does not use the base) + command = "https://rumble.com/chat/command" - # #For logging in - # login = base + "?name=user.login" - - # #For pinning a chat message - # pin = base + "?name=chat.message.pin" - - # #For unpinning a chat message - # unpin = base + "?name=chat.message.unpin" - - # #For muting a user - # mute = base + "?name=moderation.mute" - - # #For unmuting a user - # unmute = base + "?name=moderation.unmute" class Delays: """Various times for delays and waits""" @@ -102,6 +88,9 @@ class Message: #How long to wait between sending messages send_cooldown = 3 + #Prefix Rumble uses for native command + command_prefix = "/" + class Upload: """Data relating to uploading videos""" #Size of upload chunks, not sure if this can be changed diff --git a/src/cocorum/uploadphp.py b/src/cocorum/uploadphp.py index 9135210..b5f2fc4 100644 --- a/src/cocorum/uploadphp.py +++ b/src/cocorum/uploadphp.py @@ -208,7 +208,7 @@ def upload_video(self, file_path, title: str, category1, **kwargs): Defaults to free. scheduled_publish: Time to publish the video to public in seconds since epoch. Defaults to publish immediately. - thumbnail: Thumbnail to use. Set to index 0-2 for an auto thumbnail, or a file path for custom. + thumbnail: Thumbnail to use. Set to index 0-2 for an auto thumbnail, or a local file path for custom. Defaults to 0 """ assert os.path.exists(file_path), "Video file does not exist on disk"