From 774872d6557283df9365870d1899a1d762e1f8c1 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 6 Feb 2020 22:45:54 +0100 Subject: [PATCH] Add missing bridge.go, oops --- bridge.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bridge.go diff --git a/bridge.go b/bridge.go new file mode 100644 index 0000000..d01a2f9 --- /dev/null +++ b/bridge.go @@ -0,0 +1,53 @@ +package jounce + +import ( + "gopkg.in/irc.v3" +) + +func forwardChannel(dc *downstreamConn, ch *upstreamChannel) { + if !ch.complete { + panic("Tried to forward a partial channel") + } + + dc.messages <- &irc.Message{ + Prefix: dc.prefix(), + Command: "JOIN", + Params: []string{ch.Name}, + } + + if ch.Topic != "" { + dc.messages <- &irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_TOPIC, + Params: []string{dc.nick, ch.Name, ch.Topic}, + } + } else { + dc.messages <- &irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_NOTOPIC, + Params: []string{dc.nick, ch.Name, "No topic is set"}, + } + } + + // TODO: rpl_topicwhotime + + // TODO: send multiple members in each message + for nick, membership := range ch.Members { + s := nick + if membership != 0 { + s = string(membership) + nick + } + + dc.messages <- &irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_NAMREPLY, + Params: []string{dc.nick, string(ch.Status), ch.Name, s}, + } + } + + dc.messages <- &irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_ENDOFNAMES, + Params: []string{dc.nick, ch.Name, "End of /NAMES list"}, + } +}