5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 14:00:27 +00:00

Move nickformatting into bridge

This commit is contained in:
Wim 2016-08-16 00:08:38 +02:00
parent 889b6debc4
commit e11d786775
4 changed files with 31 additions and 25 deletions

View File

@ -65,7 +65,8 @@ func (b *Bridge) handleReceive(c chan config.Message) {
// do not send to originated bridge // do not send to originated bridge
if br.Name() != msg.Origin { if br.Name() != msg.Origin {
msg.Channel = m[br.Name()] 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 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
}

View File

@ -85,8 +85,7 @@ func (b *Birc) Send(msg config.Message) error {
b.Command(&msg) b.Command(&msg)
return nil return nil
} }
username := b.ircNickFormat(msg.Username) b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
b.i.Privmsg(msg.Channel, username+msg.Text)
return nil 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)) 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 { func (b *Birc) nicksPerRow() int {
if b.Config.Mattermost.NicksPerRow < 1 { if b.Config.Mattermost.NicksPerRow < 1 {
return 4 return 4

View File

@ -95,11 +95,7 @@ func (b *Bmattermost) Name() string {
func (b *Bmattermost) Send(msg config.Message) error { func (b *Bmattermost) Send(msg config.Message) error {
flog.mm.Infof("mattermost send %#v", msg) flog.mm.Infof("mattermost send %#v", msg)
if msg.Origin != "mattermost" { if msg.Origin != "mattermost" {
username := msg.Username + ": " return b.SendType(msg.Username, msg.Text, msg.Channel, "")
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 nil return nil
} }

View File

@ -59,11 +59,7 @@ func (b *Bxmpp) Name() string {
} }
func (b *Bxmpp) Send(msg config.Message) error { func (b *Bxmpp) Send(msg config.Message) error {
username := msg.Username + ": " b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Xmpp.Muc, Text: msg.Username + msg.Text})
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})
return nil return nil
} }
@ -126,7 +122,7 @@ func (b *Bxmpp) handleXmpp() error {
nick = s[1] nick = s[1]
} }
if nick != b.Xmpp.Nick { 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"} b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Origin: "xmpp"}
} }
} }