mirror of https://github.com/fluffle/goirc
Update README and example client.
This commit is contained in:
parent
fd6fc1269b
commit
fe4fae0479
26
README.md
26
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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue