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,7 +13,10 @@ func init() {
msg, err := formatMessage(*r.Respond, m, ruleDef, nil) msg, err := formatMessage(*r.Respond, m, ruleDef, nil)
if err != 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( return errors.Wrap(

View file

@ -177,13 +177,14 @@ func (r *rule) Matches(m *irc.Message, event *string) bool {
} }
type ruleAction struct { type ruleAction struct {
Ban *string `json:"ban" yaml:"ban"` Ban *string `json:"ban" yaml:"ban"`
Command []string `json:"command" yaml:"command"` Command []string `json:"command" yaml:"command"`
CounterStep *int64 `json:"counter_step" yaml:"counter_step"` CounterStep *int64 `json:"counter_step" yaml:"counter_step"`
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"`
Timeout *time.Duration `json:"timeout" yaml:"timeout"` RespondFallback *string `json:"respond_fallback" yaml:"respond_fallback"`
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
} }
func loadConfig(filename string) error { func loadConfig(filename string) error {

View file

@ -30,7 +30,8 @@ rules: # See below for examples
- delete_message: true # Bool, set to true to delete - delete_message: true # Bool, set to true to delete
# 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