summaryrefslogtreecommitdiffstats
path: root/bridge/bridge.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-02-14 23:52:45 +0100
committerWim <wim@42.be>2017-02-14 23:52:45 +0100
commitdc3723210076d7f7fecdfbf98b5de2f4540900ea (patch)
tree4ea4e6f055562d3f884f2c1b5c65bcbf79f5844c /bridge/bridge.go
parent163f55f9c27e9e8a75774424d22598799e8306c6 (diff)
downloadmatterbridge-msglm-dc3723210076d7f7fecdfbf98b5de2f4540900ea.tar.gz
matterbridge-msglm-dc3723210076d7f7fecdfbf98b5de2f4540900ea.tar.bz2
matterbridge-msglm-dc3723210076d7f7fecdfbf98b5de2f4540900ea.zip
Refactor. Make extra options easier for other protocols
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r--bridge/bridge.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go
index c8c6ac4e..db26c422 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -25,16 +25,17 @@ type Bridger interface {
type Bridge struct {
Config config.Protocol
Bridger
- Name string
- Account string
- Protocol string
- ChannelsOut []string
- ChannelsIn []string
- ChannelOptions config.ChannelOptions
+ Name string
+ Account string
+ Protocol string
+ ChannelsIn map[string]config.ChannelOptions
+ ChannelsOut map[string]config.ChannelOptions
}
func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Bridge {
b := new(Bridge)
+ b.ChannelsIn = make(map[string]config.ChannelOptions)
+ b.ChannelsOut = make(map[string]config.ChannelOptions)
accInfo := strings.Split(bridge.Account, ".")
protocol := accInfo[0]
name := accInfo[1]
@@ -75,10 +76,22 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
func (b *Bridge) JoinChannels() error {
exists := make(map[string]bool)
- for _, channel := range append(b.ChannelsIn, b.ChannelsOut...) {
+ b.joinChannels(b.ChannelsIn, exists)
+ b.joinChannels(b.ChannelsOut, exists)
+ return nil
+}
+
+func (b *Bridge) joinChannels(cMap map[string]config.ChannelOptions, exists map[string]bool) error {
+ mychannel := ""
+ for channel, info := range cMap {
if !exists[channel] {
+ mychannel = channel
log.Infof("%s: joining %s", b.Account, channel)
- b.JoinChannel(channel)
+ if b.Protocol == "irc" && info.Key != "" {
+ log.Debugf("using key %s for channel %s", info.Key, channel)
+ mychannel = mychannel + " " + info.Key
+ }
+ b.JoinChannel(mychannel)
exists[channel] = true
}
}