Skip to content

Commit

Permalink
Include additional info such as channel, msgid, and msg line # in OOT…
Browse files Browse the repository at this point in the history
…RACE
  • Loading branch information
hloeung committed Jul 22, 2021
1 parent c96ade5 commit 92c1a09
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type ChannelMessageEvent struct {
MessageID string
Event string
ParentID string
Multiline bool
MessageIdx int
}

type ChannelTopicEvent struct {
Expand Down
15 changes: 11 additions & 4 deletions bridge/mattermost/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,15 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
}

codeBlock := false
for _, msg := range msgs {
for msgIndex, msg := range msgs {
if msg == "```" {
codeBlock = !codeBlock
}
// skip empty lines for anything not part of a code block.
if !codeBlock && msg == "" {
if len(msgs) > 1 && m.v.GetBool("ootrace") {
logger.Infof("OOTRACE: #%s: %s: skipping msg %d to eventChan", dmchannel, data.Id, msgIndex)
}
continue
}

Expand Down Expand Up @@ -938,16 +941,20 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
MessageID: data.Id,
Event: rmsg.Event,
ParentID: data.ParentId,
Multiline: len(msgs) > 1,
MessageIdx: msgIndex,
},
}

if len(msgs) > 1 && m.v.GetBool("ootrace") {
logger.Infof("OOTRACE: sending msg %s to eventChan on %d: %d", msg, time.Now().UnixNano(), len(m.eventChan))
logger.Infof("OOTRACE: #%s: %s: sending msg %d %s to eventChan on %d: %d", dmchannel, data.Id, msgIndex, msg, time.Now().UnixNano(), len(m.eventChan))
}

m.eventChan <- event

if len(msgs) > 1 && m.v.GetBool("ootrace") {
logger.Infof("OOTRACE: #%s: %s: sent msg %d %s to eventChan on %d: %d", dmchannel, data.Id, msgIndex, msg, time.Now().UnixNano(), len(m.eventChan))
}

if data.Type == "me" {
break
}
Expand All @@ -957,7 +964,7 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
m.handleFileEvent(channelType, ghost, data, rmsg)

if len(msgs) > 1 && m.v.GetBool("ootrace") {
logger.Infof("OOTRACE: %s sent %v", m.mc.GetUser(data.UserId).Username, data.Message)
logger.Infof("OOTRACE: #%s: %s: %s sent %v", dmchannel, data.Id, m.mc.GetUser(data.UserId).Username, data.Message)
}

logger.Debugf("handleWsActionPost() user %s sent %s", m.mc.GetUser(data.UserId).Username, data.Message)
Expand Down
5 changes: 3 additions & 2 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
case "notice":
ch.SpoofNotice(nick, event.Text)
default:
if u.v.GetBool("ootrace") && event.Multiline {
logger.Infof("OOTRACE: got msg %s on %d", event.Text, time.Now().UnixNano())
if u.v.GetBool("ootrace") && event.MessageIdx > 0 {
name := u.br.GetChannelName(event.ChannelID)
logger.Infof("OOTRACE: %s: %s: got msg %d %s on %d", name, event.MessageID, event.MessageIdx, event.Text, time.Now().UnixNano())
}
ch.SpoofMessage(nick, event.Text)
}
Expand Down

0 comments on commit 92c1a09

Please sign in to comment.