-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathctcp.go
83 lines (72 loc) · 1.98 KB
/
ctcp.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
72
73
74
75
76
77
78
79
80
81
82
83
package ircchans
import (
"strings"
"fmt"
"time"
)
//CTCP sucks, each client implements it a bit differently
func (n *Network) ctcp() {
exch := make(chan bool, 0)
err := n.Shutdown.Reg(exch)
if err != nil {
return
}
ch := make(chan *IrcMessage)
n.Listen.RegListener("PRIVMSG", "ctcp", ch)
defer n.Listen.DelListener("PRIVMSG", "ctcp")
for !closed(ch) {
var p *IrcMessage
select {
case p = <-ch:
case exit := <-exch:
if exit {
return
}
continue
}
if i := strings.LastIndex(p.Params[1], "\x01"); i > -1 { //FIXME: DCC?
p.Params[1] = strings.Trim(p.Params[1], "\x01")
ctype := p.Params[1]
dst := strings.Split(p.Prefix, "!", 2)[0]
switch {
case ctype == "VERSION":
n.Notice(dst, fmt.Sprintf("\x01VERSION %s\x01", IRCVERSION))
case ctype == "USERINFO":
n.Notice(dst, fmt.Sprintf("\x01USERINFO %s\x01", n.user))
case ctype == "CLIENTINFO":
n.Notice(dst, "\x01CLIENTINFO PING VERSION TIME USERINFO CLIENTINFO FINGER SOURCE\x01")
case ctype[0:4] == "PING":
params := strings.Split(p.Params[1], " ", -1)
if len(params) < 2 {
n.l.Println("Illegal ctcp ping received: No arguments", p)
break
}
n.Notice(dst, fmt.Sprintf("\x01PING %s\x01", strings.Join(params[1:], " ")))
case ctype == "TIME":
n.Notice(dst, fmt.Sprintf("\x01TIME %s\x01", time.LocalTime().String()))
//TODO: ACTION, PAGE?
case ctype == "FINGER":
n.Notice(dst, fmt.Sprintln("\x01FINGER like i'm gonna tell you\x01"))
case ctype == "SOURCE":
n.Notice(dst, fmt.Sprintln("\x01SOURCE https://github.com/soul9/go-irc-chans\x01"))
}
}
}
return
}
func (n *Network) CtcpVersion(target string) {
}
func (n *Network) CtcpUserInfo(target string) {
}
func (n *Network) CtcpClientInfo(target string) {
}
func (n *Network) CtcpPing(target string) {
}
func (n *Network) CtcpTime(target string) {
}
func (n *Network) CtcpFinger(target string) {
}
func (n *Network) CtcpSource(target string) {
}
func (n *Network) CtcpAction(target string) {
}