mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 08:10:08 +00:00
Introduce channelCounter function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ab42decb1b
commit
d3a993cda5
2 changed files with 13 additions and 3 deletions
|
@ -25,6 +25,15 @@ func formatMessage(tplString string, m *irc.Message, r *rule, fields map[string]
|
|||
return msgParts[arg], nil
|
||||
}
|
||||
|
||||
messageFunctions["channelCounter"] = func(name string) (string, error) {
|
||||
channel, ok := fields["channel"].(string)
|
||||
if !ok {
|
||||
return "", errors.New("channel not available")
|
||||
}
|
||||
|
||||
return strings.Join([]string{channel, name}, ":"), nil
|
||||
}
|
||||
|
||||
messageFunctions["counterValue"] = func(name string, _ ...string) int64 {
|
||||
return store.GetCounterValue(name)
|
||||
}
|
||||
|
@ -41,7 +50,7 @@ func formatMessage(tplString string, m *irc.Message, r *rule, fields map[string]
|
|||
}
|
||||
|
||||
messageFunctions["recentGame"] = func(username string, v ...string) (string, error) {
|
||||
game, _, err := twitch.getRecentStreamInfo(username)
|
||||
game, _, err := twitch.getRecentStreamInfo(strings.TrimLeft(username, "#"))
|
||||
if err != nil && len(v) > 0 {
|
||||
return v[0], nil
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ There are certain variables available in the strings with templating enabled:
|
|||
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
|
||||
- `channelCounter <counter name>` - Wraps the counter name into a channel specific counter name including the channel name
|
||||
- `counterValue <counter name>` - Returns the current value of the counter which identifier was supplied
|
||||
- `fixUsername <username>` - Ensures the username no longer contains the `@` prefix
|
||||
- `group <idx>` - Gets matching group specified by index from `match_message` regular expression
|
||||
|
@ -80,8 +81,8 @@ Additionally there are some functions available in the templates:
|
|||
|
||||
```yaml
|
||||
- actions:
|
||||
- counter: '{{ recentGame "mychannel" }}'
|
||||
- respond: 'I already died {{ counterValue (recentGame "mychannel") }} times in {{ recentGame "mychannel" }}'
|
||||
- counter: '{{ channelCounter (recentGame .channel) }}'
|
||||
- respond: 'I already died {{ counterValue (channelCounter (recentGame .channel)) }} times in {{ recentGame .channel }}'
|
||||
cooldown: 60s
|
||||
enable_on: [broadcaster, moderator]
|
||||
match_channels: ['#mychannel']
|
||||
|
|
Loading…
Reference in a new issue