From 20bf8748a2ab2202d7b8e2ba76b01ce653547713 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 11 Nov 2017 11:51:50 -0500 Subject: [PATCH] slack: add whitelist for bots --- config/config.go | 1 + slack/slack.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index d00cb5c..15241a2 100644 --- a/config/config.go +++ b/config/config.go @@ -109,6 +109,7 @@ type Config struct { MinPush int MaxPush int } + BotList map[string]bool } func init() { diff --git a/slack/slack.go b/slack/slack.go index 9bd317b..2af6c36 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -134,7 +134,7 @@ type slackMessage struct { Text string `json:"text"` User string `json:"user"` Username string `json:"username"` - BotId string `json:"bot_id"` + BotID string `json:"bot_id"` Ts string `json:"ts"` ThreadTs string `json:"thread_ts"` Error struct { @@ -363,7 +363,6 @@ func (s *Slack) populateEmojiList() { func (s *Slack) receiveMessage() (slackMessage, error) { var msg []byte m := slackMessage{} - //err := websocket.JSON.Receive(s.ws, &m) err := websocket.Message.Receive(s.ws, &msg) if err != nil { log.Println("Error decoding WS message") @@ -393,7 +392,13 @@ func (s *Slack) Serve() error { } switch msg.Type { case "message": - if msg.BotId == "" && !msg.Hidden && msg.ThreadTs == "" { + botOK := true + if msg.BotID != "" { + u, _ := s.getUser(msg.User) + 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) if m.Time.Before(s.lastRecieved) { log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)