summaryrefslogtreecommitdiffstats
path: root/bridge/gitter/gitter.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-02-27 00:33:21 +0100
committerWim <wim@42.be>2018-02-27 23:22:12 +0100
commit2bac8673829516d8314c459133e85a8c0cc1959c (patch)
treeed4123232727f9c53c685b1687725206f0b02cb6 /bridge/gitter/gitter.go
parent5fbd8a3be05cdecdde515ad459b7a5d87b056956 (diff)
downloadmatterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.gz
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.tar.bz2
matterbridge-msglm-2bac8673829516d8314c459133e85a8c0cc1959c.zip
Refactor using factory
Diffstat (limited to 'bridge/gitter/gitter.go')
-rw-r--r--bridge/gitter/gitter.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go
index 69af8d2c..0cd8e520 100644
--- a/bridge/gitter/gitter.go
+++ b/bridge/gitter/gitter.go
@@ -3,9 +3,9 @@ package bgitter
import (
"fmt"
"github.com/42wim/go-gitter"
+ "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
- log "github.com/sirupsen/logrus"
"strings"
)
@@ -17,20 +17,13 @@ type Bgitter struct {
*config.BridgeConfig
}
-var flog *log.Entry
-var protocol = "gitter"
-
-func init() {
- flog = log.WithFields(log.Fields{"prefix": protocol})
-}
-
-func New(cfg *config.BridgeConfig) *Bgitter {
+func New(cfg *config.BridgeConfig) bridge.Bridger {
return &Bgitter{BridgeConfig: cfg}
}
func (b *Bgitter) Connect() error {
var err error
- flog.Info("Connecting")
+ b.Log.Info("Connecting")
b.c = gitter.New(b.Config.Token)
b.User, err = b.c.GetUser()
if err != nil {
@@ -40,7 +33,7 @@ func (b *Bgitter) Connect() error {
if err != nil {
return err
}
- flog.Info("Connection succeeded")
+ b.Log.Info("Connection succeeded")
return nil
}
@@ -78,7 +71,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
case *gitter.MessageReceived:
// ignore message sent from ourselves
if ev.Message.From.ID != b.User.ID {
- flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
+ b.Log.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
rmsg := config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID,
ID: ev.Message.ID}
@@ -86,11 +79,11 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
rmsg.Event = config.EVENT_USER_ACTION
rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1)
}
- flog.Debugf("Message is %#v", rmsg)
+ b.Log.Debugf("Message is %#v", rmsg)
b.Remote <- rmsg
}
case *gitter.GitterConnectionClosed:
- flog.Errorf("connection with gitter closed for room %s", room)
+ b.Log.Errorf("connection with gitter closed for room %s", room)
}
}
}(stream, room.URI)
@@ -98,10 +91,10 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
}
func (b *Bgitter) Send(msg config.Message) (string, error) {
- flog.Debugf("Receiving %#v", msg)
+ b.Log.Debugf("Receiving %#v", msg)
roomID := b.getRoomID(msg.Channel)
if roomID == "" {
- flog.Errorf("Could not find roomID for %v", msg.Channel)
+ b.Log.Errorf("Could not find roomID for %v", msg.Channel)
return "", nil
}
@@ -130,7 +123,7 @@ func (b *Bgitter) Send(msg config.Message) (string, error) {
// Edit message
if msg.ID != "" {
- flog.Debugf("updating message with id %s", msg.ID)
+ b.Log.Debugf("updating message with id %s", msg.ID)
_, err := b.c.UpdateMessage(roomID, msg.ID, msg.Username+msg.Text)
if err != nil {
return "", err