-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
70 lines (57 loc) · 1.21 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package irc
import (
"log"
"net"
"os"
"sync"
"github.com/osm/event"
)
type postConnectMessage struct {
target string
message string
}
// Client contains the IRC client
type Client struct {
// Connection and address
conn net.Conn
addr string
// Event hub
hub event.Hub
// Logger
logger *log.Logger
// Quit channel
// Send data on this channel to exit the main loop
quit chan bool
// Client related variables
nick string
user string
realName string
channels []string
version string
currentNick string
currentUser string
currentHost string
postConnectMessages []postConnectMessage
postConnectModes []string
infoMu sync.Mutex
// If this is true, all output will be logged
debug bool
}
// NewClient creates a new IRC client
func NewClient(opts ...Option) *Client {
// Create a new client
c := &Client{
hub: event.NewHub(),
logger: log.New(os.Stdout, "IRC: ", log.LstdFlags),
quit: make(chan bool),
version: "github.com/osm/irc",
}
// Apply all options
for _, opt := range opts {
opt(c)
}
// Attach all core event handlers
c.coreEvents()
// Return the client
return c
}