Allow to disable automessages with templates
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
b6d59045d0
commit
14dbc832d7
1 changed files with 23 additions and 0 deletions
|
@ -20,6 +20,8 @@ type autoMessage struct {
|
||||||
Message string `yaml:"message"`
|
Message string `yaml:"message"`
|
||||||
UseAction bool `yaml:"use_action"`
|
UseAction bool `yaml:"use_action"`
|
||||||
|
|
||||||
|
DisableOnTemplate *string `yaml:"disable_on_template"`
|
||||||
|
|
||||||
Cron string `yaml:"cron"`
|
Cron string `yaml:"cron"`
|
||||||
MessageInterval int64 `yaml:"message_interval"`
|
MessageInterval int64 `yaml:"message_interval"`
|
||||||
OnlyOnLive bool `yaml:"only_on_live"`
|
OnlyOnLive bool `yaml:"only_on_live"`
|
||||||
|
@ -71,6 +73,10 @@ func (a *autoMessage) CanSend() bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !a.allowExecuteDisableOnTemplate() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,3 +143,20 @@ func (a *autoMessage) Send(c *irc.Client) error {
|
||||||
|
|
||||||
return nil
|
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"
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue