strimertul/docs/twitch.md

3.3 KiB

Twitch integration

Configuration

Enable/disable Twitch integration

The Twitch integration can be enabled/disabled via stul-meta/modules, see modules.md for more details.

Twitch integration configuration

The Twitch integration can be configured via twitch/config using a JSON object like this:

{
	"enabled": bool,             // Enable Twitch module (required)
	"enable_bot": bool,          // Enable IRC bot
	"api_client_id": string,     // Twitch App Client ID
	"api_client_secret": string  // Twitch App Client Secret
}

The IRC bot has its own configuration in twitch/bot-config as the following JSON object:

{
	"username": string, // Bot username, probably ignored
	"oauth": string,    // OAuth token
	"channel": string,  // Twitch channel to join
	"chat_keys": bool,  // True to enable chatlog keys
	"chat_history": int // How many messages to save in twitch/chat-history
}

If chat_keys is enabled, these keys will be updated every time a new message is written in the specified channel:

  • twitch/ev/chat-message containing the message that was just written
  • twitch/chat-history containing the updated list of the last N messages (N depends on chat_history)

See this page for info on chat message schema.

Custom commands

The bot supports user-defined custom commands for basic things like auto-replies, counters and shoutouts.

The key twitch/bot-custom-commands contains a JSON dictionary of custom commands like the following:

{
	"!command" : {
		"description": string,  // Command description, for UI only
		"access_level": string, // Minimum required access level, see below
		"response": string,     // Response
		"enabled": bool         // Must be true for the command to work
	},
	...
}

Access levels

The access_level property must be a string determining what kind of users can use the command, it can be one of the following:

Access level identifier Minimum access level
"streamer" Just the broadcaster
"moderators" Moderators and up
"vip" VIP and up
"subscriber" Twitch subscribers and up
"everyone" Everyone

Every level allows people in the upper tiers to use the command as well (eg. a VIP-only command can be used by the broadcaster and moderators).

Response templating

Responses are fully functional golang templates, please refer to text/template for a full reference on syntax and functionality.

The following functions are available:

  • Every function in sprig
  • [user .] retrieves the Twitch username of whoever typed the command
  • [param N .] retrieves the Nth word after the command (ie. "param 1 ." on "!so something awful" would return "something")
  • [randomInt MIN MAX] returns a random integer between MIN and MAX
  • [game USERNAME] returns the current game for Twitch user USERNAME
  • [count COUNTER] increases the counter for key COUNTER by 1 and returns it

Sending text as the bot

Writing any string to twitch/@send-chat-message will send it as a message in chat from the bot's account