Merge pull request #93 from velour/bot2bot

allow more bot2bot
This commit is contained in:
Chris Sexton 2017-11-17 10:20:13 -05:00 committed by GitHub
commit bcdd9a2a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View File

@ -109,7 +109,6 @@ type Config struct {
MinPush int MinPush int
MaxPush int MaxPush int
} }
BotList map[string]bool
} }
func init() { func init() {

View File

@ -37,6 +37,8 @@ type Slack struct {
users map[string]string users map[string]string
myBotID string
emoji map[string]string emoji map[string]string
eventReceived func(msg.Message) eventReceived func(msg.Message)
@ -228,6 +230,7 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string
type MessageResponse struct { type MessageResponse struct {
OK bool `json:"ok"` OK bool `json:"ok"`
Timestamp string `json:"ts"` Timestamp string `json:"ts"`
BotID string `json:"message.bot_id"`
} }
var mr MessageResponse var mr MessageResponse
@ -240,6 +243,8 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string
return "", errors.New("failure response received") return "", errors.New("failure response received")
} }
s.myBotID = mr.BotID
return mr.Timestamp, err return mr.Timestamp, err
} }
@ -392,16 +397,8 @@ func (s *Slack) Serve() error {
} }
switch msg.Type { switch msg.Type {
case "message": case "message":
botOK := true isItMe := s.myBotID != "" && msg.BotID != s.myBotID
if msg.BotID != "" { if !isItMe && !msg.Hidden && msg.ThreadTs == "" {
u, _ := s.getUser(msg.User)
if u == "" && msg.Username != "" {
u = msg.Username
}
log.Printf("User: %s, BotList: %+v", u, s.config.BotList)
botOK = s.config.BotList[strings.Title(u)]
}
if botOK && !msg.Hidden && msg.ThreadTs == "" {
m := s.buildMessage(msg) m := s.buildMessage(msg)
if m.Time.Before(s.lastRecieved) { if m.Time.Before(s.lastRecieved) {
log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time) log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)