Add DisableOnMatchMessages functionality

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-12-22 01:46:37 +01:00
parent 38c5b1ef4c
commit 6e4af652b9
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -35,11 +35,14 @@ type rule struct {
MatchEvent *string `yaml:"match_event"`
MatchMessage *string `yaml:"match_message"`
DisableOnMatchMessages []string `yaml:"disable_on_match_messages"`
DisableOnPermit bool `yaml:"disable_on_permit"`
DisableOn []string `yaml:"disable_on"`
EnableOn []string `yaml:"enable_on"`
matchMessage *regexp.Regexp
matchMessage *regexp.Regexp
disableOnMatchMessages []*regexp.Regexp
}
func (r rule) MatcherID() string {
@ -102,6 +105,28 @@ func (r rule) Matches(m *irc.Message, event *string) bool {
}
}
if len(r.DisableOnMatchMessages) > 0 {
// If the regexps were not pre-compiled, do it now
if len(r.disableOnMatchMessages) != len(r.DisableOnMatchMessages) {
r.disableOnMatchMessages = nil
for _, dm := range r.DisableOnMatchMessages {
dmr, err := regexp.Compile(dm)
if err != nil {
logger.WithError(err).Error("Unable to compile expression")
return false
}
r.disableOnMatchMessages = append(r.disableOnMatchMessages, dmr)
}
}
for _, rex := range r.disableOnMatchMessages {
if rex.MatchString(m.Trailing()) {
logger.Trace("Non-Match: Disable-On-Message")
return false
}
}
}
// Check whether user has one of the disable rules
for _, b := range r.DisableOn {
if badges.Has(b) {