2012-08-17 20:38:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2012-08-17 22:17:39 +00:00
|
|
|
"bitbucket.org/phlyingpenguin/godeepintir/bot"
|
|
|
|
"bitbucket.org/phlyingpenguin/godeepintir/config"
|
|
|
|
"bitbucket.org/phlyingpenguin/godeepintir/plugins"
|
2012-08-17 22:56:44 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2012-08-17 20:38:15 +00:00
|
|
|
)
|
|
|
|
import irc "github.com/fluffle/goirc/client"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
// These belong in the JSON file
|
|
|
|
// var server = flag.String("server", "irc.freenode.net", "Server to connect to.")
|
|
|
|
// var nick = flag.String("nick", "CrappyBot", "Nick to set upon connection.")
|
|
|
|
// var pass = flag.String("pass", "", "IRC server password to use")
|
|
|
|
// var channel = flag.String("channel", "#AlePaleTest", "Channel to connet to.")
|
|
|
|
|
|
|
|
var cfile = flag.String("config", "config.json", "Config file to load. (Defaults to config.json)")
|
|
|
|
flag.Parse() // parses the logging flags.
|
|
|
|
|
2012-08-17 22:56:44 +00:00
|
|
|
config := config.Readconfig(Version, *cfile)
|
2012-08-17 20:38:15 +00:00
|
|
|
|
|
|
|
c := irc.SimpleClient(config.Nick)
|
|
|
|
// Optionally, enable SSL
|
|
|
|
c.SSL = false
|
|
|
|
|
|
|
|
// Add handlers to do things here!
|
|
|
|
// e.g. join a channel on connect.
|
|
|
|
c.AddHandler("connected",
|
2012-08-17 21:37:49 +00:00
|
|
|
func(conn *irc.Conn, line *irc.Line) {
|
2012-08-17 20:38:15 +00:00
|
|
|
for _, channel := range config.Channels {
|
|
|
|
conn.Join(channel)
|
2012-08-25 04:49:48 +00:00
|
|
|
fmt.Printf("Now talking in %s.\n", channel)
|
2012-08-17 20:38:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
// And a signal on disconnect
|
|
|
|
quit := make(chan bool)
|
|
|
|
|
|
|
|
c.AddHandler("disconnected",
|
|
|
|
func(conn *irc.Conn, line *irc.Line) { quit <- true })
|
|
|
|
|
2012-08-17 21:37:49 +00:00
|
|
|
b := bot.NewBot(config, c)
|
2012-08-17 22:09:29 +00:00
|
|
|
// b.AddHandler(plugins.NewTestPlugin(b))
|
2012-08-17 23:22:37 +00:00
|
|
|
b.AddHandler("talker", plugins.NewTalkerPlugin(b))
|
|
|
|
b.AddHandler("beers", plugins.NewBeersPlugin(b))
|
2012-08-20 01:28:25 +00:00
|
|
|
b.AddHandler("remember", plugins.NewRememberPlugin(b))
|
2012-08-26 15:45:04 +00:00
|
|
|
b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b))
|
2012-08-26 19:14:09 +00:00
|
|
|
// catches anything left, will always return true
|
|
|
|
b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
|
2012-08-17 20:38:15 +00:00
|
|
|
|
2012-08-23 20:28:45 +00:00
|
|
|
c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) {
|
|
|
|
b.MsgRecieved(conn, line)
|
|
|
|
})
|
|
|
|
|
2012-08-25 04:46:13 +00:00
|
|
|
c.AddHandler("JOIN", func(conn *irc.Conn, line *irc.Line) {
|
|
|
|
b.UserJoined(conn, line)
|
|
|
|
})
|
|
|
|
|
2012-08-17 20:38:15 +00:00
|
|
|
c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
|
2012-08-18 01:39:26 +00:00
|
|
|
b.MsgRecieved(conn, line)
|
2012-08-17 20:38:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Tell client to connect
|
|
|
|
if err := c.Connect(config.Server, config.Pass); err != nil {
|
|
|
|
fmt.Printf("Connection error: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for disconnect
|
|
|
|
<-quit
|
|
|
|
}
|