Setup#

The bot needs a Twitch application, a Discord application, and somewhere to run. It runs on Linux (amd64 and arm64) as a systemd service.

Twitch#

Register an application at https://dev.twitch.tv/console/apps and copy its Client ID and a Client Secret. The OAuth redirect URL can be http://localhost; it isn’t used.

The bot only needs an app access token, so no one has to log in with a Twitch account.

Warning

The bot reuses the application’s first EventSub conduit and deletes EventSub subscriptions it doesn’t need. Give each deployment its own Twitch application.

Discord#

  1. Create an application at https://discord.com/developers/applications.

  2. Add a bot to it and copy its token.

  3. Invite it to your server with the bot and applications.commands scopes and these permissions:

    Permission

    Why

    View Channel

    To see the notification channels

    Send Messages

    For the embed style

    Embed Links

    For the embed style

    Manage Webhooks

    For the webhook style, which is the default

    Mention Everyone

    Only if your messages ping @everyone or roles

    The bot logs an invite URL with exactly these permissions when it connects (invite_url in the discord ready line), so the easiest way is to start it first and open that link.

The bot works in every server it is invited to.

Running it#

Download the archive for your platform from the GitLab releases and extract it, or build it yourself with go build ..

The Discord token and the Twitch client secret are only ever read as systemd credentials named discord-token and twitch-client-secret — never from the environment. Any of LoadCredential=, LoadCredentialEncrypted= or SetCredential= works. To try it out from a shell, with each secret in a file of that name:

systemd-run --user --pty --same-dir \
  -p LoadCredential=discord-token:$PWD/discord-token \
  -p LoadCredential=twitch-client-secret:$PWD/twitch-client-secret \
  -E TWITCH_CLIENT_ID=... \
  ./stream_title_bot

Configuration#

Variable

Default

Meaning

TWITCH_CLIENT_ID

(required)

The Twitch application’s client ID

DB_PATH

stream_title_bot.db

Where the watches are stored (SQLite)

RESTART_GRACE

10m

How soon a new stream counts as the same one; 0 disables (details)

DEBUG

unset

Set to 1 for debug logging

NixOS#

The flake’s nixosModules.default provides services.stream-title-bot. It runs the bot as a sandboxed systemd service with a dynamic user, keeping its database in /var/lib/stream-title-bot.

services.stream-title-bot = {
  enable = true;
  twitchClientId = "...";
  # Read at runtime and passed as systemd credentials, e.g. sops-nix paths.
  # Never copied to the Nix store, so they can stay root-only.
  discordTokenFile = config.sops.secrets.stream-title-bot-discord.path;
  twitchClientSecretFile = config.sops.secrets.stream-title-bot-twitch.path;
};

Option

Default

Meaning

twitchClientId

(required)

TWITCH_CLIENT_ID

discordTokenFile

(required)

File holding the Discord bot token

twitchClientSecretFile

(required)

File holding the Twitch client secret

restartGrace

"10m"

RESTART_GRACE

debug

false

DEBUG

package

the flake’s

The bot package to run

On hosts with the hostedServices module, the service registers itself there instead (without a virtual host, since the bot serves nothing).