Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 8af1cca2ee7cebb0753cb1833aedb969969b0d59 Author: Wim <wim@42.be> Date: Tue Sep 20 00:13:57 2016 +0000 Cleanup slack bridge debug/info messages diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index fbaff70..7542985 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -169 +168 @@ type MMMessage struct {  }    type Bslack struct { - mh *matterhook.Client - sc *slack.Client - // MMapi + mh *matterhook.Client + sc *slack.Client   Config *config.Protocol   rtm *slack.RTM   Plus bool @@ -417 +407 @@ func New(config config.Protocol, origin string, c chan config.Message) *Bslack {   b.Remote = c   b.protocol = protocol   b.origin = origin - b.Plus = config.UseAPI + b.Config.UseAPI = config.UseAPI   return b  }   @@ -5019 +4914 @@ func (b *Bslack) Command(cmd string) string {  }    func (b *Bslack) Connect() error { - if !b.Plus { + flog.Info("Connecting") + if !b.Config.UseAPI {   b.mh = matterhook.New(b.Config.URL,   matterhook.Config{BindAddress: b.Config.BindAddress})   } else {   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()   go b.rtm.ManageConnection()   go b.handleSlack() @@ -767 +706 @@ func (b *Bslack) FullOrigin() string {  func (b *Bslack) JoinChannel(channel string) error {   schannel := b.getChannelByName(channel)   if schannel != nil && !schannel.IsMember { - flog.Infof("Joining %s", channel)   b.sc.JoinChannel(schannel.ID)   }   return nil @@ -958 +888 @@ func (b *Bslack) Origin() string {  }    func (b *Bslack) Send(msg config.Message) error { - flog.Infof("slack send %#v", msg) - if msg.Origin != "slack" { + flog.Debugf("Receiving %#v", msg) + if msg.FullOrigin != b.FullOrigin() {   return b.SendType(msg.Username, msg.Text, msg.Channel, "")   }   return nil @@ -1067 +997 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str   if b.Config.PrefixMessagesWithNick {   message = nick + " " + message   } - if !b.Plus { + if !b.Config.UseAPI {   matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}   matterMessage.Channel = channel   matterMessage.UserName = nick @@ -11710 +1108 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str   flog.Info(err)   return err   } - flog.Debug("->slack channel: ", channel, " ", message)   return nil   } - flog.Debugf("sent to slack channel API: %s %s", channel, message)   newmsg := b.rtm.NewOutgoingMessage(message, b.getChannelByName(channel).ID)   b.rtm.SendMessage(newmsg)   return nil @@ -13919 +13019 @@ func (b *Bslack) getChannelByName(name string) *slack.Channel {  }    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) - if b.Plus { + if b.Config.UseAPI {   go b.handleSlackClient(mchan)   } else {   go b.handleMatterHook(mchan)   }   time.Sleep(time.Second) - flog.Info("Start listening for Slack messages") + flog.Debug("Start listening for Slack messages")   for message := range mchan {   texts := strings.Split(message.Text, "\n")   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()}   }   } @@ -1617 +1527 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {   for msg := range b.rtm.IncomingEvents {   switch ev := msg.Data.(type) {   case *slack.MessageEvent: - flog.Debugf("%#v", ev) + flog.Debugf("Receiving from slackclient %#v", ev)   channel, err := b.rtm.GetChannelInfo(ev.Channel)   if err != nil {   continue @@ -1897 +1807 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {  func (b *Bslack) handleMatterHook(mchan chan *MMMessage) {   for {   message := b.mh.Receive() - flog.Debugf("receiving from slack %#v", message) + flog.Debugf("receiving from matterhook (slack) %#v", message)   m := &MMMessage{}   m.Username = message.UserName   m.Text = message.Text