Add NOTICE messages to ring buffer

References: https://todo.sr.ht/~emersion/soju/33
This commit is contained in:
Simon Ser 2020-04-03 21:00:19 +02:00
parent 3d142cae9f
commit ee8aae7a96
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 13 additions and 26 deletions

View File

@ -720,11 +720,11 @@ func (dc *downstreamConn) runNetwork(net *network, loadHistory bool) {
msg = msg.Copy() msg = msg.Copy()
switch msg.Command { switch msg.Command {
case "PRIVMSG": case "PRIVMSG", "NOTICE":
msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix) msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix)
msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) msg.Params[0] = dc.marshalEntity(uc, msg.Params[0])
default: default:
panic("expected to consume a PRIVMSG message") panic(fmt.Sprintf("unexpected %q message", msg.Command))
} }
dc.SendMessage(msg) dc.SendMessage(msg)

View File

@ -257,34 +257,21 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
}) })
return nil return nil
case "NOTICE": case "NOTICE":
uc.logger.Print(msg)
if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message
uc.forEachDownstream(func(dc *downstreamConn) { uc.network.ring.Produce(msg)
dc.SendMessage(&irc.Message{
Command: "NOTICE",
Params: msg.Params,
})
})
} else { // regular user NOTICE } else { // regular user NOTICE
var nick, text string var entity, text string
if err := parseMessageParams(msg, &nick, &text); err != nil { if err := parseMessageParams(msg, &entity, &text); err != nil {
return err return err
} }
target := nick target := entity
if nick == uc.nick { if target == uc.nick {
target = msg.Prefix.Name target = msg.Prefix.Name
} }
uc.appendLog(target, msg) uc.appendLog(target, msg)
uc.forEachDownstream(func(dc *downstreamConn) { uc.network.ring.Produce(msg)
dc.SendMessage(&irc.Message{
Prefix: dc.marshalUserPrefix(uc, msg.Prefix),
Command: "NOTICE",
Params: []string{dc.marshalEntity(uc, nick), text},
})
})
} }
case "CAP": case "CAP":
var subCmd string var subCmd string
@ -1139,8 +1126,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
return fmt.Errorf("expected a prefix") return fmt.Errorf("expected a prefix")
} }
var nick, text string var entity, text string
if err := parseMessageParams(msg, &nick, &text); err != nil { if err := parseMessageParams(msg, &entity, &text); err != nil {
return err return err
} }
@ -1148,13 +1135,13 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
uc.logger.Printf("skipping PRIVMSG from soju's service: %v", msg) uc.logger.Printf("skipping PRIVMSG from soju's service: %v", msg)
break break
} }
if nick == serviceNick { if entity == serviceNick {
uc.logger.Printf("skipping PRIVMSG to soju's service: %v", msg) uc.logger.Printf("skipping PRIVMSG to soju's service: %v", msg)
break break
} }
target := nick target := entity
if nick == uc.nick { if target == uc.nick {
target = msg.Prefix.Name target = msg.Prefix.Name
} }
uc.appendLog(target, msg) uc.appendLog(target, msg)