Reconnect on quit. (irc) See #431 (#445)

* potential fixes for #431
* go: fix formatting/gofmt/goreturns
This commit is contained in:
Liam Stanley 2018-06-09 06:47:40 -04:00 committed by Wim
parent 33bd60528b
commit 51327a4056
15 changed files with 69 additions and 54 deletions

View File

@ -2,14 +2,15 @@ package api
import ( import (
"encoding/json" "encoding/json"
"net/http"
"sync"
"time"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/labstack/echo" "github.com/labstack/echo"
"github.com/labstack/echo/middleware" "github.com/labstack/echo/middleware"
"github.com/zfjagann/golang-ring" "github.com/zfjagann/golang-ring"
"net/http"
"sync"
"time"
) )
type Api struct { type Api struct {

View File

@ -3,13 +3,14 @@ package bdiscord
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"regexp"
"strings"
"sync"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"regexp"
"strings"
"sync"
) )
type Bdiscord struct { type Bdiscord struct {

View File

@ -2,11 +2,12 @@ package bgitter
import ( import (
"fmt" "fmt"
"strings"
"github.com/42wim/go-gitter" "github.com/42wim/go-gitter"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"strings"
) )
type Bgitter struct { type Bgitter struct {

View File

@ -3,12 +3,13 @@ package helper
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/sirupsen/logrus"
"io" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/sirupsen/logrus"
) )
func DownloadFile(url string) (*[]byte, error) { func DownloadFile(url string) (*[]byte, error) {

View File

@ -4,14 +4,6 @@ import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"fmt" "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" "hash/crc32"
"io" "io"
"io/ioutil" "io/ioutil"
@ -22,6 +14,15 @@ import (
"strings" "strings"
"time" "time"
"unicode/utf8" "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 { type Birc struct {
@ -114,18 +115,19 @@ func (b *Birc) Connect() error {
go func() { go func() {
for { for {
if err := i.Connect(); err != nil { if err := i.Connect(); err != nil {
b.Log.Errorf("error: %s", err) b.Log.Errorf("disconnect: 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
})
} else { } 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 b.i = i

View File

@ -3,14 +3,15 @@ package bmatrix
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
matrix "github.com/matterbridge/gomatrix"
"mime" "mime"
"regexp" "regexp"
"strings" "strings"
"sync" "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 { type Bmatrix struct {

View File

@ -3,13 +3,14 @@ package bmattermost
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/matterclient" "github.com/42wim/matterbridge/matterclient"
"github.com/42wim/matterbridge/matterhook" "github.com/42wim/matterbridge/matterhook"
"github.com/rs/xid" "github.com/rs/xid"
"strings"
) )
type Bmattermost struct { type Bmattermost struct {

View File

@ -2,13 +2,14 @@ package bsshchat
import ( import (
"bufio" "bufio"
"io"
"strings"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/shazow/ssh-chat/sshd" "github.com/shazow/ssh-chat/sshd"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io"
"strings"
) )
type Bsshchat struct { type Bsshchat struct {

View File

@ -2,8 +2,9 @@ package btelegram
import ( import (
"bytes" "bytes"
"github.com/russross/blackfriday"
"html" "html"
"github.com/russross/blackfriday"
) )
type customHTML struct { type customHTML struct {

View File

@ -2,14 +2,15 @@ package bxmpp
import ( import (
"crypto/tls" "crypto/tls"
"strings"
"time"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/jpillora/backoff" "github.com/jpillora/backoff"
"github.com/rs/xid"
"github.com/matterbridge/go-xmpp" "github.com/matterbridge/go-xmpp"
"strings" "github.com/rs/xid"
"time"
) )
type Bxmpp struct { type Bxmpp struct {

View File

@ -10,18 +10,18 @@ import (
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/api" "github.com/42wim/matterbridge/bridge/api"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/discord" bdiscord "github.com/42wim/matterbridge/bridge/discord"
"github.com/42wim/matterbridge/bridge/gitter" bgitter "github.com/42wim/matterbridge/bridge/gitter"
"github.com/42wim/matterbridge/bridge/irc" birc "github.com/42wim/matterbridge/bridge/irc"
"github.com/42wim/matterbridge/bridge/matrix" bmatrix "github.com/42wim/matterbridge/bridge/matrix"
"github.com/42wim/matterbridge/bridge/mattermost" bmattermost "github.com/42wim/matterbridge/bridge/mattermost"
"github.com/42wim/matterbridge/bridge/rocketchat" brocketchat "github.com/42wim/matterbridge/bridge/rocketchat"
"github.com/42wim/matterbridge/bridge/slack" bslack "github.com/42wim/matterbridge/bridge/slack"
"github.com/42wim/matterbridge/bridge/sshchat" bsshchat "github.com/42wim/matterbridge/bridge/sshchat"
"github.com/42wim/matterbridge/bridge/steam" bsteam "github.com/42wim/matterbridge/bridge/steam"
"github.com/42wim/matterbridge/bridge/telegram" btelegram "github.com/42wim/matterbridge/bridge/telegram"
"github.com/42wim/matterbridge/bridge/xmpp" bxmpp "github.com/42wim/matterbridge/bridge/xmpp"
"github.com/42wim/matterbridge/bridge/zulip" bzulip "github.com/42wim/matterbridge/bridge/zulip"
"github.com/hashicorp/golang-lru" "github.com/hashicorp/golang-lru"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
// "github.com/davecgh/go-spew/spew" // "github.com/davecgh/go-spew/spew"

View File

@ -2,9 +2,10 @@ package gateway
import ( import (
"fmt" "fmt"
"strconv"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"strconv"
"testing" "testing"
) )

View File

@ -2,9 +2,10 @@ package gateway
import ( import (
"fmt" "fmt"
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "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" // "github.com/davecgh/go-spew/spew"
"time" "time"
) )

View File

@ -2,6 +2,7 @@ package samechannelgateway
import ( import (
"fmt" "fmt"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"

View File

@ -6,14 +6,15 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gorilla/schema"
"github.com/nlopes/slack"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
"time" "time"
"github.com/gorilla/schema"
"github.com/nlopes/slack"
) )
// OMessage for mattermost incoming webhook. (send to mattermost) // OMessage for mattermost incoming webhook. (send to mattermost)