mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 17:30:26 +00:00
Cleanup slack bridge debug/info messages
This commit is contained in:
parent
e8c7898583
commit
0e96e9f9be
@ -16,9 +16,8 @@ type MMMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Bslack struct {
|
type Bslack struct {
|
||||||
mh *matterhook.Client
|
mh *matterhook.Client
|
||||||
sc *slack.Client
|
sc *slack.Client
|
||||||
// MMapi
|
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
rtm *slack.RTM
|
rtm *slack.RTM
|
||||||
Plus bool
|
Plus bool
|
||||||
@ -41,7 +40,7 @@ func New(config config.Protocol, origin string, c chan config.Message) *Bslack {
|
|||||||
b.Remote = c
|
b.Remote = c
|
||||||
b.protocol = protocol
|
b.protocol = protocol
|
||||||
b.origin = origin
|
b.origin = origin
|
||||||
b.Plus = config.UseAPI
|
b.Config.UseAPI = config.UseAPI
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,19 +49,14 @@ func (b *Bslack) Command(cmd string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) Connect() error {
|
func (b *Bslack) Connect() error {
|
||||||
if !b.Plus {
|
flog.Info("Connecting")
|
||||||
|
if !b.Config.UseAPI {
|
||||||
b.mh = matterhook.New(b.Config.URL,
|
b.mh = matterhook.New(b.Config.URL,
|
||||||
matterhook.Config{BindAddress: b.Config.BindAddress})
|
matterhook.Config{BindAddress: b.Config.BindAddress})
|
||||||
} else {
|
} else {
|
||||||
b.sc = slack.New(b.Config.Token)
|
b.sc = slack.New(b.Config.Token)
|
||||||
flog.Infof("Trying login on slack with Token")
|
|
||||||
/*
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
flog.Info("Login ok")
|
|
||||||
}
|
}
|
||||||
|
flog.Info("Connection succeeded")
|
||||||
b.rtm = b.sc.NewRTM()
|
b.rtm = b.sc.NewRTM()
|
||||||
go b.rtm.ManageConnection()
|
go b.rtm.ManageConnection()
|
||||||
go b.handleSlack()
|
go b.handleSlack()
|
||||||
@ -76,7 +70,6 @@ func (b *Bslack) FullOrigin() string {
|
|||||||
func (b *Bslack) JoinChannel(channel string) error {
|
func (b *Bslack) JoinChannel(channel string) error {
|
||||||
schannel := b.getChannelByName(channel)
|
schannel := b.getChannelByName(channel)
|
||||||
if schannel != nil && !schannel.IsMember {
|
if schannel != nil && !schannel.IsMember {
|
||||||
flog.Infof("Joining %s", channel)
|
|
||||||
b.sc.JoinChannel(schannel.ID)
|
b.sc.JoinChannel(schannel.ID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -95,8 +88,8 @@ func (b *Bslack) Origin() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) Send(msg config.Message) error {
|
func (b *Bslack) Send(msg config.Message) error {
|
||||||
flog.Infof("slack send %#v", msg)
|
flog.Debugf("Receiving %#v", msg)
|
||||||
if msg.Origin != "slack" {
|
if msg.FullOrigin != b.FullOrigin() {
|
||||||
return b.SendType(msg.Username, msg.Text, msg.Channel, "")
|
return b.SendType(msg.Username, msg.Text, msg.Channel, "")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -106,7 +99,7 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str
|
|||||||
if b.Config.PrefixMessagesWithNick {
|
if b.Config.PrefixMessagesWithNick {
|
||||||
message = nick + " " + message
|
message = nick + " " + message
|
||||||
}
|
}
|
||||||
if !b.Plus {
|
if !b.Config.UseAPI {
|
||||||
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
|
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
|
||||||
matterMessage.Channel = channel
|
matterMessage.Channel = channel
|
||||||
matterMessage.UserName = nick
|
matterMessage.UserName = nick
|
||||||
@ -117,10 +110,8 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str
|
|||||||
flog.Info(err)
|
flog.Info(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
flog.Debug("->slack channel: ", channel, " ", message)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
flog.Debugf("sent to slack channel API: %s %s", channel, message)
|
|
||||||
newmsg := b.rtm.NewOutgoingMessage(message, b.getChannelByName(channel).ID)
|
newmsg := b.rtm.NewOutgoingMessage(message, b.getChannelByName(channel).ID)
|
||||||
b.rtm.SendMessage(newmsg)
|
b.rtm.SendMessage(newmsg)
|
||||||
return nil
|
return nil
|
||||||
@ -139,19 +130,19 @@ func (b *Bslack) getChannelByName(name string) *slack.Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) handleSlack() {
|
func (b *Bslack) handleSlack() {
|
||||||
flog.Infof("Choosing API based slack connection: %t", b.Plus)
|
flog.Debugf("Choosing API based slack connection: %t", b.Config.UseAPI)
|
||||||
mchan := make(chan *MMMessage)
|
mchan := make(chan *MMMessage)
|
||||||
if b.Plus {
|
if b.Config.UseAPI {
|
||||||
go b.handleSlackClient(mchan)
|
go b.handleSlackClient(mchan)
|
||||||
} else {
|
} else {
|
||||||
go b.handleMatterHook(mchan)
|
go b.handleMatterHook(mchan)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
flog.Info("Start listening for Slack messages")
|
flog.Debug("Start listening for Slack messages")
|
||||||
for message := range mchan {
|
for message := range mchan {
|
||||||
texts := strings.Split(message.Text, "\n")
|
texts := strings.Split(message.Text, "\n")
|
||||||
for _, text := range texts {
|
for _, text := range texts {
|
||||||
flog.Debug("Sending message from " + message.Username + " to " + message.Channel)
|
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.FullOrigin())
|
||||||
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin()}
|
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +152,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
|
|||||||
for msg := range b.rtm.IncomingEvents {
|
for msg := range b.rtm.IncomingEvents {
|
||||||
switch ev := msg.Data.(type) {
|
switch ev := msg.Data.(type) {
|
||||||
case *slack.MessageEvent:
|
case *slack.MessageEvent:
|
||||||
flog.Debugf("%#v", ev)
|
flog.Debugf("Receiving from slackclient %#v", ev)
|
||||||
channel, err := b.rtm.GetChannelInfo(ev.Channel)
|
channel, err := b.rtm.GetChannelInfo(ev.Channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -189,7 +180,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
|
|||||||
func (b *Bslack) handleMatterHook(mchan chan *MMMessage) {
|
func (b *Bslack) handleMatterHook(mchan chan *MMMessage) {
|
||||||
for {
|
for {
|
||||||
message := b.mh.Receive()
|
message := b.mh.Receive()
|
||||||
flog.Debugf("receiving from slack %#v", message)
|
flog.Debugf("receiving from matterhook (slack) %#v", message)
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
m.Username = message.UserName
|
m.Username = message.UserName
|
||||||
m.Text = message.Text
|
m.Text = message.Text
|
||||||
|
Loading…
Reference in New Issue
Block a user