From 8c56e610ff0a1655cf2d9a2bfaa96250e573a452 Mon Sep 17 00:00:00 2001 From: delthas Date: Thu, 26 Mar 2020 05:53:13 +0100 Subject: [PATCH] Marshal NOTICE user prefixes and channels NOTICE messages can be both special messages from the server (with no prefix nick), or regular PRIVMSG-like messages from users. This commit adds support for marshaling channel and user prefixes in the latter case. --- upstream.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/upstream.go b/upstream.go index fe8704e..cb5208c 100644 --- a/upstream.go +++ b/upstream.go @@ -204,9 +204,24 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { case "NOTICE": uc.logger.Print(msg) - uc.forEachDownstream(func(dc *downstreamConn) { - dc.SendMessage(msg) - }) + if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message + uc.forEachDownstream(func(dc *downstreamConn) { + dc.SendMessage(msg) + }) + } else { // regular user NOTICE + var nick, text string + if err := parseMessageParams(msg, &nick, &text); err != nil { + return err + } + + uc.forEachDownstream(func(dc *downstreamConn) { + dc.SendMessage(&irc.Message{ + Prefix: dc.marshalUserPrefix(uc, msg.Prefix), + Command: "NOTICE", + Params: []string{dc.marshalEntity(uc, nick), text}, + }) + }) + } case "CAP": var subCmd string if err := parseMessageParams(msg, nil, &subCmd); err != nil {