Root App self wrapper in python
Project description
rootpy-self
Root App self wrapper in python.
Installation
pip install rootpy-self
Features
- Easy to use Discord.py-inspired API design
- Real-time events via WebSocket support for DM notifications
- Channel polling to monitor all your communities and channels
- Message handling for sending and receiving messages easily
- Profile management for avatar and status updates
- Modular design with clean, organized codebase
Quick Start
import rootpy
class MyBot(rootpy.RootClient):
def on_ready(self):
print("Bot is ready!")
def on_message(self, message):
print(f"[{message.channel_name}] {message.author_name}: {message.content}")
if message.content == "!ping":
message.reply("Pong!")
bot = MyBot(token="your_token_here")
bot.run()
Getting Your Token
- Open the Root app
- Use a network inspector or packet sniffer to capture API requests
- Find the
Authorization: Bearer <token>header - Copy the token value
API Reference
RootClient
The main client class for interacting with Root.
Constructor
RootClient(token, device_id=None)
token- Your Root API tokendevice_id- Optional device ID (auto-generated if not provided)
Core Methods
| Method | Description |
|---|---|
run(poll_interval=0.1, websocket=False) |
Start the bot and begin listening for events |
stop() |
Stop the bot and close all connections |
Community & Channel Methods
| Method | Description |
|---|---|
get_joined_communities() |
Get a list of all communities you've joined |
get_channel_groups(community_id) |
Get all channel groups in a community |
get_channels(community_id, channel_group_id) |
Get channels within a specific channel group |
get_all_channels(community_id) |
Get all channels in a community (all groups) |
add_community(community_id, name) |
Manually add a community to monitor |
User Methods
| Method | Description |
|---|---|
get_user(user_id, community_id) |
Get user information within a community |
Messaging Methods
| Method | Description |
|---|---|
send_message(channel_id, content) |
Send a message to a channel |
list_messages(channel_id, community_id, limit=3) |
Get recent messages from a channel (max 3) |
Profile Methods
| Method | Description |
|---|---|
set_avatar(asset_url) |
Set profile picture from an already-uploaded Root asset URL |
set_avatar_from_file(file_path) |
Upload a local image file and set it as profile picture |
set_avatar_from_url(image_url) |
Download an image from URL, upload it, and set as profile picture |
set_status(status_text) |
Set your status text |
Upload Methods
| Method | Description |
|---|---|
upload_image(file_path) |
Upload a local image file to Root, returns asset URL |
upload_image_from_url(url) |
Download and upload an image from URL, returns asset URL |
upload_image_bytes(image_data, extension="jpg") |
Upload raw image bytes, returns asset URL |
Events
Override these methods to handle events:
def on_ready(self):
pass
def on_message(self, message):
pass
Message
Represents a message from Root.
Properties
| Property | Type | Description |
|---|---|---|
content |
str |
Message content |
author_id |
tuple |
Author's ID |
author_name |
str |
Author's display name |
channel_id |
tuple |
Channel ID |
channel_name |
str |
Channel name |
community_id |
tuple |
Community ID |
community_name |
str |
Community name |
message_id |
tuple |
Message ID |
Methods
| Method | Description |
|---|---|
reply(content) |
Reply to the message in the same channel |
Examples
Basic Message Logger
import rootpy
class Logger(rootpy.RootClient):
def on_message(self, message):
with open("messages.log", "a") as f:
f.write(f"[{message.community_name}][{message.channel_name}] ")
f.write(f"{message.author_name}: {message.content}\n")
bot = Logger(token="your_token")
bot.run()
Command Bot with Prefix
import rootpy
class CommandBot(rootpy.RootClient):
def on_message(self, message):
if message.content.startswith("!"):
cmd = message.content[1:].split()[0]
if cmd == "ping":
message.reply("Pong!")
elif cmd == "hello":
message.reply(f"Hello, {message.author_name}!")
bot = CommandBot(token="your_token")
bot.run()
Profile Picture & Status
import rootpy
client = rootpy.RootClient(token="your_token")
client.set_avatar_from_file("my_pic.jpg")
client.set_avatar_from_url("https://example.com/image.png")
client.set_status("Hello World!")
asset_url = client.upload_image("another_pic.png")
if asset_url:
client.set_avatar(asset_url)
Requirements
- Python 3.8+
- requests
- websocket-client
License
MIT License
Disclaimer
This library is for educational purposes only. Use responsibly and in accordance with Root's Terms of Service.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rootpy_self-0.1.0.tar.gz.
File metadata
- Download URL: rootpy_self-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ed7e22bd7d8ca380467795e675b5bffcaeeb6a603596725bffc99835d718958
|
|
| MD5 |
a1461605635f01aea7e00515c6d7b7ee
|
|
| BLAKE2b-256 |
813f3636b3828281ef93edd9fd38313b2dcfff71288fa15cc8788180939db503
|
File details
Details for the file rootpy_self-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rootpy_self-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dda88f74e3d8da0307fb2e10d40bb013e02d11fc4fabe82ee78a05760a72fb2
|
|
| MD5 |
091ed475d994489076c0d924cf751554
|
|
| BLAKE2b-256 |
4c48591e95eacf0081442c868efb32fdfc6709a3ffd10ea5d408cdeec20632be
|