-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_command_topic.go
50 lines (42 loc) · 966 Bytes
/
handle_command_topic.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
package ircd
import (
"strings"
)
func handleTopic(s *server, c clienter, m message) {
target := m.params[0]
if !m.isTargetChannel() {
c.sendRPL(s.name, errNoSuchChannel{
client: c.nickname(),
channel: target,
})
return
}
ch, exists := s.Channels.get(target)
if !exists {
c.sendRPL(s.name, errNoSuchChannel{
client: c.nickname(),
channel: target,
})
return
}
if ch.hasMode(modeChannelRestrictTopic) && !ch.clients().hasMode(c, modeMemberHalfOperator, modeMemberOperator, modeMemberAdmin, modeMemberOwner) {
c.sendRPL(s.name, errChanoPrivsNeeded{
client: c.nickname(),
channel: ch.name(),
})
return
}
// set topic
text := strings.Join(m.params[1:len(m.params)], " ")
ch.setTopic(text, c.nickname())
// get topic
topic := ch.topic()
// broadcast new topic to clients on channel
ch.broadcastRPL(
rplTopic{
client: c.nickname(),
channel: ch.name(),
topic: topic.text,
}, c.id(), false,
)
}