Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit deaa885eeaf9701bccbf2551ee373608ec7ec43e Merge: 291f1bc 5131ecc Author: Wim <wim@42.be> Date: Sun Nov 13 23:09:06 2016 +0000 Merge branch 'refactor' diff --cc gateway/samechannel/samechannel.go index 2240ee8,23c4152..47dfeb9 --- a/gateway/samechannel/samechannel.go +++ b/gateway/samechannel/samechannel.go @@@ -53,51 -54,24 +54,37 @@@ func (gw *SameChannelGateway) handleRec   }   }    -func (gw *SameChannelGateway) handleMessage(msg config.Message, dest *bridge.Bridge) {  +func (gw *SameChannelGateway) handleMessage(msg config.Message, dest bridge.Bridge) {  + // is this a configured channel  + if !gw.validChannel(msg.Channel) {  + return  + }   // do not send the message to the bridge we come from if also the channel is the same - if msg.FullOrigin == dest.FullOrigin() { + if msg.Account == dest.Account {   return   } - gw.modifyMessage(&msg, dest) - log.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.FullOrigin, msg.Channel, dest.FullOrigin(), msg.Channel) + gw.modifyUsername(&msg, dest)  - log.Debugf("Sending %#v from %s to %s", msg, msg.Account, dest.Account) ++ log.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, msg.Channel, dest.Account, msg.Channel)   err := dest.Send(msg)   if err != nil {   log.Error(err)   }   }   - func setNickFormat(msg *config.Message, format string) { - if format == "" { - msg.Username = msg.Protocol + "." + msg.Origin + "-" + msg.Username + ": " - return - } - msg.Username = strings.Replace(format, "{NICK}", msg.Username, -1) - msg.Username = strings.Replace(msg.Username, "{BRIDGE}", msg.Origin, -1) - msg.Username = strings.Replace(msg.Username, "{PROTOCOL}", msg.Protocol, -1) - } - - func (gw *SameChannelGateway) modifyMessage(msg *config.Message, dest bridge.Bridge) { - switch dest.Protocol() { - case "irc": - setNickFormat(msg, gw.Config.IRC[dest.Origin()].RemoteNickFormat) - case "mattermost": - setNickFormat(msg, gw.Config.Mattermost[dest.Origin()].RemoteNickFormat) - case "slack": - setNickFormat(msg, gw.Config.Slack[dest.Origin()].RemoteNickFormat) - case "discord": - setNickFormat(msg, gw.Config.Discord[dest.Origin()].RemoteNickFormat) - } + func (gw *SameChannelGateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) { + br := gw.Bridges[msg.Account] + nick := dest.Config.RemoteNickFormat + nick = strings.Replace(nick, "{NICK}", msg.Username, -1) + nick = strings.Replace(nick, "{BRIDGE}", br.Name, -1) + nick = strings.Replace(nick, "{PROTOCOL}", br.Protocol, -1) + msg.Username = nick   }  +  +func (gw *SameChannelGateway) validChannel(channel string) bool {  + for _, c := range gw.Channels {  + if c == channel {  + return true  + }  + }  + return false  +}