diff options
-rw-r--r-- | bridge/bridge.go | 28 | ||||
-rw-r--r-- | bridge/irc/irc.go | 14 | ||||
-rw-r--r-- | bridge/mattermost/mattermost.go | 6 | ||||
-rw-r--r-- | bridge/xmpp/xmpp.go | 8 |
4 files changed, 31 insertions, 25 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 +} diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 9ed5202b..102efa56 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -85,8 +85,7 @@ func (b *Birc) Send(msg config.Message) error { b.Command(&msg) return nil } - username := b.ircNickFormat(msg.Username) - b.i.Privmsg(msg.Channel, username+msg.Text) + b.i.Privmsg(msg.Channel, msg.Username+msg.Text) return nil } @@ -164,17 +163,6 @@ func (b *Birc) handleTopicWhoTime(event *irc.Event) { flog.irc.Infof("%s: Topic set by %s [%s]", event.Code, user, time.Unix(t, 0)) } -func (b *Birc) ircNickFormat(nick string) string { - flog.irc.Debug("ircnick", nick) - if nick == b.ircNick { - return nick - } - if b.Config.IRC.RemoteNickFormat == "" { - return "irc-" + nick - } - return strings.Replace(b.Config.IRC.RemoteNickFormat, "{NICK}", nick, -1) -} - func (b *Birc) nicksPerRow() int { if b.Config.Mattermost.NicksPerRow < 1 { return 4 diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 9dc0cebb..1371969e 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -95,11 +95,7 @@ func (b *Bmattermost) Name() string { func (b *Bmattermost) Send(msg config.Message) error { flog.mm.Infof("mattermost send %#v", msg) if msg.Origin != "mattermost" { - username := msg.Username + ": " - if b.Config.Mattermost.RemoteNickFormat != "" { - username = strings.Replace(b.Config.Mattermost.RemoteNickFormat, "{NICK}", msg.Username, -1) - } - return b.SendType(username, msg.Text, msg.Channel, "") + return b.SendType(msg.Username, msg.Text, msg.Channel, "") } return nil } diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 5d10f9bd..5d602475 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -59,11 +59,7 @@ func (b *Bxmpp) Name() string { } func (b *Bxmpp) Send(msg config.Message) error { - username := msg.Username + ": " - if b.Config.Xmpp.RemoteNickFormat != "" { - username = strings.Replace(b.Config.Xmpp.RemoteNickFormat, "{NICK}", msg.Username, -1) - } - b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Xmpp.Muc, Text: username + msg.Text}) + b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Xmpp.Muc, Text: msg.Username + msg.Text}) return nil } @@ -126,7 +122,7 @@ func (b *Bxmpp) handleXmpp() error { nick = s[1] } if nick != b.Xmpp.Nick { - flog.xmpp.Info("sending message to remote", nick, v.Text, channel) + flog.xmpp.Infof("sending message to remote %s %s %s", nick, v.Text, channel) b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Origin: "xmpp"} } } |