Add fallback text for failed respond templates

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-01-21 01:00:04 +01:00
parent ffe81d3358
commit 2a1b8d2a6c
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 14 additions and 9 deletions

View file

@ -13,8 +13,11 @@ func init() {
msg, err := formatMessage(*r.Respond, m, ruleDef, nil) msg, err := formatMessage(*r.Respond, m, ruleDef, nil)
if err != nil { if err != nil {
if r.RespondFallback == nil {
return errors.Wrap(err, "preparing response") return errors.Wrap(err, "preparing response")
} }
msg = *r.RespondFallback
}
return errors.Wrap( return errors.Wrap(
c.WriteMessage(&irc.Message{ c.WriteMessage(&irc.Message{

View file

@ -183,6 +183,7 @@ type ruleAction struct {
Counter *string `json:"counter" yaml:"counter"` Counter *string `json:"counter" yaml:"counter"`
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"` DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
Respond *string `json:"respond" yaml:"respond"` Respond *string `json:"respond" yaml:"respond"`
RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
Timeout *time.Duration `json:"timeout" yaml:"timeout"` Timeout *time.Duration `json:"timeout" yaml:"timeout"`
} }

View file

@ -31,6 +31,7 @@ rules: # See below for examples
# Send responding message to the channel the original message was received in # 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 # Issue a timeout on the user who wrote the chat-line
- timeout: 1s # Duration value: 1s / 1m / 1h - timeout: 1s # Duration value: 1s / 1m / 1h