Merge pull request #184 from velour/logself

slackApp: a few fixes...
This commit is contained in:
Chris Sexton 2019-06-07 16:56:23 -04:00 committed by GitHub
commit f407da6128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 17 deletions

View File

@ -185,27 +185,29 @@ func (s *SlackApp) msgReceivd(msg *slackevents.MessageEvent) {
} }
isItMe := msg.BotID != "" && msg.BotID == s.myBotID isItMe := msg.BotID != "" && msg.BotID == s.myBotID
m := s.buildMessage(msg)
if m.Time.Before(s.lastRecieved) {
log.Debug().
Time("ts", m.Time).
Interface("lastRecv", s.lastRecieved).
Msg("Ignoring message")
return
}
if err := s.log(m); err != nil {
log.Fatal().Err(err).Msg("Error logging message")
}
if !isItMe && msg.ThreadTimeStamp == "" { if !isItMe && msg.ThreadTimeStamp == "" {
m := s.buildMessage(msg) s.lastRecieved = m.Time
if m.Time.Before(s.lastRecieved) { s.event(s, bot.Message, m)
log.Debug().
Time("ts", m.Time).
Interface("lastRecv", s.lastRecieved).
Msg("Ignoring message")
} else {
if err := s.log(m); err != nil {
log.Fatal().Err(err).Msg("Error logging message")
}
s.lastRecieved = m.Time
s.event(s, bot.Message, m)
}
} else if msg.ThreadTimeStamp != "" { } else if msg.ThreadTimeStamp != "" {
//we're throwing away some information here by not parsing the correct reply object type, but that's okay //we're throwing away some information here by not parsing the correct reply object type, but that's okay
s.event(s, bot.Reply, s.buildMessage(msg), msg.ThreadTimeStamp) s.event(s, bot.Reply, s.buildMessage(msg), msg.ThreadTimeStamp)
} else if isItMe {
s.event(s, bot.SelfMessage, m)
} else { } else {
log.Debug(). log.Debug().
Str("text", msg.Text). Str("text", msg.Text).
Msg("THAT MESSAGE WAS HIDDEN") Msg("Unknown message is hidden")
} }
} }
@ -408,12 +410,16 @@ func (s *SlackApp) buildMessage(m *slackevents.MessageEvent) msg.Message {
name := "UNKNOWN" name := "UNKNOWN"
u, _ := s.getUser(m.User) u, _ := s.getUser(m.User)
if u != nil { if u != nil {
name = u.Name name = u.Profile.DisplayName
} }
if m.Username != "" && u == nil { if m.Username != "" && u == nil {
name = m.Username name = m.Username
} }
ch, _ := s.getChannel(m.Channel)
chName := m.Channel
if ch, _ := s.getChannel(m.Channel); ch != nil {
chName = ch.Name
}
tstamp := slackTStoTime(m.TimeStamp) tstamp := slackTStoTime(m.TimeStamp)
@ -425,7 +431,7 @@ func (s *SlackApp) buildMessage(m *slackevents.MessageEvent) msg.Message {
Body: text, Body: text,
Raw: m, Raw: m,
Channel: m.Channel, Channel: m.Channel,
ChannelName: ch.Name, ChannelName: chName,
IsIM: m.ChannelType == "im", IsIM: m.ChannelType == "im",
Command: isCmd, Command: isCmd,
Action: isAction, Action: isAction,