/
ircstuff.go
77 lines (70 loc) · 1.82 KB
/
ircstuff.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
package main
import (
"irc"
"fmt"
"strings"
"time"
)
func ircStuff() {
var nick string
var peers []string
type payload struct {
Author string
Text string
Timestamp string
}
irccon := irc.IRC("testgo", "testgo")
irccon.Connect("irc.freenode.net:6667")
irccon.AddCallback("JOIN",func(e *irc.IRCEvent){
fmt.Println(e)
if nick == e.Nick {
go irccon.SendRaw("who #bootstrap")
time.Sleep(5e9)
WritePeers(peers)
go DialRelays()
}
})
irccon.AddCallback("NOTICE",func(e *irc.IRCEvent){
if strings.Contains(e.Message, "PING"){
fmt.Println("received response from",e.Host)
PingResponse <- e.Host
}
})
irccon.AddCallback("311",func(e *irc.IRCEvent){
//irccon.Privmsg("#bootstrap",e.Arguments[3])
})
irccon.AddCallback("352",func(e *irc.IRCEvent){ // who response from server
//irccon.Privmsg("#bootstrap",e.Arguments[3])
peers = append(peers,e.Arguments[3])
fmt.Println("GOT WHO RESPONSE:",e)
//WritePeer(e.Arguments[3])
})
irccon.AddCallback("372",func(e *irc.IRCEvent){
//fmt.Println(e)
})
irccon.AddCallback("353",func(e *irc.IRCEvent){ //channel name list
names := strings.Split(e.Message," ",-1)
fmt.Println(e)
//fmt.Println(e.Message)
for i := range names {
if names[i] != nick {
fmt.Println(names[i])
}
}
})
irccon.AddCallback("001", func(e *irc.IRCEvent) {
irccon.Join("#bootstrap")
fmt.Println(e)
nick = e.Arguments[0]
})
go func(){
for {
v:=<- ircChan
timestamp := time.LocalTime().String()
author := myUsername
payload := `{"author":"`+author+`","text":"`+string(v)+`","timestamp":"`+timestamp+`"}`
msg := `{"type":"newtweet","tweetbody":`+payload+`}`
irccon.Privmsg("#bootstrap",msg)
}
}()
}