Rework lysenko to use latest hugot, removing go-ircevent
This commit is contained in:
46
lysenko.go
46
lysenko.go
@@ -1,18 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fluffle/goirc/client"
|
||||
"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/deadline"
|
||||
"ur.gs/lysenko/handlers/quotedb"
|
||||
)
|
||||
@@ -34,30 +33,14 @@ func init() {
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
channelList := strings.Split(*channels, ",")
|
||||
config := client.NewConfig(*nick)
|
||||
config.Server = *host
|
||||
config.Pass = *nickserv
|
||||
config.SSL = *ssl
|
||||
adapter := irc.New(config, channelList...)
|
||||
|
||||
conn := irce.IRC(*nick, *ident)
|
||||
conn.UseTLS = *ssl
|
||||
conn.Password = *nickserv
|
||||
conn.Debug = true
|
||||
|
||||
conn.AddCallback("001", func(e *irce.Event) {
|
||||
for _, channel := range channelList {
|
||||
conn.Join(channel)
|
||||
}
|
||||
})
|
||||
|
||||
if err := conn.Connect(*host); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer conn.Quit()
|
||||
|
||||
adapter, err := irc.New(conn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
db, err := quotedb.New(*quotes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -65,12 +48,11 @@ func main() {
|
||||
defer db.DB.Close()
|
||||
|
||||
mux := hugot.DefaultMux
|
||||
mux.AddHearsHandler("edb.AddQuoteHandler{QuoteDB: db})
|
||||
mux.AddHearsHandler(deadline.NewHears("edb.LastQuoteHandler{QuoteDB: db}))
|
||||
mux.AddHearsHandler(deadline.NewHears("edb.FindQuoteHandler{QuoteDB: db}))
|
||||
mux.AddHearsHandler(deadline.NewHears("edb.RandQuoteHandler{QuoteDB: db}))
|
||||
mux.AddHearsHandler(deadline.NewHears("edb.QuoteHandler{QuoteDB: db}))
|
||||
mux.HandleCommand("edb.AddQuoteHandler{QuoteDB: db})
|
||||
mux.HandleCommand(deadline.NewCommand("edb.LastQuoteHandler{QuoteDB: db}))
|
||||
mux.HandleCommand(deadline.NewCommand("edb.FindQuoteHandler{QuoteDB: db}))
|
||||
mux.HandleCommand(deadline.NewCommand("edb.RandQuoteHandler{QuoteDB: db}))
|
||||
mux.HandleCommand(deadline.NewCommand("edb.QuoteHandler{QuoteDB: db}))
|
||||
|
||||
go hugot.ListenAndServe(ctx, adapter, mux)
|
||||
conn.Loop()
|
||||
hugot.ListenAndServe(context.Background(), mux, adapter)
|
||||
}
|
||||
|
Reference in New Issue
Block a user