mirror of https://github.com/fluffle/goirc
Resolve merge conflicts
This commit is contained in:
parent
6277eb6e2d
commit
7481baa454
81
README.md
81
README.md
|
@ -15,54 +15,55 @@ old `go1` API.
|
|||
### Using the framework
|
||||
|
||||
Synopsis:
|
||||
```go
|
||||
package main
|
||||
|
||||
package main
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
irc "github.com/fluffle/goirc/client"
|
||||
)
|
||||
|
||||
irc "github.com/fluffle/goirc/client"
|
||||
)
|
||||
func main() {
|
||||
// Creating a simple IRC client is simple.
|
||||
c := irc.SimpleClient("nick")
|
||||
|
||||
func main() {
|
||||
// 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.SSLConfig = &tls.Config{ServerName: "irc.freenode.net"}
|
||||
cfg.Server = "irc.freenode.net:7000"
|
||||
cfg.NewNick = func(n string) string { return n + "^" }
|
||||
c = irc.Client(cfg)
|
||||
|
||||
// Or, create a config and fiddle with it first:
|
||||
cfg := irc.NewConfig("nick")
|
||||
cfg.SSL = true
|
||||
cfg.SSLConfig = &tls.Config{ServerName: "irc.freenode.net"}
|
||||
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.
|
||||
c.HandleFunc(irc.CONNECTED,
|
||||
func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
|
||||
// And a signal on disconnect
|
||||
quit := make(chan bool)
|
||||
c.HandleFunc(irc.DISCONNECTED,
|
||||
func(conn *irc.Conn, line *irc.Line) { quit <- true })
|
||||
|
||||
// Add handlers to do things here!
|
||||
// e.g. join a channel on connect.
|
||||
c.HandleFunc(irc.CONNECTED,
|
||||
func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
|
||||
// And a signal on disconnect
|
||||
quit := make(chan bool)
|
||||
c.HandleFunc(irc.DISCONNECTED,
|
||||
func(conn *irc.Conn, line *irc.Line) { quit <- true })
|
||||
|
||||
// Tell client to connect.
|
||||
if err := c.Connect(); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err.Error())
|
||||
}
|
||||
|
||||
// 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.Error())
|
||||
}
|
||||
|
||||
// Wait for disconnect
|
||||
<-quit
|
||||
// Tell client to connect.
|
||||
if err := c.Connect(); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err.Error())
|
||||
}
|
||||
|
||||
// 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.Error())
|
||||
}
|
||||
|
||||
// Wait for disconnect
|
||||
<-quit
|
||||
}
|
||||
```
|
||||
|
||||
The test client provides a good (if basic) example of how to use the framework.
|
||||
Reading `client/handlers.go` gives a more in-depth look at how handlers can be
|
||||
written. Commands to be sent to the server (e.g. PRIVMSG) are methods of the
|
||||
|
|
Loading…
Reference in New Issue