-
Notifications
You must be signed in to change notification settings - Fork 27
/
auth.go
49 lines (41 loc) · 1.02 KB
/
auth.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
package main
import (
"github.com/thoj/go-ircevent"
"strings"
)
func (i *IRCCat) inChannel(channel string) bool {
return i.channels.Contains(channel)
}
func (i *IRCCat) authorisedUser(nick string) bool {
_, exists := i.auth_users[nick]
return exists
}
func (i *IRCCat) handleJoin(e *irc.Event) {
if e.Arguments[0] == i.auth_channel {
i.auth_users[e.Nick] = true
}
}
func (i *IRCCat) handlePart(e *irc.Event) {
if e.Arguments[0] == i.auth_channel {
delete(i.auth_users, e.Nick)
}
}
func (i *IRCCat) handleQuit(e *irc.Event) {
delete(i.auth_users, e.Nick)
}
func (i *IRCCat) handleNames(e *irc.Event) {
if e.Arguments[2] == i.auth_channel {
nicks := strings.Split(e.Arguments[3], " ")
for _, nick := range nicks {
// TODO: this is probably not an optimal way of trimming the mode characters.
nick = strings.TrimLeft(nick, "@%+")
i.auth_users[nick] = true
}
}
}
func (i *IRCCat) handleNick(e *irc.Event) {
if i.auth_users[e.Nick] {
delete(i.auth_users, e.Nick)
i.auth_users[e.Arguments[0]] = true
}
}