diff --git a/config/config.go b/config/config.go index 15241a2..d00cb5c 100644 --- a/config/config.go +++ b/config/config.go @@ -109,7 +109,6 @@ type Config struct { MinPush int MaxPush int } - BotList map[string]bool } func init() { diff --git a/slack/slack.go b/slack/slack.go index 5dddef3..94a3dc2 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -37,6 +37,8 @@ type Slack struct { users map[string]string + myBotID string + emoji map[string]string eventReceived func(msg.Message) @@ -228,6 +230,7 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string type MessageResponse struct { OK bool `json:"ok"` Timestamp string `json:"ts"` + BotID string `json:"message.bot_id"` } var mr MessageResponse @@ -240,6 +243,8 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string return "", errors.New("failure response received") } + s.myBotID = mr.BotID + return mr.Timestamp, err } @@ -392,16 +397,8 @@ func (s *Slack) Serve() error { } switch msg.Type { case "message": - botOK := true - if msg.BotID != "" { - 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 == "" { + isItMe := s.myBotID != "" && msg.BotID != s.myBotID + if !isItMe && !msg.Hidden && msg.ThreadTs == "" { m := s.buildMessage(msg) if m.Time.Before(s.lastRecieved) { log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)