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#
Create an application at https://discord.com/developers/applications.
Add a bot to it and copy its token.
Invite it to your server with the
botandapplications.commandsscopes and these permissions:Permission
Why
View Channel
To see the notification channels
Send Messages
For the
embedstyleEmbed Links
For the
embedstyleManage Webhooks
For the
webhookstyle, which is the defaultMention Everyone
Only if your messages ping
@everyoneor rolesThe bot logs an invite URL with exactly these permissions when it connects (
invite_urlin thediscord readyline), 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 |
|---|---|---|
|
(required) |
The Twitch application’s client ID |
|
|
Where the watches are stored (SQLite) |
|
|
How soon a new stream counts as the same one; |
|
unset |
Set to |
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 |
|---|---|---|
|
(required) |
|
|
(required) |
File holding the Discord bot token |
|
(required) |
File holding the Twitch client secret |
|
|
|
|
|
|
|
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).