Skip to content

Instantly share code, notes, and snippets.

@angch
Created November 3, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angch/09b44da2288d8be00e9e245f8f11f610 to your computer and use it in GitHub Desktop.
Save angch/09b44da2288d8be00e9e245f8f11f610 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"strings"
"github.com/nlopes/slack"
)
func main() {
slack_api_token := os.Getenv("SLACK_API_TOKEN")
api := slack.New(slack_api_token)
rtm := api.NewRTM()
go rtm.ManageConnection()
for msg := range rtm.IncomingEvents {
switch ev := msg.Data.(type) {
case *slack.MessageEvent:
if ev.Msg.Edited == nil && ev.Msg.Hidden == false && strings.Contains(strings.ToLower(ev.Msg.Text), "evil") {
rtm.AddReaction("smiling_imp", slack.ItemRef{
Channel: ev.Msg.Channel,
Timestamp: ev.Msg.Timestamp,
})
}
if ev.Msg.Edited == nil && ev.Msg.Hidden == false && strings.Contains(strings.ToLower(ev.Msg.Text), "bot") {
rtm.AddReaction("robot_face", slack.ItemRef{
Channel: ev.Msg.Channel,
Timestamp: ev.Msg.Timestamp,
})
}
default:
// Ignore other events..
//fmt.Printf("Unexpected: %v\n", msg.Data)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment