mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-24 11:42:03 -08:00
Add Connect() to Bridger interface
This commit is contained in:
parent
9cb3413d9c
commit
889b6debc4
@ -41,6 +41,9 @@ func NewBridge(cfg *config.Config) error {
|
|||||||
if len(b.Bridges) < 2 {
|
if len(b.Bridges) < 2 {
|
||||||
log.Fatalf("only %d sections enabled. Need at least 2 sections enabled (eg [IRC] and [mattermost]", len(b.Bridges))
|
log.Fatalf("only %d sections enabled. Need at least 2 sections enabled (eg [IRC] and [mattermost]", len(b.Bridges))
|
||||||
}
|
}
|
||||||
|
for _, br := range b.Bridges {
|
||||||
|
br.Connect()
|
||||||
|
}
|
||||||
b.mapChannels()
|
b.mapChannels()
|
||||||
b.mapIgnores()
|
b.mapIgnores()
|
||||||
b.handleReceive(c)
|
b.handleReceive(c)
|
||||||
|
@ -20,38 +20,27 @@ type Birc struct {
|
|||||||
names map[string][]string
|
names map[string][]string
|
||||||
ircIgnoreNicks []string
|
ircIgnoreNicks []string
|
||||||
*config.Config
|
*config.Config
|
||||||
kind string
|
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
type FancyLog struct {
|
type FancyLog struct {
|
||||||
irc *log.Entry
|
irc *log.Entry
|
||||||
mm *log.Entry
|
|
||||||
xmpp *log.Entry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var flog FancyLog
|
var flog FancyLog
|
||||||
|
|
||||||
const Legacy = "legacy"
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flog.irc = log.WithFields(log.Fields{"module": "irc"})
|
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 {
|
func New(config *config.Config, c chan config.Message) *Birc {
|
||||||
b := &Birc{}
|
b := &Birc{}
|
||||||
b.Config = config
|
b.Config = config
|
||||||
b.kind = "legacy"
|
|
||||||
b.Remote = c
|
b.Remote = c
|
||||||
b.ircNick = b.Config.IRC.Nick
|
b.ircNick = b.Config.IRC.Nick
|
||||||
b.ircMap = make(map[string]string)
|
b.ircMap = make(map[string]string)
|
||||||
b.names = make(map[string][]string)
|
b.names = make(map[string][]string)
|
||||||
b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
|
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
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +52,27 @@ func (b *Birc) Command(msg *config.Message) string {
|
|||||||
return ""
|
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 {
|
func (b *Birc) Name() string {
|
||||||
return "irc"
|
return "irc"
|
||||||
}
|
}
|
||||||
@ -80,24 +90,6 @@ func (b *Birc) Send(msg config.Message) error {
|
|||||||
return nil
|
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) {
|
func (b *Birc) endNames(event *irc.Event) {
|
||||||
channel := event.Arguments[1]
|
channel := event.Arguments[1]
|
||||||
sort.Strings(b.names[channel])
|
sort.Strings(b.names[channel])
|
||||||
|
@ -55,6 +55,14 @@ func New(cfg *config.Config, c chan config.Message) *Bmattermost {
|
|||||||
b.Remote = c
|
b.Remote = c
|
||||||
b.Plus = cfg.General.Plus
|
b.Plus = cfg.General.Plus
|
||||||
b.mmMap = make(map[string]string)
|
b.mmMap = make(map[string]string)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Command(cmd string) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Connect() error {
|
||||||
if !b.Plus {
|
if !b.Plus {
|
||||||
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
||||||
matterhook.Config{InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
matterhook.Config{InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
||||||
@ -67,7 +75,7 @@ func New(cfg *config.Config, c chan config.Message) *Bmattermost {
|
|||||||
flog.mm.Infof("Trying login %s (team: %s) on %s", b.Config.Mattermost.Login, b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
flog.mm.Infof("Trying login %s (team: %s) on %s", b.Config.Mattermost.Login, b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
||||||
err := b.mc.Login()
|
err := b.mc.Login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.mm.Fatal("Can not connect", err)
|
return err
|
||||||
}
|
}
|
||||||
flog.mm.Info("Login ok")
|
flog.mm.Info("Login ok")
|
||||||
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
||||||
@ -77,11 +85,7 @@ func New(cfg *config.Config, c chan config.Message) *Bmattermost {
|
|||||||
go b.mc.WsReceiver()
|
go b.mc.WsReceiver()
|
||||||
}
|
}
|
||||||
go b.handleMatter()
|
go b.handleMatter()
|
||||||
return b
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bmattermost) Command(cmd string) string {
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmattermost) Name() string {
|
func (b *Bmattermost) Name() string {
|
||||||
|
@ -17,8 +17,6 @@ type Bxmpp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FancyLog struct {
|
type FancyLog struct {
|
||||||
irc *log.Entry
|
|
||||||
mm *log.Entry
|
|
||||||
xmpp *log.Entry
|
xmpp *log.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,27 +29,29 @@ type Message struct {
|
|||||||
var flog FancyLog
|
var flog FancyLog
|
||||||
|
|
||||||
func init() {
|
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"})
|
flog.xmpp = log.WithFields(log.Fields{"module": "xmpp"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *config.Config, c chan config.Message) *Bxmpp {
|
func New(config *config.Config, c chan config.Message) *Bxmpp {
|
||||||
b := &Bxmpp{}
|
b := &Bxmpp{}
|
||||||
b.xmppMap = make(map[string]string)
|
b.xmppMap = make(map[string]string)
|
||||||
var err error
|
|
||||||
b.Config = config
|
b.Config = config
|
||||||
b.Remote = c
|
b.Remote = c
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) Connect() error {
|
||||||
|
var err error
|
||||||
flog.xmpp.Info("Trying XMPP connection")
|
flog.xmpp.Info("Trying XMPP connection")
|
||||||
b.xc, err = b.createXMPP()
|
b.xc, err = b.createXMPP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.xmpp.Debugf("%#v", err)
|
flog.xmpp.Debugf("%#v", err)
|
||||||
panic("xmpp failure")
|
return err
|
||||||
}
|
}
|
||||||
flog.xmpp.Info("Connection succeeded")
|
flog.xmpp.Info("Connection succeeded")
|
||||||
b.setupChannels()
|
b.setupChannels()
|
||||||
go b.handleXmpp()
|
go b.handleXmpp()
|
||||||
return b
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bxmpp) Name() string {
|
func (b *Bxmpp) Name() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user