soju/bridge.go
delthas 9ff8429a53
Add downstream NAMES support
NAMES reply for channels currently joined will be returned from cache;
requests for channels not joined will be forwarded from upstream.
2020-03-25 09:47:26 +01:00

53 lines
1.2 KiB
Go

package soju
import (
"gopkg.in/irc.v3"
)
func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
if !ch.complete {
panic("Tried to forward a partial channel")
}
downstreamName := dc.marshalChannel(ch.conn, ch.Name)
if ch.Topic != "" {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_TOPIC,
Params: []string{dc.nick, downstreamName, ch.Topic},
})
} else {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_NOTOPIC,
Params: []string{dc.nick, downstreamName, "No topic is set"},
})
}
// TODO: rpl_topicwhotime
sendNames(dc, ch)
}
func sendNames(dc *downstreamConn, ch *upstreamChannel) {
// TODO: send multiple members in each message
downstreamName := dc.marshalChannel(ch.conn, ch.Name)
for nick, membership := range ch.Members {
s := membership.String() + dc.marshalNick(ch.conn, nick)
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_NAMREPLY,
Params: []string{dc.nick, string(ch.Status), downstreamName, s},
})
}
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFNAMES,
Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
})
}