From 70f26a1a5ad431e69e8cdb7a7d83de3aa6bcab6e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 1 May 2020 18:12:47 +0200 Subject: [PATCH] Unify upstream NOTICE and PRIVMSG handling --- upstream.go | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/upstream.go b/upstream.go index 9a47ef9..f12c509 100644 --- a/upstream.go +++ b/upstream.go @@ -277,19 +277,28 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { Params: msg.Params, }) return nil - case "NOTICE": + case "NOTICE", "PRIVMSG": if msg.Prefix == nil { return fmt.Errorf("expected a prefix") } + var entity, text string + if err := parseMessageParams(msg, &entity, &text); err != nil { + return err + } + + if msg.Prefix.Name == serviceNick { + uc.logger.Printf("skipping %v from soju's service: %v", msg.Command, msg) + break + } + if entity == serviceNick { + uc.logger.Printf("skipping %v to soju's service: %v", msg.Command, msg) + break + } + if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message uc.produce("", msg, nil) - } else { // regular user NOTICE - var entity, text string - if err := parseMessageParams(msg, &entity, &text); err != nil { - return err - } - + } else { // regular user NOTICE or PRIVMSG target := entity if target == uc.nick { target = msg.Prefix.Name @@ -1083,30 +1092,6 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { Params: []string{dc.nick, nick, "End of /WHOIS list"}, }) }) - case "PRIVMSG": - if msg.Prefix == nil { - return fmt.Errorf("expected a prefix") - } - - var entity, text string - if err := parseMessageParams(msg, &entity, &text); err != nil { - return err - } - - if msg.Prefix.Name == serviceNick { - uc.logger.Printf("skipping PRIVMSG from soju's service: %v", msg) - break - } - if entity == serviceNick { - uc.logger.Printf("skipping PRIVMSG to soju's service: %v", msg) - break - } - - target := entity - if target == uc.nick { - target = msg.Prefix.Name - } - uc.produce(target, msg, nil) case "INVITE": var nick, channel string if err := parseMessageParams(msg, &nick, &channel); err != nil {