Skip to content

Commit

Permalink
Added raid command
Browse files Browse the repository at this point in the history
- Added ServicePHP.raid_confirm()
- Added ChatAPI.command()
  • Loading branch information
thelabcat committed Dec 25, 2024
1 parent a278969 commit 3a56877
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
18 changes: 17 additions & 1 deletion src/cocorum/chatapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
7 changes: 7 additions & 0 deletions src/cocorum/servicephp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
)
21 changes: 5 additions & 16 deletions src/cocorum/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cocorum/uploadphp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3a56877

Please sign in to comment.