diff --git a/README.md b/README.md index 0f8bc11..77a465a 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,18 @@ There is some example code that demonstrates usage of the library in `client.go` Synopsis: - import "flag" import irc "github.com/fluffle/goirc/client" func main() { - flag.Parse() // parses the logging flags. - c := irc.Client("nick") - // Optionally, enable SSL - c.SSL = true + // Creating a simple IRC client is simple. + c := irc.SimpleClient("nick") + + // Or, create a config and fiddle with it first: + cfg := irc.NewConfig("nick") + cfg.SSL = true + cfg.Server = "irc.freenode.net:7000" + cfg.NewNick = func(n string) string { return n + "^" } + c := irc.Client(cfg) // Add handlers to do things here! // e.g. join a channel on connect. @@ -31,8 +35,16 @@ Synopsis: c.HandleFunc("disconnected", func(conn *irc.Conn, line *irc.Line) { quit <- true }) - // Tell client to connect - if err := c.Connect("irc.freenode.net"); err != nil { + // Tell client to connect. + if err := c.Connect(); err != nil { + fmt.Printf("Connection error: %s\n", err.String()) + } + + // With a "simple" client, set Server before calling Connect... + c.Config().Server = "irc.freenode.net" + + // ... or, use ConnectTo instead. + if err := c.ConnectTo("irc.freenode.net"); err != nil { fmt.Printf("Connection error: %s\n", err.String()) } diff --git a/client.go b/client.go index 848bd41..7da934f 100644 --- a/client.go +++ b/client.go @@ -16,7 +16,7 @@ func main() { flag.Parse() // create new IRC connection - c := irc.Client("GoTest", "gotest") + c := irc.SimpleClient("GoTest", "gotest") c.EnableStateTracking() c.HandleFunc("connected", func(conn *irc.Conn, line *irc.Line) { conn.Join(*channel) }) @@ -55,10 +55,10 @@ func main() { case cmd[1] == 'f': if len(cmd) > 2 && cmd[2] == 'e' { // enable flooding - c.Flood = true + c.Config().Flood = true } else if len(cmd) > 2 && cmd[2] == 'd' { // disable flooding - c.Flood = false + c.Config().Flood = false } for i := 0; i < 20; i++ { c.Privmsg("#", "flood test!") @@ -81,7 +81,7 @@ func main() { for !reallyquit { // connect to server - if err := c.Connect(*host); err != nil { + if err := c.ConnectTo(*host); err != nil { fmt.Printf("Connection error: %s\n", err) return }