Move nickformatting into bridge
This commit is contained in:
parent
889b6debc4
commit
e11d786775
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue