mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 18:59:24 +00:00
Reuse connection when using same bridge with another gateway. See #87
This commit is contained in:
@ -31,6 +31,7 @@ type Bridge struct {
|
||||
Account string
|
||||
Protocol string
|
||||
Channels map[string]config.ChannelInfo
|
||||
Joined map[string]bool
|
||||
}
|
||||
|
||||
func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Bridge {
|
||||
@ -42,6 +43,7 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
|
||||
b.Name = name
|
||||
b.Protocol = protocol
|
||||
b.Account = bridge.Account
|
||||
b.Joined = make(map[string]bool)
|
||||
|
||||
// override config from environment
|
||||
config.OverrideCfgFromEnv(cfg, protocol, name)
|
||||
@ -81,8 +83,7 @@ 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.Channels, exists)
|
||||
err := b.joinChannels(b.Channels, b.Joined)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -94,7 +95,7 @@ func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map
|
||||
for ID, channel := range channels {
|
||||
if !exists[ID] {
|
||||
mychannel = channel.Name
|
||||
log.Infof("%s: joining %s %s", b.Account, channel.Name, ID)
|
||||
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
|
||||
|
@ -26,11 +26,13 @@ type Message struct {
|
||||
}
|
||||
|
||||
type ChannelInfo struct {
|
||||
Name string
|
||||
Account string
|
||||
Direction string
|
||||
ID string
|
||||
Options ChannelOptions
|
||||
Name string
|
||||
Account string
|
||||
Direction string
|
||||
ID string
|
||||
GID map[string]bool
|
||||
SameChannel map[string]bool
|
||||
Options ChannelOptions
|
||||
}
|
||||
|
||||
type Protocol struct {
|
||||
@ -71,9 +73,10 @@ type ChannelOptions struct {
|
||||
}
|
||||
|
||||
type Bridge struct {
|
||||
Account string
|
||||
Channel string
|
||||
Options ChannelOptions
|
||||
Account string
|
||||
Channel string
|
||||
Options ChannelOptions
|
||||
SameChannel bool
|
||||
}
|
||||
|
||||
type Gateway struct {
|
||||
|
@ -60,6 +60,7 @@ func (b *Birc) Command(msg *config.Message) string {
|
||||
}
|
||||
|
||||
func (b *Birc) Connect() error {
|
||||
flog.Info("hier?")
|
||||
b.Local = make(chan config.Message, b.Config.MessageQueue+10)
|
||||
flog.Infof("Connecting %s", b.Config.Server)
|
||||
i := irc.IRC(b.Config.Nick, b.Config.Nick)
|
||||
@ -92,7 +93,7 @@ func (b *Birc) Connect() error {
|
||||
}
|
||||
|
||||
func (b *Birc) Disconnect() error {
|
||||
b.i.Disconnect()
|
||||
//b.i.Disconnect()
|
||||
close(b.Local)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user