2020-12-26 00:34:05 +00:00
## Configuration
```yaml
---
# Channels to join (only those can be acted on)
channels:
- mychannel
# Allow moderators to hand out permits (if set to false only broadcaster can do this)
permit_allow_moderator: true
# How long to permit on !permit command
permit_timeout: 60s
2021-05-26 12:00:21 +00:00
# Variables are made available in templating (for example useful to disable several
# rules at once using the `disable_on_template` directive)
# Supported data types: Boolean, Float, Integer, String
variables:
myvariable: true
anothervariable: "string"
2021-03-27 17:06:44 +00:00
auto_messages:
- channel: 'mychannel' # String, channel to send message to
message: 'Automated message' # String, message to send
use_action: true # Bool, optional, send message as action (`/me < message > `)
# Even though all of these are optional, at least one MUST be specified for the entry to be valid
cron: '*/10 * * * * ' # String, optional, cron syntax when to send the message
message_interval: 3 # Integer, optional, how many non-bot-messages must be sent in between
time_interval: 900s # Duration, optional, how long to wait before repeating the message
only_on_live: true # Boolean, optional, only send the message when channel is live
2021-05-26 12:00:21 +00:00
# Disable message using templating, must yield string `true` to disable the automated message
disable_on_template: '{{ ne .myvariable true }}'
2020-12-26 00:34:05 +00:00
rules: # See below for examples
- actions: # Array of actions to take when this rule matches
# Issue a ban on the user who wrote the chat-line
- ban: "reason of ban"
2021-01-10 21:15:57 +00:00
# Command to execute for the chat message, must return an JSON encoded array of actions
- command: [/bin/bash, -c, "echo '[{\"respond\": \"Text\"}]'"]
2020-12-26 00:34:05 +00:00
# Modify an internal counter value (does NOT send a chat line)
- counter: "counterid" # String to identify the counter, applies templating
2021-03-06 00:42:40 +00:00
counter_set: 25 # String, set counter to value (counter_step is ignored if set),
# applies templating but MUST result in a parseable integer
2020-12-26 00:34:05 +00:00
counter_step: 1 # Integer, can be negative or positive, default: +1
2021-05-12 16:26:17 +00:00
# Introduce a delay between two actions
- delay: 1m # Duration, how long to wait (fixed)
delay_jitter: 1m # Duration, add random delay to fixed delay between 0 and this value
2020-12-27 13:42:51 +00:00
# Issue a delete on the message caught
- delete_message: true # Bool, set to true to delete
2021-05-26 13:36:03 +00:00
# Send raw IRC message to Twitch servers
- raw_message: 'PRIVMSG #{{ .channel }} :Test' # String, applies templating
2020-12-26 00:34:05 +00:00
# Send responding message to the channel the original message was received in
2021-01-21 00:00:04 +00:00
- respond: 'Hello chatter' # String, applies templating
2021-06-02 13:31:16 +00:00
respond_as_reply: true # Boolean, optional, use Twitch-Reply feature in respond
2021-01-21 00:00:50 +00:00
respond_fallback: 'Oh noes' # String, text to send if the template function causes
2021-01-21 00:13:09 +00:00
# an error, applies templating (default: unset)
2020-12-26 00:34:05 +00:00
# Issue a timeout on the user who wrote the chat-line
- timeout: 1s # Duration value: 1s / 1m / 1h
2021-05-26 13:36:03 +00:00
# Send a whisper (ATTENTION: You need to have a known / verified bot for this!)
# Without being known / verified your whisper will just silently get dropped by Twitch
2021-05-26 13:41:37 +00:00
# Go here to get that verification: https://dev.twitch.tv/limit-increase
2021-05-26 13:36:03 +00:00
- whisper_to: '{{ .username }}' # String, username to send to, applies templating
whisper_message: 'Ohai!' # String, message to send, applies templating
2021-06-07 20:20:19 +00:00
# Add a cooldown to the rule in general (not to trigger counters twice, ...)
# Using this will prevent the rule to be executed in all matching channels
# as long as the cooldown is active.
2020-12-26 00:34:05 +00:00
cooldown: 1s # Duration value: 1s / 1m / 1h
2021-06-07 20:20:19 +00:00
# Add a cooldown to the rule per channel (not to trigger counters twice, ...)
# Using this will prevent the rule to be executed in the channel it was triggered
# which means other channels are not affected.
channel_cooldown: 1s # Duration value: 1s / 1m / 1h
# Add a cooldown to the rule per user (not to trigger counters twice, ...)
# Using this will prevent the rule to be executed for the user which triggered it
# in any of the matching channels, which means other users can trigger the command
# while that particular user cannot
user_cooldown: 1s # Duration value: 1s / 1m / 1h
2021-03-21 13:36:28 +00:00
# Do not apply cooldown for these badges
skip_cooldown_for: [broadcaster, moderator]
2021-05-26 12:00:21 +00:00
# Disable the rule by setting to true
disable: false
2021-03-21 13:04:04 +00:00
# Disable actions when the matched channel has no active stream
disable_on_offline: false
2020-12-26 00:34:05 +00:00
# Disable actions on this rule if the user has an active permit
disable_on_permit: false
2021-05-26 12:00:21 +00:00
# Disable actions using templating, must yield string `true` to disable the rule
disable_on_template: '{{ ne .myvariable true }}'
2020-12-26 00:34:05 +00:00
# Disable actions on this rule if the user has one of these badges
disable_on: [broadcaster, moderator]
# Enable actions on this rule only if the user has one of these badges
enable_on: [broadcaster, moderator]
# Require the chat message to be sent in this channel
match_channels: ['#mychannel']
2020-12-31 18:46:55 +00:00
# Require the chat message to be sent by one of these users
match_users: ['mychannel'] # List of users, all names MUST be all lower-case
2020-12-26 00:34:05 +00:00
# Execute actions when this event occurs
2021-05-26 12:38:15 +00:00
# Available events: join, host, part, permit, raid, resub, sub, subgift, whisper
2020-12-26 00:34:05 +00:00
match_event: 'permit'
# Execute action when the chat message matches this regular expression
match_message: '' # String, regular expression
# Disable the actions on this rule if one of these regular expression matches the chat message
disable_on_match_messages: []
...
```
## Templating
There are certain variables available in the strings with templating enabled:
2020-12-26 00:36:18 +00:00
- `channel` - Channel the message was sent to, only available for regular messages not events
2020-12-26 00:34:05 +00:00
- `msg` - The message object, used in functions, should not be sent to chat
- `permitTimeout` - Value of `permit_timeout` in seconds
- `username` - The username of the message author
Additionally there are some functions available in the templates:
- `arg <idx>` - Takes the message sent to the channel, splits by space and returns the Nth element
2020-12-26 01:01:13 +00:00
- `channelCounter <counter name>` - Wraps the counter name into a channel specific counter name including the channel name
2021-06-17 14:54:50 +00:00
- `concat <delimiter> <...parts>` - Join the given string parts with delimiter
2020-12-26 00:34:05 +00:00
- `counterValue <counter name>` - Returns the current value of the counter which identifier was supplied
2021-05-24 19:42:55 +00:00
- `displayName <username> [fallback]` - Returns the display name the specified user set for themselves
2021-01-20 23:35:42 +00:00
- `fixUsername <username>` - Ensures the username no longer contains the `@` or `#` prefix
- `followDate <from> <to>` - Looks up when `from` followed `to`
2020-12-26 00:34:05 +00:00
- `group <idx>` - Gets matching group specified by index from `match_message` regular expression
- `recentGame <username> [fallback]` - Returns the last played game name of the specified user (see shoutout example) or the `fallback` if the game could not be fetched. If no fallback was supplied the message will fail and not be sent.
- `tag <tagname>` - Takes the message sent to the channel, returns the value of the tag specified
2021-01-20 22:45:09 +00:00
- `toLower <string>` - Converts the given string to lower-case
- `toUpper <string>` - Converts the given string to upper-case
2020-12-26 00:34:05 +00:00
2021-01-10 21:15:57 +00:00
## Command executions
Your command will get a JSON object passed through `stdin` you can parse to gain details about the message. It is expected to yield an array of actions on `stdout` and exit with status `0` . If it does not the action will be marked failed. In case you need to output debug output you can use `stderr` which is directly piped to the bots `stderr` .
This is an example input you might get on `stdin` :
```json
{
"badges": {
"glhf-pledge": 1,
"moderator": 1
},
"channel": "#tezrian",
"message": "!test",
"tags": {
"badge-info": "",
"badges": "moderator/1,glhf-pledge/1",
"client-nonce": "6801c82a341f728dbbaad87ef30eae49",
"color": "#A72920",
"display-name": "Luziferus",
"emotes": "",
"flags": "",
"id": "dca06466-3741-4b22-8339-4cb5b07a02cc",
"mod": "1",
"room-id": "485884564",
"subscriber": "0",
"tmi-sent-ts": "1610313040489",
"turbo": "0",
"user-id": "69699328",
"user-type": "mod"
},
"username": "luziferus"
}
```
The example was dumped using this action:
```yaml
- actions:
- command: [/usr/bin/bash, -c, "jq . >& 2"]
match_channels: ['#tezrian']
match_message: '^!test'
```
2020-12-26 00:34:05 +00:00
## Rule examples
### Game death counter with dynamic name
```yaml
- actions:
2020-12-26 01:01:13 +00:00
- counter: '{{ channelCounter (recentGame .channel) }}'
2020-12-26 01:03:42 +00:00
- respond: >-
I already died {{ counterValue (channelCounter (recentGame .channel)) }}
times in {{ recentGame .channel }}'
2020-12-26 00:34:05 +00:00
cooldown: 60s
enable_on: [broadcaster, moderator]
match_channels: ['#mychannel']
match_message: '^!death'
```
### Link-protection while allowing Twitch clips
```yaml
- actions:
- timeout: 1s
- respond: '@{{ .username }}, please ask for permission before posting links.'
disable_on: [broadcaster, moderator, subscriber, vip]
disable_on_match_messages:
- '^(?:https?://)?clips\.twitch\.tv/[a-zA-Z0-9-]+$'
disable_on_permit: true
match_channels: ['#mychannel']
match_message: '(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]'
```
2021-01-20 23:35:42 +00:00
### Post follow date for an user
2021-01-20 23:37:16 +00:00
```yaml
2021-01-20 23:35:42 +00:00
- actions:
- respond: 'You followed on {{ ( followDate .username ( fixUsername .channel ) ).Format "2006-01-02" }}'
match_channels: ['#mychannel']
match_message: '^!followage'
```
2021-05-12 16:26:17 +00:00
### Respond to a message after random delay
```yaml
- actions:
# Respond after 30-40s
- delay: 30s
delay_jitter: 10s
- respond: 'Hey {{ .username }}'
match_channels: ['#mychannel']
match_message: '^Hi'
```
2020-12-26 00:34:05 +00:00
### Send a notification on successful permit
```yaml
- actions:
- respond: >-
@{{ fixUsername (arg 1) }}, you will not get timed out
for the next {{ .permitTimeout }} seconds.
match_channels: ['#mychannel']
match_event: 'permit'
```
### Shoutout command with game query
```yaml
- actions:
- respond: >-
Check out @{{ fixUsername (group 1) }} and leave a follow,
they were last playing {{ recentGame (fixUsername (group 1)) "something mysterious" }}
at https://twitch.tv/{{ fixUsername (group 1) }}
enable_on: [broadcaster, moderator]
match_channels: ['#mychannel']
match_message: '^!so ([@\w]+)'
```