mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 08:40:01 +00:00
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"`
|
||||
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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue