Unmarshal nicks in texts of PRIVMSG and NOTICE from downstreams
When writing a PRIVMSG or NOTICE on a channel, it is very common to use autocompletion to mention other users on that channel. When using soju in multi-network mode, all users will have their nicked suffixed by `/network`. This suffix should be removed before sending it upstream. This adds support for removing all `/network` suffixes in messages sent to a channel of that network.
This commit is contained in:
parent
276ce12e7c
commit
19854b7ec7
@ -199,6 +199,14 @@ func (dc *downstreamConn) unmarshalEntity(name string) (*upstreamConn, string, e
|
|||||||
return conn, name, nil
|
return conn, name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *downstreamConn) unmarshalText(uc *upstreamConn, text string) string {
|
||||||
|
if dc.upstream() != nil {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
// TODO: smarter parsing that ignores URLs
|
||||||
|
return strings.ReplaceAll(text, "/"+uc.network.GetName(), "")
|
||||||
|
}
|
||||||
|
|
||||||
func (dc *downstreamConn) readMessages(ch chan<- event) error {
|
func (dc *downstreamConn) readMessages(ch chan<- event) error {
|
||||||
for {
|
for {
|
||||||
msg, err := dc.ReadMessage()
|
msg, err := dc.ReadMessage()
|
||||||
@ -1233,9 +1241,13 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
|||||||
dc.handleNickServPRIVMSG(uc, text)
|
dc.handleNickServPRIVMSG(uc, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unmarshaledText := text
|
||||||
|
if uc.isChannel(upstreamName) {
|
||||||
|
unmarshaledText = dc.unmarshalText(uc, text)
|
||||||
|
}
|
||||||
uc.SendMessage(&irc.Message{
|
uc.SendMessage(&irc.Message{
|
||||||
Command: "PRIVMSG",
|
Command: "PRIVMSG",
|
||||||
Params: []string{upstreamName, text},
|
Params: []string{upstreamName, unmarshaledText},
|
||||||
})
|
})
|
||||||
|
|
||||||
echoMsg := &irc.Message{
|
echoMsg := &irc.Message{
|
||||||
@ -1261,9 +1273,13 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unmarshaledText := text
|
||||||
|
if uc.isChannel(upstreamName) {
|
||||||
|
unmarshaledText = dc.unmarshalText(uc, text)
|
||||||
|
}
|
||||||
uc.SendMessage(&irc.Message{
|
uc.SendMessage(&irc.Message{
|
||||||
Command: "NOTICE",
|
Command: "NOTICE",
|
||||||
Params: []string{upstreamName, text},
|
Params: []string{upstreamName, unmarshaledText},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case "INVITE":
|
case "INVITE":
|
||||||
|
Loading…
Reference in New Issue
Block a user