diff options
author | Wim <wim@42.be> | 2016-08-16 00:08:38 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-08-20 18:08:57 +0200 |
commit | e11d786775cf64123227a44983067cc463e632f5 (patch) | |
tree | 1c26971dc864a6e0549f2b11964124ecd380261e /bridge/bridge.go | |
parent | 889b6debc4f339975076668b6ab7d85f7dd08922 (diff) | |
download | matterbridge-msglm-e11d786775cf64123227a44983067cc463e632f5.tar.gz matterbridge-msglm-e11d786775cf64123227a44983067cc463e632f5.tar.bz2 matterbridge-msglm-e11d786775cf64123227a44983067cc463e632f5.zip |
Move nickformatting into bridge
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r-- | bridge/bridge.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go index 2a9ea7c7..8b89097c 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -65,7 +65,8 @@ func (b *Bridge) handleReceive(c chan config.Message) { // do not send to originated bridge if br.Name() != msg.Origin { msg.Channel = m[br.Name()] - br.Send(msg) + msgmod := b.modifyMessage(msg, br.Name()) + br.Send(msgmod) } } } @@ -109,3 +110,28 @@ func (b *Bridge) ignoreMessage(nick string, message string, protocol string) boo } return false } + +func setNoNickFormat(msg *config.Message) { + msg.Username = msg.Origin + "-" + msg.Username + ": " +} + +func setNickFormat(msg *config.Message, format string) { + if format == "" { + setNoNickFormat(msg) + return + } + msg.Username = strings.Replace(format, "{NICK}", msg.Username, -1) + msg.Username = strings.Replace(msg.Username, "{BRIDGE}", msg.Origin, -1) +} + +func (b *Bridge) modifyMessage(msg config.Message, dest string) config.Message { + switch dest { + case "irc": + setNickFormat(&msg, b.Config.IRC.RemoteNickFormat) + case "xmpp": + setNickFormat(&msg, b.Config.Xmpp.RemoteNickFormat) + case "mattermost": + setNickFormat(&msg, b.Config.Mattermost.RemoteNickFormat) + } + return msg +} |