-
Notifications
You must be signed in to change notification settings - Fork 2
/
irc.go
66 lines (55 loc) · 1.19 KB
/
irc.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
package main
import (
//"crypto/tls"
"fmt"
"log"
"strings"
"time"
"github.com/quiteawful/qairc"
)
// StartIrc handles all irc messages and sends them to the parser
func StartIrc() {
ctxIrc = qairc.QAIrc(*cfgNick, *cfgNick)
ctxIrc.Address = *cfgNetwork + ":" + *cfgPort
ctxIrc.UseTLS = false
//ctxIrc.TLSCfg = &tls.Config{InsecureSkipVerify: true}
err := ctxIrc.Run()
if err != nil {
log.Println(err.Error())
return
}
for {
m, status := <-ctxIrc.Out
if !status {
ctxIrc.Reconnect()
}
if m.Type == "001" {
ctxIrc.Join(*cfgChannel)
}
if m.Type == "PRIVMSG" {
l := len(m.Args)
msg := m.Args[l-1]
// change the sender.nick to the fist word, when
// qabot answers from telegram
user := m.Sender.Nick
if m.Sender.Nick == "qabot" || strings.Contains(m.Sender.Nick, "bot") {
tmp := strings.Split(msg, ":")
if len(tmp) > 1 {
user = tmp[0]
}
}
p := &Post{
User: user,
Message: msg,
Timestamp: time.Now().Local(),
}
postReceiver <- p
}
}
}
func ircMessage(channel, msg string) {
m := fmt.Sprintf("PRIVMSG %s :%s\r\n", channel, msg)
// PRIVMSG #test :Voting time is 600 seconds.
log.Println(m)
ctxIrc.In <- m
}