Changeset 268 in code for trunk/downstream.go


Ignore:
Timestamp:
Apr 24, 2020, 4:26:44 PM (5 years ago)
Author:
delthas
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r262 r268  
    198198        }
    199199        return conn, name, nil
     200}
     201
     202func (dc *downstreamConn) unmarshalText(uc *upstreamConn, text string) string {
     203        if dc.upstream() != nil {
     204                return text
     205        }
     206        // TODO: smarter parsing that ignores URLs
     207        return strings.ReplaceAll(text, "/"+uc.network.GetName(), "")
    200208}
    201209
     
    12341242                        }
    12351243
     1244                        unmarshaledText := text
     1245                        if uc.isChannel(upstreamName) {
     1246                                unmarshaledText = dc.unmarshalText(uc, text)
     1247                        }
    12361248                        uc.SendMessage(&irc.Message{
    12371249                                Command: "PRIVMSG",
    1238                                 Params:  []string{upstreamName, text},
     1250                                Params:  []string{upstreamName, unmarshaledText},
    12391251                        })
    12401252
     
    12621274                        }
    12631275
     1276                        unmarshaledText := text
     1277                        if uc.isChannel(upstreamName) {
     1278                                unmarshaledText = dc.unmarshalText(uc, text)
     1279                        }
    12641280                        uc.SendMessage(&irc.Message{
    12651281                                Command: "NOTICE",
    1266                                 Params:  []string{upstreamName, text},
     1282                                Params:  []string{upstreamName, unmarshaledText},
    12671283                        })
    12681284                }
Note: See TracChangeset for help on using the changeset viewer.