Allow to disable automessages with templates

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-05-25 17:05:27 +02:00
parent b6d59045d0
commit 14dbc832d7
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -20,6 +20,8 @@ type autoMessage struct {
Message string `yaml:"message"`
UseAction bool `yaml:"use_action"`
DisableOnTemplate *string `yaml:"disable_on_template"`
Cron string `yaml:"cron"`
MessageInterval int64 `yaml:"message_interval"`
OnlyOnLive bool `yaml:"only_on_live"`
@ -71,6 +73,10 @@ func (a *autoMessage) CanSend() bool {
}
}
if !a.allowExecuteDisableOnTemplate() {
return false
}
return true
}
@ -137,3 +143,20 @@ func (a *autoMessage) Send(c *irc.Client) error {
return nil
}
func (a *autoMessage) allowExecuteDisableOnTemplate() bool {
if a.DisableOnTemplate == nil {
// No match criteria set, does not speak against matching
return true
}
res, err := formatMessage(*a.DisableOnTemplate, nil, nil, map[string]interface{}{
"channel": a.Channel,
})
if err != nil {
// Caused an error, forbid execution
return false
}
return res != "true"
}