Unify upstream NOTICE and PRIVMSG handling

This commit is contained in:
Simon Ser 2020-05-01 18:12:47 +02:00
parent aa6f3a9954
commit 70f26a1a5a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -277,19 +277,28 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
Params: msg.Params, Params: msg.Params,
}) })
return nil return nil
case "NOTICE": case "NOTICE", "PRIVMSG":
if msg.Prefix == nil { if msg.Prefix == nil {
return fmt.Errorf("expected a prefix") return fmt.Errorf("expected a prefix")
} }
if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message
uc.produce("", msg, nil)
} else { // regular user NOTICE
var entity, text string var entity, text string
if err := parseMessageParams(msg, &entity, &text); err != nil { if err := parseMessageParams(msg, &entity, &text); err != nil {
return err 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 or PRIVMSG
target := entity target := entity
if target == uc.nick { if target == uc.nick {
target = msg.Prefix.Name 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"}, 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": case "INVITE":
var nick, channel string var nick, channel string
if err := parseMessageParams(msg, &nick, &channel); err != nil { if err := parseMessageParams(msg, &nick, &channel); err != nil {