diff options
author | Wim <wim@42.be> | 2017-02-17 22:12:53 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-02-17 22:12:53 +0100 |
commit | 7558a2162e79ffa29b11881fe249ec836a8c8b3d (patch) | |
tree | c64a7e3898d7ac9e49523ed9c0b2a4eaac492886 /bridge/bridge.go | |
parent | fe258e1b6752f2751d7aec742a4ee20a5594dcdb (diff) | |
parent | 62b165c0b4052f96ab89c358301bf246d239eba7 (diff) | |
download | matterbridge-msglm-7558a2162e79ffa29b11881fe249ec836a8c8b3d.tar.gz matterbridge-msglm-7558a2162e79ffa29b11881fe249ec836a8c8b3d.tar.bz2 matterbridge-msglm-7558a2162e79ffa29b11881fe249ec836a8c8b3d.zip |
Merge branch 'status'
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r-- | bridge/bridge.go | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go index b387812a..db26c422 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -10,6 +10,8 @@ import ( "github.com/42wim/matterbridge/bridge/slack" "github.com/42wim/matterbridge/bridge/telegram" "github.com/42wim/matterbridge/bridge/xmpp" + log "github.com/Sirupsen/logrus" + "strings" ) @@ -17,18 +19,23 @@ type Bridger interface { Send(msg config.Message) error Connect() error JoinChannel(channel string) error + Disconnect() error } type Bridge struct { Config config.Protocol Bridger - Name string - Account string - Protocol string + 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] @@ -66,3 +73,27 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid } return b } + +func (b *Bridge) JoinChannels() error { + exists := make(map[string]bool) + 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) + 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 + } + } + return nil +} |