mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 00:21:16 +00:00
Add fallback text for failed respond templates
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ffe81d3358
commit
2a1b8d2a6c
3 changed files with 14 additions and 9 deletions
|
@ -13,7 +13,10 @@ func init() {
|
|||
|
||||
msg, err := formatMessage(*r.Respond, m, ruleDef, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "preparing response")
|
||||
if r.RespondFallback == nil {
|
||||
return errors.Wrap(err, "preparing response")
|
||||
}
|
||||
msg = *r.RespondFallback
|
||||
}
|
||||
|
||||
return errors.Wrap(
|
||||
|
|
15
config.go
15
config.go
|
@ -177,13 +177,14 @@ func (r *rule) Matches(m *irc.Message, event *string) bool {
|
|||
}
|
||||
|
||||
type ruleAction struct {
|
||||
Ban *string `json:"ban" yaml:"ban"`
|
||||
Command []string `json:"command" yaml:"command"`
|
||||
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"`
|
||||
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
|
||||
Ban *string `json:"ban" yaml:"ban"`
|
||||
Command []string `json:"command" yaml:"command"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func loadConfig(filename string) error {
|
||||
|
|
|
@ -30,7 +30,8 @@ rules: # See below for examples
|
|||
- delete_message: true # Bool, set to true to delete
|
||||
|
||||
# Send responding message to the channel the original message was received in
|
||||
- respond: 'Hello chatter' # String, applies templating
|
||||
- respond: 'Hello chatter' # String, applies templating
|
||||
respond_fallback: 'Oh noes' # String, text to send if the template function causes an error (default: unset)
|
||||
|
||||
# Issue a timeout on the user who wrote the chat-line
|
||||
- timeout: 1s # Duration value: 1s / 1m / 1h
|
||||
|
|
Loading…
Reference in a new issue