From 51327a405651442ac47c4ce75363442fa323b592 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 9 Jun 2018 06:47:40 -0400 Subject: Reconnect on quit. (irc) See #431 (#445) * potential fixes for #431 * go: fix formatting/gofmt/goreturns --- bridge/irc/irc.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'bridge/irc') diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 4919c85d..fe1e0d3b 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -4,14 +4,6 @@ import ( "bytes" "crypto/tls" "fmt" - "github.com/42wim/matterbridge/bridge" - "github.com/42wim/matterbridge/bridge/config" - "github.com/42wim/matterbridge/bridge/helper" - "github.com/dfordsoft/golib/ic" - "github.com/lrstanley/girc" - "github.com/paulrosania/go-charset/charset" - _ "github.com/paulrosania/go-charset/data" - "github.com/saintfish/chardet" "hash/crc32" "io" "io/ioutil" @@ -22,6 +14,15 @@ import ( "strings" "time" "unicode/utf8" + + "github.com/42wim/matterbridge/bridge" + "github.com/42wim/matterbridge/bridge/config" + "github.com/42wim/matterbridge/bridge/helper" + "github.com/dfordsoft/golib/ic" + "github.com/lrstanley/girc" + "github.com/paulrosania/go-charset/charset" + _ "github.com/paulrosania/go-charset/data" + "github.com/saintfish/chardet" ) type Birc struct { @@ -114,18 +115,19 @@ func (b *Birc) Connect() error { go func() { for { if err := i.Connect(); err != nil { - b.Log.Errorf("error: %s", err) - b.Log.Info("reconnecting in 30 seconds...") - time.Sleep(30 * time.Second) - i.Handlers.Clear(girc.RPL_WELCOME) - i.Handlers.Add(girc.RPL_WELCOME, func(client *girc.Client, event girc.Event) { - b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS} - // set our correct nick on reconnect if necessary - b.Nick = event.Source.Name - }) + b.Log.Errorf("disconnect: error: %s", err) } else { - return + b.Log.Info("disconnect: client requested quit") } + + b.Log.Info("reconnecting in 30 seconds...") + time.Sleep(30 * time.Second) + i.Handlers.Clear(girc.RPL_WELCOME) + i.Handlers.Add(girc.RPL_WELCOME, func(client *girc.Client, event girc.Event) { + b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS} + // set our correct nick on reconnect if necessary + b.Nick = event.Source.Name + }) } }() b.i = i -- cgit v1.2.3