Initial commit: hugot lysenko
This commit is contained in:
84
lysenko.go
Normal file
84
lysenko.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"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/handlers/quotedb"
|
||||
)
|
||||
|
||||
var (
|
||||
channels = flag.String("channels", "##testing,##test", "Channels to join (separated by comma)")
|
||||
host = flag.String("host", "chat.freenode.net", "Server host[:port]")
|
||||
ident = flag.String("ident", "lysenko", "Lysenko Bot")
|
||||
ignores = flag.String("ignore", "", "nicks to ignore, comma-separated")
|
||||
nick = flag.String("nick", "lysenko", "Lysenko Bot")
|
||||
nickserv = flag.String("nickserv", "", "NickServ password")
|
||||
quotes = flag.String("quotedb", ":memory:", "sqlite3 quote database")
|
||||
ssl = flag.Bool("ssl", true, "Enable SSL")
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: better rand.Seed
|
||||
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, ",")
|
||||
channelList := strings.Split(*channels, ",")
|
||||
|
||||
_ = ignoreList // TODO: use this
|
||||
|
||||
conn := irce.IRC(*nick, *ident)
|
||||
conn.UseTLS = *ssl
|
||||
conn.Password = *nickserv
|
||||
|
||||
if err := conn.Connect(*host); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer conn.Quit()
|
||||
|
||||
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)
|
||||
|
||||
conn.Loop()
|
||||
}
|
Reference in New Issue
Block a user