Exemple #1
0
func HandleEvent() {
	tkn := os.Getenv("SLACK_BOT_TOKEN")
	api := slack.New(tkn)
	// api.SetDebug(true)
	ctxs.NewContext(&ags.LoadPattern{}).Exec()

	rtm := api.NewRTM()
	go rtm.ManageConnection()
	go cron.Init(rtm, api)

Loop:
	for {
		select {
		case msg := <-rtm.IncomingEvents:
			// fmt.Print("Event Received: ")
			switch ev := msg.Data.(type) {
			case *slack.HelloEvent:
				// Ignore hello

			case *slack.ConnectedEvent:
				// fmt.Println("Infos:", ev.Info)
				users, _ := api.GetUsers()
				store.MakeUserMap(users)
				channels, _ := api.GetChannels(true)
				store.MakeChanMap(channels)
				msg := rtm.NewOutgoingMessage(
					"あーえー気分やわ",
					store.ChanByName("general").ID,
				)
				rtm.SendMessage(msg)

			case *slack.MessageEvent:
				fmt.Printf("Message: %v\n", ev)
				go mh.HandleMsg(ev, rtm, api)

			case *slack.PresenceChangeEvent:
				fmt.Printf("Presence Change: %v\n", ev)

			case *slack.LatencyReport:
				// fmt.Printf("Current latency: %v\n", ev.Value)

			case *slack.RTMError:
				fmt.Printf("Error: %s\n", ev.Error())

			case *slack.InvalidAuthEvent:
				fmt.Printf("Invalid credentials")
				break Loop

			default:

				// Ignore other events..
				// fmt.Printf("Unexpected: %v\n", msg.Data)
			}
		}
	}
}
Exemple #2
0
func main() {
	fmt.Println("")
	fmt.Println("")
	fmt.Println("=================================")
	fmt.Println("============ TAKOBOT ============")
	fmt.Println("=================================")
	fmt.Println("")
	fmt.Println("")

	db.InitDB()
	ctxs.NewContext(&db.Migration{}).Exec()
	go ServeStats()
	HandleEvent()
}