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)
|
||||||
|
}
|
16
lysenko.go
16
lysenko.go
@@ -16,11 +16,13 @@ import (
|
|||||||
|
|
||||||
"ur.gs/lysenko/adapters"
|
"ur.gs/lysenko/adapters"
|
||||||
"ur.gs/lysenko/handlers/deadline"
|
"ur.gs/lysenko/handlers/deadline"
|
||||||
|
"ur.gs/lysenko/handlers/ignore"
|
||||||
"ur.gs/lysenko/handlers/quotedb"
|
"ur.gs/lysenko/handlers/quotedb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
channels = flag.String("channels", "##testing,##test", "Channels to join (separated by comma)")
|
channels = flag.String("channels", "##testing,##test", "Channels to join (separated by comma)")
|
||||||
|
ignores = flag.String("ignore", "", "Nicks to ignore (separated by comma)")
|
||||||
cooldown = flag.Int("cooldown", 120, "Command rate-limit, in seconds")
|
cooldown = flag.Int("cooldown", 120, "Command rate-limit, in seconds")
|
||||||
host = flag.String("host", "chat.freenode.net", "Server host[:port]")
|
host = flag.String("host", "chat.freenode.net", "Server host[:port]")
|
||||||
ident = flag.String("ident", "lysenko", "Lysenko Bot")
|
ident = flag.String("ident", "lysenko", "Lysenko Bot")
|
||||||
@@ -59,6 +61,10 @@ func ircAdapter() hugot.Adapter {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
var ignoresList []string
|
||||||
|
if *ignores != "" {
|
||||||
|
ignoresList = strings.Split(*ignores, ",")
|
||||||
|
}
|
||||||
|
|
||||||
adapter := adapters.NewPrefixAdapter(ircAdapter(), "!")
|
adapter := adapters.NewPrefixAdapter(ircAdapter(), "!")
|
||||||
adapter.PrivateHelpOnly = true
|
adapter.PrivateHelpOnly = true
|
||||||
@@ -75,11 +81,11 @@ func main() {
|
|||||||
deadline.Cooldown = time.Second * time.Duration(*cooldown)
|
deadline.Cooldown = time.Second * time.Duration(*cooldown)
|
||||||
|
|
||||||
mux := hugot.DefaultMux
|
mux := hugot.DefaultMux
|
||||||
mux.HandleHears("edb.AddQuoteHandler{QuoteDB: db})
|
mux.HandleHears(ignore.NewHears("edb.AddQuoteHandler{QuoteDB: db}, ignoresList...))
|
||||||
mux.HandleHears(deadline.NewHears("edb.LastQuoteHandler{QuoteDB: db}))
|
mux.HandleHears(ignore.NewHears(deadline.NewHears("edb.LastQuoteHandler{QuoteDB: db}), ignoresList...))
|
||||||
mux.HandleHears(deadline.NewHears("edb.FindQuoteHandler{QuoteDB: db}))
|
mux.HandleHears(ignore.NewHears(deadline.NewHears("edb.FindQuoteHandler{QuoteDB: db}), ignoresList...))
|
||||||
mux.HandleHears(deadline.NewHears("edb.RandQuoteHandler{QuoteDB: db}))
|
mux.HandleHears(ignore.NewHears(deadline.NewHears("edb.RandQuoteHandler{QuoteDB: db}), ignoresList...))
|
||||||
mux.HandleHears(deadline.NewHears("edb.QuoteHandler{QuoteDB: db}))
|
mux.HandleHears(ignore.NewHears(deadline.NewHears("edb.QuoteHandler{QuoteDB: db}), ignoresList...))
|
||||||
|
|
||||||
hugot.ListenAndServe(ctx, mux, adapter)
|
hugot.ListenAndServe(ctx, mux, adapter)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user