-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_command_privmsg.go
76 lines (67 loc) · 1.53 KB
/
handle_command_privmsg.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
package ircd
import (
"strings"
)
func handlePrivmsg(s *server, c clienter, m message) {
targets := strings.Split(m.params[0], ",")
text := strings.Join(m.params[1:len(m.params)], " ")
for _, target := range targets {
// is channel
if m.isTargetChannel() {
ch, exists := s.Channels.get(target)
if !exists {
c.sendRPL(s.name, errNoSuchChannel{
client: c.nickname(),
channel: target,
})
continue
}
// is user a member of the channel?
if !ch.clients().isMember(c) {
c.sendRPL(s.name, errNotOnChannel{
client: c.nickname(),
channel: ch.name(),
})
continue
}
if ch.hasMode(modeChannelModerated) && !ch.clients().hasMode(
c, modeMemberVoice, modeMemberHalfOperator, modeMemberOperator, modeMemberAdmin, modeMemberOwner) {
c.sendRPL(s.name, errCannotSendToChan{
client: c.nickname(),
channel: ch.name(),
text: "Channel is moderated.",
})
return
}
ch.broadcastCommand(privmsgCommand{
prefix: c.prefix(),
target: ch.name(),
text: text,
}, c.id(), true)
continue
}
// is user
tc, exists := s.Clients.get(target)
if tc == nil || !exists {
c.sendRPL(s.name, errNoSuchChannel{
client: c.nickname(),
channel: target,
})
continue
}
// is away?
if tc.away() != "" {
tc.sendRPL(s.name, rplAway{
client: c.nickname(),
nick: tc.nickname(),
message: tc.away(),
})
}
tc.sendCommand(privmsgCommand{
prefix: c.nickname(),
target: tc.nickname(),
text: text,
})
continue
}
}