soju/bridge.go

56 lines
1.2 KiB
Go
Raw Normal View History

2020-03-13 17:13:03 +00:00
package soju
2020-02-06 21:45:54 +00:00
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)
dc.SendMessage(&irc.Message{
2020-02-06 21:45:54 +00:00
Prefix: dc.prefix(),
Command: "JOIN",
Params: []string{downstreamName},
})
2020-02-06 21:45:54 +00:00
if ch.Topic != "" {
dc.SendMessage(&irc.Message{
2020-02-06 21:45:54 +00:00
Prefix: dc.srv.prefix(),
Command: irc.RPL_TOPIC,
Params: []string{dc.nick, downstreamName, ch.Topic},
})
2020-02-06 21:45:54 +00:00
} else {
dc.SendMessage(&irc.Message{
2020-02-06 21:45:54 +00:00
Prefix: dc.srv.prefix(),
Command: irc.RPL_NOTOPIC,
Params: []string{dc.nick, downstreamName, "No topic is set"},
})
2020-02-06 21:45:54 +00:00
}
// TODO: rpl_topicwhotime
// TODO: send multiple members in each message
for nick, membership := range ch.Members {
s := dc.marshalNick(ch.conn, nick)
2020-02-06 21:45:54 +00:00
if membership != 0 {
s = string(membership) + s
2020-02-06 21:45:54 +00:00
}
dc.SendMessage(&irc.Message{
2020-02-06 21:45:54 +00:00
Prefix: dc.srv.prefix(),
Command: irc.RPL_NAMREPLY,
Params: []string{dc.nick, string(ch.Status), downstreamName, s},
})
2020-02-06 21:45:54 +00:00
}
dc.SendMessage(&irc.Message{
2020-02-06 21:45:54 +00:00
Prefix: dc.srv.prefix(),
Command: irc.RPL_ENDOFNAMES,
Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
})
2020-02-06 21:45:54 +00:00
}