Skip to content

About

Root App Selfhost Bot.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

rootbot: a headless bot framework for Root

A framework for building bots for Root (rootapp.com). It runs a normal user account headlessly as a bot: Bearer-token auth over grpc-web, polled text-chat commands, and LiveKit voice. A complete music bot built on the framework is included as the reference example, the framework itself is bot-agnostic.

The docs carry a done/deferred mapping for the engineering standard this codebase is reviewed against.

Read this first: the risks

  • Use a throwaway account, never your main. The bot is the account it runs as: a normal Root user account, driven headlessly. Give it a dedicated alt with nothing paid attached and nothing you would miss. If the account is banned or lost, everything attached to it is gone with it.
  • The token is a full login. The Bearer token this framework runs on can do anything the account can do. Treat it like a password: keep it in the environment or in a .env file that is never committed, never paste it into chats, logs or issue reports, and treat the account as compromised if the token leaks.
  • YouTube paths carry YouTube's rules. The music example reaches YouTube through a Lavalink sidecar and yt-dlp, and that use is subject to YouTube's Terms of Service; direct access from server IPs is bot-checked, which is why the sidecar and a burner Google account exist. What you fetch and play is your responsibility.
  • Live streams are not supported. The direct-URL fetcher rejects playlists (HLS/DASH) and the provider routes cannot play live streams either, so live streams do not play. Whether and how live support should work is an open, undecided question; ordinary tracks and recorded streams are unaffected.

Unofficial project, not affiliated with Root Communications, Inc.

Install

You need Python 3.11 or newer and git. Voice playback also needs ffmpeg on the PATH.

1. ffmpeg (only for voice playback):

Windows (PowerShell):

winget install Gyan.FFmpeg

macOS / Linux (bash):

sudo apt install ffmpeg

On macOS, brew install ffmpeg works too.

2. Clone and install:

Windows (PowerShell):

git clone https://github.com/driannsa/root-bot-framework
cd root-bot-framework
py -m venv .venv
.venv\Scripts\Activate.ps1
pip install .

macOS / Linux (bash):

git clone https://github.com/driannsa/root-bot-framework
cd root-bot-framework
python3 -m venv .venv
source .venv/bin/activate
pip install .

3. Check the setup:

Windows (PowerShell):

rootbot doctor

macOS / Linux (bash):

rootbot doctor

rootbot doctor runs the setup checks and then stops. Without a token it reports [RB-E001] (no token found); that is the expected result at this point, not a failure of the install.

4. Create your first bot:

Windows (PowerShell):

rootbot new mybot
cd mybot

macOS / Linux (bash):

rootbot new mybot
cd mybot

To run it, get a token with the token capture guide, set it, and serve the skeleton (stop it with Ctrl+C):

Windows (PowerShell):

$env:ROOT_TOKEN=<redacted>
rootbot serve bot.py

macOS / Linux (bash):

export ROOT_TOKEN=<redacted>
rootbot serve bot.py

Architecture

  • rootbot.core.bot, Bot: the framework core. Owns the client, multi-community discovery and the polling loop; @bot.command decorator with typed Context, argument converters, per-user cooldowns, aliases, owner-only commands and auto-generated help; @bot.event hooks (on_ready, on_message, on_voice_join / on_voice_leave via presence diffing, on_tick, on_shutdown); a middleware pipeline around dispatch. Handler errors are contained - the loop never dies from a command.
  • rootbot.core.models, typed dataclasses (Message, Channel, Community, User, Member, Role, VoiceMember, Track) that also support dict-style access.
  • rootbot.errors, RootBotError hierarchy (AuthError, APIError, NotFoundError, ConfigError, TokenMissingError, ConversionError).
  • rootbot.config, BotConfig + loading: ROOT_TOKEN from the environment or a .env file, optional JSON config, validated.
  • rootbot.adapters.root.client, RootApi: authenticated calls to api.rootapp.com (GetSelf, ListMine/GetExtended discovery, chat List/Create/Edit/Delete/Pin, voice presence, SessionCreate), with bounded retries (exponential backoff + jitter) on transient failures.
  • rootbot.adapters.root.chat, ChatWatcher: polls every watched channel, primes a seen-ID set at startup, routes messages per community.
  • rootbot.core.cache, bounded LRU entity cache for users, channels, communities and members.
  • rootbot.core.middleware, middleware pipeline support, with logging and rate-limit middleware included.
  • rootbot.core.converters, argument converters (5m durations, int, float, bool, raw string).
  • rootbot.core.text, long-message splitting (plain text only; the framework never generates mention markup).
  • rootbot.logging, stdlib logging setup with a redaction filter that strips Bearer tokens and registered secrets from log records.
  • rootbot.testing, FakeRootApi + FakeClock for writing bot tests with no network and no sleeping.
  • rootbot.adapters.root.wire, minimal protobuf + grpc-web framing, GUID codec.
  • examples/musicbot/music.py, Lavalink client: track resolve/search and the audio stream endpoint of a Lavalink sidecar with the youtube-source plugin (direct YouTube access from a server IP does not work).
  • rootbot.voice.player, Player: joins the LiveKit room from a SessionCreate reply and publishes a mic track fed by ffmpeg PCM, with pause and volume. Voice is an optional integration, not part of the core Bot, the core skeleton is voice-free; only the music example uses this module.
  • examples/musicbot/, the music bot itself (serve loop + commands), written only against the library above.
  • examples/echobot/, examples/modbot/, minimal bots proving the framework is not music-specific.

