Move from an ignore handler to hacking the IRC adapter
This commit is contained in:
36
lysenko.go
36
lysenko.go
@@ -8,11 +8,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tcolgate/hugot"
|
||||
"github.com/tcolgate/hugot/adapters/irc"
|
||||
|
||||
irce "github.com/thoj/go-ircevent"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"ur.gs/lysenko/handlers/ignore"
|
||||
"ur.gs/lysenko/adapters/irc"
|
||||
"ur.gs/lysenko/handlers/quotedb"
|
||||
)
|
||||
|
||||
@@ -32,13 +32,6 @@ func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
func buildAdder(mux *hugot.Mux, ignoreList []string) func(next hugot.HearsHandler) {
|
||||
return func(next hugot.HearsHandler) {
|
||||
mux.AddHearsHandler(ignore.NewHears(ignoreList, next))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
ignoreList := strings.Split(*ignores, ",")
|
||||
@@ -55,30 +48,29 @@ func main() {
|
||||
}
|
||||
defer conn.Quit()
|
||||
|
||||
adapter, err := irc.New(conn, ignoreList...)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, channel := range channelList {
|
||||
conn.Join(channel)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
adapter, err := irc.New(conn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
db, err := quotedb.New(*quotes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.DB.Close()
|
||||
|
||||
add := buildAdder(hugot.DefaultMux, ignoreList)
|
||||
add("edb.AddQuoteHandler{QuoteDB: db})
|
||||
add("edb.LastQuoteHandler{QuoteDB: db})
|
||||
add("edb.FindQuoteHandler{QuoteDB: db})
|
||||
add("edb.RandQuoteHandler{QuoteDB: db})
|
||||
add("edb.QuoteHandler{QuoteDB: db})
|
||||
|
||||
go hugot.ListenAndServe(ctx, adapter, hugot.DefaultMux)
|
||||
mux := hugot.DefaultMux
|
||||
mux.AddHearsHandler("edb.AddQuoteHandler{QuoteDB: db})
|
||||
mux.AddHearsHandler("edb.LastQuoteHandler{QuoteDB: db})
|
||||
mux.AddHearsHandler("edb.FindQuoteHandler{QuoteDB: db})
|
||||
mux.AddHearsHandler("edb.RandQuoteHandler{QuoteDB: db})
|
||||
mux.AddHearsHandler("edb.QuoteHandler{QuoteDB: db})
|
||||
|
||||
go hugot.ListenAndServe(ctx, adapter, mux)
|
||||
conn.Loop()
|
||||
}
|
||||
|
Reference in New Issue
Block a user