diff options
author | JeremyRand <jeremyrand@airmail.cc> | 2020-11-25 22:54:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 23:54:27 +0100 |
commit | c3bcbd63c012f57fa81832cf4b2812dcd15c8a8f (patch) | |
tree | 1f12271d13fda2a8aee90ae38e129e6c9265606f /gateway/gateway.go | |
parent | 29e29439ee0f10f4485b699633e05da6bcc9e3ce (diff) | |
download | matterbridge-msglm-c3bcbd63c012f57fa81832cf4b2812dcd15c8a8f.tar.gz matterbridge-msglm-c3bcbd63c012f57fa81832cf4b2812dcd15c8a8f.tar.bz2 matterbridge-msglm-c3bcbd63c012f57fa81832cf4b2812dcd15c8a8f.zip |
Add UserID to RemoteNickFormat and Tengo (#1308)
* Add UserID to RemoteNickFormat and Tengo
* Use strings.ReplaceAll in gateway.modifyUsername
Fixes a warning from gocritic linter.
* Use Unicode escape sequence instead of raw ZWSP in gateway.modifyUsername
Fixes a warning from stylecheck linter.
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r-- | gateway/gateway.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index 1508ced2..eb530afd 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -337,20 +337,21 @@ func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) stri } i++ } - nick = strings.Replace(nick, "{NOPINGNICK}", msg.Username[:i]+""+msg.Username[i:], -1) + nick = strings.ReplaceAll(nick, "{NOPINGNICK}", msg.Username[:i]+"\u200b"+msg.Username[i:]) } - nick = strings.Replace(nick, "{BRIDGE}", br.Name, -1) - nick = strings.Replace(nick, "{PROTOCOL}", br.Protocol, -1) - nick = strings.Replace(nick, "{GATEWAY}", gw.Name, -1) - nick = strings.Replace(nick, "{LABEL}", br.GetString("Label"), -1) - nick = strings.Replace(nick, "{NICK}", msg.Username, -1) - nick = strings.Replace(nick, "{CHANNEL}", msg.Channel, -1) + nick = strings.ReplaceAll(nick, "{BRIDGE}", br.Name) + nick = strings.ReplaceAll(nick, "{PROTOCOL}", br.Protocol) + nick = strings.ReplaceAll(nick, "{GATEWAY}", gw.Name) + nick = strings.ReplaceAll(nick, "{LABEL}", br.GetString("Label")) + nick = strings.ReplaceAll(nick, "{NICK}", msg.Username) + nick = strings.ReplaceAll(nick, "{USERID}", msg.UserID) + nick = strings.ReplaceAll(nick, "{CHANNEL}", msg.Channel) tengoNick, err := gw.modifyUsernameTengo(msg, br) if err != nil { gw.logger.Errorf("modifyUsernameTengo error: %s", err) } - nick = strings.Replace(nick, "{TENGO}", tengoNick, -1) //nolint:gocritic + nick = strings.ReplaceAll(nick, "{TENGO}", tengoNick) return nick } @@ -549,6 +550,7 @@ func modifyInMessageTengo(filename string, msg *config.Message) error { s.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...)) _ = s.Add("msgText", msg.Text) _ = s.Add("msgUsername", msg.Username) + _ = s.Add("msgUserID", msg.UserID) _ = s.Add("msgAccount", msg.Account) _ = s.Add("msgChannel", msg.Channel) c, err := s.Compile() @@ -577,6 +579,7 @@ func (gw *Gateway) modifyUsernameTengo(msg *config.Message, br *bridge.Bridge) ( _ = s.Add("result", "") _ = s.Add("msgText", msg.Text) _ = s.Add("msgUsername", msg.Username) + _ = s.Add("msgUserID", msg.UserID) _ = s.Add("nick", msg.Username) _ = s.Add("msgAccount", msg.Account) _ = s.Add("msgChannel", msg.Channel) @@ -631,6 +634,7 @@ func (gw *Gateway) modifyOutMessageTengo(origmsg *config.Message, msg *config.Me _ = s.Add("outEvent", msg.Event) _ = s.Add("msgText", msg.Text) _ = s.Add("msgUsername", msg.Username) + _ = s.Add("msgUserID", msg.UserID) _ = s.Add("msgDrop", drop) c, err := s.Compile() if err != nil { |