Build your first bot

The whole framework in one file (examples/echobot/echobot.py):

from rootbot.core.bot import Bot

bot = Bot()


@bot.event
async def on_ready(bot):
    print(f"echobot ready as {bot.self_id}")


@bot.command("ping")
async def ping(ctx):
    await ctx.reply("pong")


@bot.command("echo")
async def echo(ctx):
    await ctx.reply(ctx.args or "say what?")


if __name__ == "__main__":
    bot.run()

Run it with the alt's token in the environment:

ROOT_TOKEN=<token> python3 -m examples.echobot.echobot

Bot() reads the token from ROOT_TOKEN or a .env file, discovers every community the account belongs to, and polls them all. Commands get a typed Context (message, author, channel, community, parsed args, converters like ctx.arg_duration(0) for 5m-style values). Add brief=/usage= to a command and the built-in !help lists it; add cooldown=30 for a per-user cooldown; wrap dispatch with bot.use(...) middleware. Full tutorial: Write your own bot.

Prerequisites

  • A Root alt account (throwaway, nothing paid attached, see limits).
  • A Linux VPS (Ubuntu) with Python 3.11+, ffmpeg, Java 17+, curl.
  • A burner Google account for the Lavalink YouTube OAuth step.
  • The alt's Bearer token, captured once from the real client (see deploy/capture/README.md).

Quickstart

  1. Capture the token: follow deploy/capture/README.md (Proxifier + mitmproxy, system proxy OFF, CA in the user store, ~20 s in voice).
  2. Configure: copy .env.example to .env and set ROOT_TOKEN; copy config.example.json to examples/musicbot/config.json (the ids are only a fallback, serve discovers the alt's communities automatically).
  3. Set up Lavalink: see deploy/lavalink/README.md, build the youtube-source plugin jar, write application.yml, and do the one-time OAuth device-code approval with the burner account.
  4. Deploy: bash deploy/deploy.sh root@your-vps (override the SSH command with ROOTBOT_SSH=... if plain ssh cannot reach the box). This installs a venv, systemd units for the bot and Lavalink, and starts both.
  5. Run manually instead: bash examples/musicbot/serve.sh.

Music bot commands

!play <url or search> (search shows a top-5 picker, playlists enqueue whole), !pause, !resume, !skip, !stop, !queue, !np, !vol <0-100>, !loop <off|track|queue>, !shuffle (smart, artist-spread), !autoplay (YouTube Mix refill), !remove <n>, !clear, !ping, !help. The bot joins the voice channel the command author is sitting in (follow-me), only takes commands from members of its voice channel while playing, and leaves after 5 idle minutes.

Stability promise

For the 0.x line the promise is light, and it covers three surfaces: the public API (the top-level rootbot exports plus the documented submodules), config keys, and the rootbot CLI's flags. Patch releases never break any of them. A break may land only at a minor bump, and only for something that shipped a deprecation warning one release ahead naming the replacement and the removal version. The plugin contract has its own mechanism (PLUGIN_API_VERSION).

rootbot.testing is provisional: its doubles may change in any release, including a patch release.

Tests

Two stubbed suites (no network, no LiveKit), 232 checks total:

  • python3 tests/test_serve.py, 150 checks: wire parsing of ListMine, watcher routing, follow-me, shuffle, autoplay, cards, playback loop.
  • python3 tests/test_framework.py, 82 checks: converters, middleware order/veto, cooldowns on a fake clock, auto-help, aliases, owner-only commands, log redaction, client retries, the entity cache, unknown payload fields, message splitting, written against rootbot.testing (FakeRootApi, FakeClock).

Quality gates (also in CI): ruff format --check, ruff check, and mypy rootbot/ (strict-ish) all pass.

Setting reference

.env (see .env.example): ROOT_TOKEN, the alt's session Bearer token. LAVALINK_PASSWORD, Lavalink server password; if empty, read from the file named by LAVALINK_PASSWORD_FILE. One of the two must be set: there is no default password file, and the music bot refuses to start without one (RB-E014). LAVALINK_BASE, Lavalink REST base (default http://127.0.0.1:2333). ROOTBOT_CONFIG, explicit path to the bot config JSON.

config.json (see config.example.json): community_id / container_id

  • home community and default voice channel, used as the join fallback and as the discovery fallback seed. communities, fallback list of {id, name} used only when API discovery returns nothing.

Honest limits

  • Root's Terms of Use (effective February 19, 2026) do not permit reverse engineering of the Service (Section 2.2) or the use of a robot, spider, or other automated device to monitor or copy the Service (Section 2.5). Root may suspend access without notice (Section 1.3) or terminate it immediately (Section 13). A bot-user account can be banned; use a throwaway alt with nothing paid attached, and never your main account.
  • Bearer token lifetime is unknown (hours at least). When it dies the log fills with poll errors; recapture and replace ROOT_TOKEN.
  • Chat is plain text only, a user account cannot send real embeds, so the bot formats embed-style text cards instead. The framework only ever sends plain text (it never generates mention markup), and long replies are split automatically at message_limit (default 2000 chars; Root's real limit is unknown, so the default is conservative).
  • Root is pre-1.0 and changes fast; field numbers in client.py come from the 0.9.167 client and may need re-mapping after updates.

About

Root App Selfhost Bot.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages