diff options
author | Wim <wim@42.be> | 2016-08-15 23:16:07 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-08-20 18:08:57 +0200 |
commit | 889b6debc4f339975076668b6ab7d85f7dd08922 (patch) | |
tree | 04ca8ee5be4ecb7f87f28e46e81045a9df1d3b25 /bridge/irc | |
parent | 9cb3413d9c79730fc3b61bfdef6b2c9a2003a383 (diff) | |
download | matterbridge-msglm-889b6debc4f339975076668b6ab7d85f7dd08922.tar.gz matterbridge-msglm-889b6debc4f339975076668b6ab7d85f7dd08922.tar.bz2 matterbridge-msglm-889b6debc4f339975076668b6ab7d85f7dd08922.zip |
Add Connect() to Bridger interface
Diffstat (limited to 'bridge/irc')
-rw-r--r-- | bridge/irc/irc.go | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index d37149a0..9ed5202b 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -20,38 +20,27 @@ type Birc struct { names map[string][]string ircIgnoreNicks []string *config.Config - kind string Remote chan config.Message } type FancyLog struct { - irc *log.Entry - mm *log.Entry - xmpp *log.Entry + irc *log.Entry } var flog FancyLog -const Legacy = "legacy" - func init() { flog.irc = log.WithFields(log.Fields{"module": "irc"}) - flog.mm = log.WithFields(log.Fields{"module": "mattermost"}) - flog.xmpp = log.WithFields(log.Fields{"module": "xmpp"}) } func New(config *config.Config, c chan config.Message) *Birc { b := &Birc{} b.Config = config - b.kind = "legacy" b.Remote = c b.ircNick = b.Config.IRC.Nick b.ircMap = make(map[string]string) b.names = make(map[string][]string) b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks) - flog.irc.Info("Trying IRC connection") - b.i = b.connect() - flog.irc.Info("Connection succeeded") return b } @@ -63,6 +52,27 @@ func (b *Birc) Command(msg *config.Message) string { return "" } +func (b *Birc) Connect() error { + flog.irc.Info("Trying IRC connection") + i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick) + i.UseTLS = b.Config.IRC.UseTLS + i.UseSASL = b.Config.IRC.UseSASL + i.SASLLogin = b.Config.IRC.NickServNick + i.SASLPassword = b.Config.IRC.NickServPassword + i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify} + if b.Config.IRC.Password != "" { + i.Password = b.Config.IRC.Password + } + i.AddCallback(ircm.RPL_WELCOME, b.handleNewConnection) + err := i.Connect(b.Config.IRC.Server) + if err != nil { + return err + } + flog.irc.Info("Connection succeeded") + b.i = i + return nil +} + func (b *Birc) Name() string { return "irc" } @@ -80,24 +90,6 @@ func (b *Birc) Send(msg config.Message) error { return nil } -func (b *Birc) connect() *irc.Connection { - i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick) - i.UseTLS = b.Config.IRC.UseTLS - i.UseSASL = b.Config.IRC.UseSASL - i.SASLLogin = b.Config.IRC.NickServNick - i.SASLPassword = b.Config.IRC.NickServPassword - i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify} - if b.Config.IRC.Password != "" { - i.Password = b.Config.IRC.Password - } - i.AddCallback(ircm.RPL_WELCOME, b.handleNewConnection) - err := i.Connect(b.Config.IRC.Server) - if err != nil { - flog.irc.Fatal(err) - } - return i -} - func (b *Birc) endNames(event *irc.Event) { channel := event.Arguments[1] sort.Strings(b.names[channel]) |