mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-10 08:40:29 +00:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package samechannelgateway
|
|
|
|
import (
|
|
"github.com/42wim/matterbridge/bridge/config"
|
|
"github.com/42wim/matterbridge/gateway"
|
|
)
|
|
|
|
type SameChannelGateway struct {
|
|
*config.Config
|
|
MyConfig *config.SameChannelGateway
|
|
Channels []string
|
|
Name string
|
|
}
|
|
|
|
func New(cfg *config.Config, gatewayCfg *config.SameChannelGateway) *SameChannelGateway {
|
|
return &SameChannelGateway{
|
|
MyConfig: gatewayCfg,
|
|
Channels: gatewayCfg.Channels,
|
|
Name: gatewayCfg.Name,
|
|
Config: cfg}
|
|
}
|
|
|
|
func (sgw *SameChannelGateway) Start() error {
|
|
gw := gateway.New(sgw.Config, &config.Gateway{Name: sgw.Name})
|
|
gw.DestChannelFunc = sgw.getDestChannel
|
|
for _, account := range sgw.MyConfig.Accounts {
|
|
for _, channel := range sgw.Channels {
|
|
br := config.Bridge{Account: account, Channel: channel}
|
|
gw.MyConfig.InOut = append(gw.MyConfig.InOut, br)
|
|
}
|
|
}
|
|
return gw.Start()
|
|
}
|
|
|
|
func (sgw *SameChannelGateway) validChannel(channel string) bool {
|
|
for _, c := range sgw.Channels {
|
|
if c == channel {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (sgw *SameChannelGateway) getDestChannel(msg *config.Message, dest string) []config.ChannelInfo {
|
|
var channels []config.ChannelInfo
|
|
if sgw.validChannel(msg.Channel) {
|
|
channels = append(channels, config.ChannelInfo{Name: msg.Channel, Account: dest, ID: msg.Channel + dest})
|
|
return channels
|
|
}
|
|
return channels
|
|
}
|