-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
71 lines (58 loc) · 1.79 KB
/
option.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
71
package irc
import (
"log"
"net"
)
// Option should be implemented by all client options
type Option func(*Client)
// WithAddr sets the address of the IRC server, this can be omitted if you supply a connection with WithConn
func WithAddr(addr string) Option {
return func(c *Client) {
c.addr = addr
}
}
// WithChannel sets the channel that the client should join on connect, this can be called mupltiple times
func WithChannel(ch string) Option {
return func(c *Client) {
if ch != "" {
c.channels = append(c.channels, ch)
}
}
}
// WithConn sets the client connection, this can be omitted if you supply an address with WithAddr
func WithConn(conn net.Conn) Option {
return func(c *Client) {
c.conn = conn
c.addr = conn.RemoteAddr().String()
}
}
// WithDebug sets the debug flag, set this if you want to log the communication
func WithDebug() Option {
return func(c *Client) { c.debug = true }
}
// WithLogger sets the logger
func WithLogger(logger *log.Logger) Option {
return func(c *Client) { c.logger = logger }
}
// WithNick sets the nick for the client
func WithNick(n string) Option {
return func(c *Client) { c.nick = n }
}
// WithRealName sets the real name for the client
func WithRealName(r string) Option {
return func(c *Client) { c.realName = r }
}
// WithUser sets the user for the client
func WithUser(u string) Option {
return func(c *Client) { c.user = u }
}
// WithVersion sets the CTCP VERSION reply string
func WithVersion(v string) Option {
return func(c *Client) { c.version = v }
}
func WithPostConnectMessage(t, m string) Option {
return func(c *Client) { c.postConnectMessages = append(c.postConnectMessages, postConnectMessage{t, m}) }
}
func WithPostConnectMode(m string) Option {
return func(c *Client) { c.postConnectModes = append(c.postConnectModes, m) }
}