Update README and example client.

This commit is contained in:
Alex Bramley 2013-02-18 01:53:17 +00:00
parent fd6fc1269b
commit fe4fae0479
2 changed files with 23 additions and 11 deletions

View File

@ -13,14 +13,18 @@ There is some example code that demonstrates usage of the library in `client.go`
Synopsis: Synopsis:
import "flag"
import irc "github.com/fluffle/goirc/client" import irc "github.com/fluffle/goirc/client"
func main() { func main() {
flag.Parse() // parses the logging flags. // Creating a simple IRC client is simple.
c := irc.Client("nick") c := irc.SimpleClient("nick")
// Optionally, enable SSL
c.SSL = true // 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! // Add handlers to do things here!
// e.g. join a channel on connect. // e.g. join a channel on connect.
@ -31,8 +35,16 @@ Synopsis:
c.HandleFunc("disconnected", c.HandleFunc("disconnected",
func(conn *irc.Conn, line *irc.Line) { quit <- true }) func(conn *irc.Conn, line *irc.Line) { quit <- true })
// Tell client to connect // Tell client to connect.
if err := c.Connect("irc.freenode.net"); err != nil { 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()) fmt.Printf("Connection error: %s\n", err.String())
} }

View File

@ -16,7 +16,7 @@ func main() {
flag.Parse() flag.Parse()
// create new IRC connection // create new IRC connection
c := irc.Client("GoTest", "gotest") c := irc.SimpleClient("GoTest", "gotest")
c.EnableStateTracking() c.EnableStateTracking()
c.HandleFunc("connected", c.HandleFunc("connected",
func(conn *irc.Conn, line *irc.Line) { conn.Join(*channel) }) func(conn *irc.Conn, line *irc.Line) { conn.Join(*channel) })
@ -55,10 +55,10 @@ func main() {
case cmd[1] == 'f': case cmd[1] == 'f':
if len(cmd) > 2 && cmd[2] == 'e' { if len(cmd) > 2 && cmd[2] == 'e' {
// enable flooding // enable flooding
c.Flood = true c.Config().Flood = true
} else if len(cmd) > 2 && cmd[2] == 'd' { } else if len(cmd) > 2 && cmd[2] == 'd' {
// disable flooding // disable flooding
c.Flood = false c.Config().Flood = false
} }
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
c.Privmsg("#", "flood test!") c.Privmsg("#", "flood test!")
@ -81,7 +81,7 @@ func main() {
for !reallyquit { for !reallyquit {
// connect to server // connect to server
if err := c.Connect(*host); err != nil { if err := c.ConnectTo(*host); err != nil {
fmt.Printf("Connection error: %s\n", err) fmt.Printf("Connection error: %s\n", err)
return return
} }