Add DisableOnMatchMessages functionality
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
38c5b1ef4c
commit
6e4af652b9
1 changed files with 26 additions and 1 deletions
27
config.go
27
config.go
|
@ -35,11 +35,14 @@ type rule struct {
|
||||||
MatchEvent *string `yaml:"match_event"`
|
MatchEvent *string `yaml:"match_event"`
|
||||||
MatchMessage *string `yaml:"match_message"`
|
MatchMessage *string `yaml:"match_message"`
|
||||||
|
|
||||||
|
DisableOnMatchMessages []string `yaml:"disable_on_match_messages"`
|
||||||
|
|
||||||
DisableOnPermit bool `yaml:"disable_on_permit"`
|
DisableOnPermit bool `yaml:"disable_on_permit"`
|
||||||
DisableOn []string `yaml:"disable_on"`
|
DisableOn []string `yaml:"disable_on"`
|
||||||
EnableOn []string `yaml:"enable_on"`
|
EnableOn []string `yaml:"enable_on"`
|
||||||
|
|
||||||
matchMessage *regexp.Regexp
|
matchMessage *regexp.Regexp
|
||||||
|
disableOnMatchMessages []*regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r rule) MatcherID() string {
|
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
|
// Check whether user has one of the disable rules
|
||||||
for _, b := range r.DisableOn {
|
for _, b := range r.DisableOn {
|
||||||
if badges.Has(b) {
|
if badges.Has(b) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue