From 14dbc832d72738430af72a9318d9ff6351b93187 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 25 May 2021 17:05:27 +0200 Subject: [PATCH] Allow to disable automessages with templates Signed-off-by: Knut Ahlers --- automessage.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/automessage.go b/automessage.go index 3574e18..d1dae09 100644 --- a/automessage.go +++ b/automessage.go @@ -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" +}