forked from jshiffer/matterbridge
Validate channels for samechannelgateway. Fixes #73.
This commit is contained in:
parent
a3dd0f1345
commit
08ebee6b4f
@ -54,12 +54,16 @@ func (gw *SameChannelGateway) handleReceive(c chan config.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
// 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.FullOrigin == dest.FullOrigin() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gw.modifyMessage(&msg, dest)
|
gw.modifyMessage(&msg, dest)
|
||||||
log.Debugf("Sending %#v from %s to %s", msg, msg.FullOrigin, dest.FullOrigin())
|
log.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.FullOrigin, msg.Channel, dest.FullOrigin(), msg.Channel)
|
||||||
err := dest.Send(msg)
|
err := dest.Send(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -88,3 +92,12 @@ func (gw *SameChannelGateway) modifyMessage(msg *config.Message, dest bridge.Bri
|
|||||||
setNickFormat(msg, gw.Config.Discord[dest.Origin()].RemoteNickFormat)
|
setNickFormat(msg, gw.Config.Discord[dest.Origin()].RemoteNickFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gw *SameChannelGateway) validChannel(channel string) bool {
|
||||||
|
for _, c := range gw.Channels {
|
||||||
|
if c == channel {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user