diff options
author | Wim <wim@42.be> | 2017-03-28 23:58:22 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-03-28 23:58:22 +0200 |
commit | 1e0490bd36ec20a7de43587f43feb6ec63c02ddb (patch) | |
tree | 56a0aef0270d4f4570392c3428eb48e533eb0939 /bridge | |
parent | 8afc641f0c9dc33195fb48b056f6c11913a10f98 (diff) | |
parent | 2e4d58cb921afe074e761285b311963ba5f358c6 (diff) | |
download | matterbridge-msglm-1e0490bd36ec20a7de43587f43feb6ec63c02ddb.tar.gz matterbridge-msglm-1e0490bd36ec20a7de43587f43feb6ec63c02ddb.tar.bz2 matterbridge-msglm-1e0490bd36ec20a7de43587f43feb6ec63c02ddb.zip |
Merge branch 'channelinfo'
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/bridge.go | 38 | ||||
-rw-r--r-- | bridge/config/config.go | 8 |
2 files changed, 24 insertions, 22 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go index 12fb71d7..022e6a98 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -27,17 +27,15 @@ type Bridger interface { type Bridge struct { Config config.Protocol Bridger - Name string - Account string - Protocol string - ChannelsIn map[string]config.ChannelOptions - ChannelsOut map[string]config.ChannelOptions + Name string + Account string + Protocol string + Channels map[string]config.ChannelInfo } 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) + b.Channels = make(map[string]config.ChannelInfo) accInfo := strings.Split(bridge.Account, ".") protocol := accInfo[0] name := accInfo[1] @@ -84,32 +82,28 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid func (b *Bridge) JoinChannels() error { exists := make(map[string]bool) - err := b.joinChannels(b.ChannelsIn, exists) - if err != nil { - return err - } - err = b.joinChannels(b.ChannelsOut, exists) + err := b.joinChannels(b.Channels, exists) if err != nil { return err } return nil } -func (b *Bridge) joinChannels(cMap map[string]config.ChannelOptions, exists map[string]bool) error { +func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, 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 + for ID, channel := range channels { + if !exists[ID] { + mychannel = channel.Name + log.Infof("%s: joining %s %s", b.Account, channel.Name, ID) + if b.Protocol == "irc" && channel.Options.Key != "" { + log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name) + mychannel = mychannel + " " + channel.Options.Key } - err := b.JoinChannel(mychannel) + err := b.JoinChannel(channel.Name) if err != nil { return err } - exists[channel] = true + exists[ID] = true } } return nil diff --git a/bridge/config/config.go b/bridge/config/config.go index 23f8db18..f48da10f 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -25,6 +25,14 @@ type Message struct { Timestamp time.Time } +type ChannelInfo struct { + Name string + Account string + Direction string + ID string + Options ChannelOptions +} + type Protocol struct { BindAddress string // mattermost, slack Buffer int // api |