mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
Add delay-action
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
596f4fad3b
commit
ba63d5f8bd
3 changed files with 57 additions and 9 deletions
24
action_delay.go
Normal file
24
action_delay.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/go-irc/irc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerAction(func(c *irc.Client, m *irc.Message, ruleDef *rule, r *ruleAction) error {
|
||||
if r.Delay == 0 && r.DelayJitter == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
totalDelay := r.Delay
|
||||
if r.DelayJitter > 0 {
|
||||
totalDelay += time.Duration(rand.Int63n(int64(r.DelayJitter)))
|
||||
}
|
||||
|
||||
time.Sleep(totalDelay)
|
||||
return nil
|
||||
})
|
||||
}
|
26
rule.go
26
rule.go
|
@ -250,13 +250,21 @@ func (r *rule) allowExecuteUserWhitelist(logger *log.Entry, m *irc.Message, even
|
|||
}
|
||||
|
||||
type ruleAction struct {
|
||||
Ban *string `json:"ban" yaml:"ban"`
|
||||
Command []string `json:"command" yaml:"command"`
|
||||
CounterSet *string `json:"counter_set" yaml:"counter_set"`
|
||||
CounterStep *int64 `json:"counter_step" yaml:"counter_step"`
|
||||
Counter *string `json:"counter" yaml:"counter"`
|
||||
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
|
||||
Respond *string `json:"respond" yaml:"respond"`
|
||||
RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
|
||||
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
|
||||
Ban *string `json:"ban" yaml:"ban"`
|
||||
|
||||
Command []string `json:"command" yaml:"command"`
|
||||
|
||||
CounterSet *string `json:"counter_set" yaml:"counter_set"`
|
||||
CounterStep *int64 `json:"counter_step" yaml:"counter_step"`
|
||||
Counter *string `json:"counter" yaml:"counter"`
|
||||
|
||||
Delay time.Duration `json:"delay" yaml:"delay"`
|
||||
DelayJitter time.Duration `json:"delay_jitter" yaml:"delay_jitter"`
|
||||
|
||||
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
|
||||
|
||||
Respond *string `json:"respond" yaml:"respond"`
|
||||
RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
|
||||
|
||||
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
|
16
wiki/Home.md
16
wiki/Home.md
|
@ -40,6 +40,10 @@ rules: # See below for examples
|
|||
# applies templating but MUST result in a parseable integer
|
||||
counter_step: 1 # Integer, can be negative or positive, default: +1
|
||||
|
||||
# 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
|
||||
|
||||
# Issue a delete on the message caught
|
||||
- delete_message: true # Bool, set to true to delete
|
||||
|
||||
|
@ -193,6 +197,18 @@ The example was dumped using this action:
|
|||
match_message: '^!followage'
|
||||
```
|
||||
|
||||
### 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'
|
||||
```
|
||||
|
||||
### Send a notification on successful permit
|
||||
|
||||
```yaml
|
||||
|
|
Loading…
Reference in a new issue