Allow people to be ignored by nick
This commit is contained in:
34
handlers/ignore/ignore.go
Normal file
34
handlers/ignore/ignore.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package ignore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/tcolgate/hugot"
|
||||
)
|
||||
|
||||
type HearsIgnore struct {
|
||||
hugot.HearsHandler
|
||||
|
||||
Ignore []*regexp.Regexp
|
||||
}
|
||||
|
||||
func NewHears(next hugot.HearsHandler, who ...string) hugot.HearsHandler {
|
||||
var ignoreCompiled []*regexp.Regexp
|
||||
for _, str := range who {
|
||||
ignoreCompiled = append(ignoreCompiled, regexp.MustCompile(str))
|
||||
}
|
||||
|
||||
return &HearsIgnore{HearsHandler: next, Ignore: ignoreCompiled}
|
||||
}
|
||||
|
||||
func (i *HearsIgnore) Heard(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message, matches [][]string) {
|
||||
for _, re := range i.Ignore {
|
||||
if re.MatchString(m.From) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
i.HearsHandler.Heard(ctx, w, m, matches)
|
||||
}
|
Reference in New Issue
Block a user