diff options
author | Liam Stanley <me@liamstanley.io> | 2018-06-09 06:47:40 -0400 |
---|---|---|
committer | Wim <wim@42.be> | 2018-06-09 12:47:40 +0200 |
commit | 51327a405651442ac47c4ce75363442fa323b592 (patch) | |
tree | 4011309b5c748f7e5e717a5a7fc62a4026c6f421 | |
parent | 33bd60528be4eaf28ffd1065517ea41fde9ea62b (diff) | |
download | matterbridge-msglm-51327a405651442ac47c4ce75363442fa323b592.tar.gz matterbridge-msglm-51327a405651442ac47c4ce75363442fa323b592.tar.bz2 matterbridge-msglm-51327a405651442ac47c4ce75363442fa323b592.zip |
Reconnect on quit. (irc) See #431 (#445)
* potential fixes for #431
* go: fix formatting/gofmt/goreturns
-rw-r--r-- | bridge/api/api.go | 7 | ||||
-rw-r--r-- | bridge/discord/discord.go | 7 | ||||
-rw-r--r-- | bridge/gitter/gitter.go | 3 | ||||
-rw-r--r-- | bridge/helper/helper.go | 5 | ||||
-rw-r--r-- | bridge/irc/irc.go | 38 | ||||
-rw-r--r-- | bridge/matrix/matrix.go | 9 | ||||
-rw-r--r-- | bridge/mattermost/mattermost.go | 3 | ||||
-rw-r--r-- | bridge/sshchat/sshchat.go | 5 | ||||
-rw-r--r-- | bridge/telegram/html.go | 3 | ||||
-rw-r--r-- | bridge/xmpp/xmpp.go | 7 | ||||
-rw-r--r-- | gateway/gateway.go | 24 | ||||
-rw-r--r-- | gateway/gateway_test.go | 3 | ||||
-rw-r--r-- | gateway/router.go | 3 | ||||
-rw-r--r-- | gateway/samechannel/samechannel_test.go | 1 | ||||
-rw-r--r-- | matterhook/matterhook.go | 5 |
15 files changed, 69 insertions, 54 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go index 54eea4a7..28c57106 100644 --- a/bridge/api/api.go +++ b/bridge/api/api.go @@ -2,14 +2,15 @@ package api import ( "encoding/json" + "net/http" + "sync" + "time" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/labstack/echo" "github.com/labstack/echo/middleware" "github.com/zfjagann/golang-ring" - "net/http" - "sync" - "time" ) type Api struct { diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index ef4e5ca6..81f0cbe3 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -3,13 +3,14 @@ package bdiscord import ( "bytes" "fmt" + "regexp" + "strings" + "sync" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" "github.com/bwmarrin/discordgo" - "regexp" - "strings" - "sync" ) type Bdiscord struct { diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go index faa86e5a..f47ca7ea 100644 --- a/bridge/gitter/gitter.go +++ b/bridge/gitter/gitter.go @@ -2,11 +2,12 @@ package bgitter import ( "fmt" + "strings" + "github.com/42wim/go-gitter" "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" - "strings" ) type Bgitter struct { diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index c4ac0ae2..a3f4255c 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -3,12 +3,13 @@ package helper import ( "bytes" "fmt" - "github.com/42wim/matterbridge/bridge/config" - log "github.com/sirupsen/logrus" "io" "net/http" "strings" "time" + + "github.com/42wim/matterbridge/bridge/config" + log "github.com/sirupsen/logrus" ) func DownloadFile(url string) (*[]byte, error) { 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 diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index ed3d5bf2..95ba6b42 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -3,14 +3,15 @@ package bmatrix import ( "bytes" "fmt" - "github.com/42wim/matterbridge/bridge" - "github.com/42wim/matterbridge/bridge/config" - "github.com/42wim/matterbridge/bridge/helper" - matrix "github.com/matterbridge/gomatrix" "mime" "regexp" "strings" "sync" + + "github.com/42wim/matterbridge/bridge" + "github.com/42wim/matterbridge/bridge/config" + "github.com/42wim/matterbridge/bridge/helper" + matrix "github.com/matterbridge/gomatrix" ) type Bmatrix struct { diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index ae5d9db7..14c71af4 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -3,13 +3,14 @@ package bmattermost import ( "errors" "fmt" + "strings" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/matterclient" "github.com/42wim/matterbridge/matterhook" "github.com/rs/xid" - "strings" ) type Bmattermost struct { diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index 6e879e84..846a9081 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -2,13 +2,14 @@ package bsshchat import ( "bufio" + "io" + "strings" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" "github.com/shazow/ssh-chat/sshd" log "github.com/sirupsen/logrus" - "io" - "strings" ) type Bsshchat struct { diff --git a/bridge/telegram/html.go b/bridge/telegram/html.go index 5e7bdc72..85547d7b 100644 --- a/bridge/telegram/html.go +++ b/bridge/telegram/html.go @@ -2,8 +2,9 @@ package btelegram import ( "bytes" - "github.com/russross/blackfriday" "html" + + "github.com/russross/blackfriday" ) type customHTML struct { diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index cb0da1b2..0e2d951c 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -2,14 +2,15 @@ package bxmpp import ( "crypto/tls" + "strings" + "time" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" "github.com/jpillora/backoff" - "github.com/rs/xid" "github.com/matterbridge/go-xmpp" - "strings" - "time" + "github.com/rs/xid" ) type Bxmpp struct { diff --git a/gateway/gateway.go b/gateway/gateway.go index b926912a..6529393f 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -10,18 +10,18 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/api" "github.com/42wim/matterbridge/bridge/config" - "github.com/42wim/matterbridge/bridge/discord" - "github.com/42wim/matterbridge/bridge/gitter" - "github.com/42wim/matterbridge/bridge/irc" - "github.com/42wim/matterbridge/bridge/matrix" - "github.com/42wim/matterbridge/bridge/mattermost" - "github.com/42wim/matterbridge/bridge/rocketchat" - "github.com/42wim/matterbridge/bridge/slack" - "github.com/42wim/matterbridge/bridge/sshchat" - "github.com/42wim/matterbridge/bridge/steam" - "github.com/42wim/matterbridge/bridge/telegram" - "github.com/42wim/matterbridge/bridge/xmpp" - "github.com/42wim/matterbridge/bridge/zulip" + bdiscord "github.com/42wim/matterbridge/bridge/discord" + bgitter "github.com/42wim/matterbridge/bridge/gitter" + birc "github.com/42wim/matterbridge/bridge/irc" + bmatrix "github.com/42wim/matterbridge/bridge/matrix" + bmattermost "github.com/42wim/matterbridge/bridge/mattermost" + brocketchat "github.com/42wim/matterbridge/bridge/rocketchat" + bslack "github.com/42wim/matterbridge/bridge/slack" + bsshchat "github.com/42wim/matterbridge/bridge/sshchat" + bsteam "github.com/42wim/matterbridge/bridge/steam" + btelegram "github.com/42wim/matterbridge/bridge/telegram" + bxmpp "github.com/42wim/matterbridge/bridge/xmpp" + bzulip "github.com/42wim/matterbridge/bridge/zulip" "github.com/hashicorp/golang-lru" log "github.com/sirupsen/logrus" // "github.com/davecgh/go-spew/spew" diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index 25242177..bf9461c7 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -2,9 +2,10 @@ package gateway import ( "fmt" + "strconv" + "github.com/42wim/matterbridge/bridge/config" "github.com/stretchr/testify/assert" - "strconv" "testing" ) diff --git a/gateway/router.go b/gateway/router.go index 264486c2..3a45de36 100644 --- a/gateway/router.go +++ b/gateway/router.go @@ -2,9 +2,10 @@ package gateway import ( "fmt" + "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" - "github.com/42wim/matterbridge/gateway/samechannel" + samechannelgateway "github.com/42wim/matterbridge/gateway/samechannel" // "github.com/davecgh/go-spew/spew" "time" ) diff --git a/gateway/samechannel/samechannel_test.go b/gateway/samechannel/samechannel_test.go index 7e48ebc4..7c75444f 100644 --- a/gateway/samechannel/samechannel_test.go +++ b/gateway/samechannel/samechannel_test.go @@ -2,6 +2,7 @@ package samechannelgateway import ( "fmt" + "github.com/42wim/matterbridge/bridge/config" "github.com/BurntSushi/toml" "github.com/stretchr/testify/assert" diff --git a/matterhook/matterhook.go b/matterhook/matterhook.go index 11453e34..9287baa9 100644 --- a/matterhook/matterhook.go +++ b/matterhook/matterhook.go @@ -6,14 +6,15 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/gorilla/schema" - "github.com/nlopes/slack" "io" "io/ioutil" "log" "net" "net/http" "time" + + "github.com/gorilla/schema" + "github.com/nlopes/slack" ) // OMessage for mattermost incoming webhook. (send to mattermost) |