func Listen(db *sql.DB, token string) chan []string {
	// Prepared MySQL statements. The actual SQL queries are defined as constants.
	if setUserStmt, err = db.Prepare(setUserQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare set user: %v", err))
	}
	if setSwStmt, err = db.Prepare(setSwQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare set software: %v", err))
	}
	if getUserStm, err = db.Prepare(getUserQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare get user: %v", err))
	}

	s := make(chan []string)
	api := slack.New(token)
	rtm := api.NewRTM()
	go rtm.ManageConnection()

	go func(chan []string) {
	Loop:
		for {
			select {
			case msg := <-rtm.IncomingEvents:
				// fmt.Println("Event Received: ")
				switch ev := msg.Data.(type) {
				case *slack.HelloEvent:
					// Ignore hello
				case *slack.ConnectedEvent:
					// fmt.Println("Infos:", ev.Info)
					// fmt.Println("Connection counter:", ev.ConnectionCount)
					rtm.SendMessage(rtm.NewOutgoingMessage("Hello again!", "#go-testing"))
				case *slack.MessageEvent:
					// fmt.Printf("Message: %v\n", ev)
					info := rtm.GetInfo()
					botuser := info.User.ID
					// Set a prefix that should be met in order to warrant a response from us
					prefix := fmt.Sprintf("<@%s> ", botuser)
					// If the original message wasn’t posted by our bot AND it contains our
					// prefix @botuser, then we’ll respond to the channel.
					// if ev.User != botuser && strings.HasPrefix(ev.Text, prefix) {
					//	rtm.SendMessage(rtm.NewOutgoingMessage("What's up buddy!?!?", ev.Channel))
					// }
					if ev.User != info.User.ID && strings.HasPrefix(ev.Text, prefix) {
						respond(rtm, ev, prefix, s)
					}
				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.Println("Invalid credentials")
					close(s)
					break Loop

				default:
					// Ignore other events..
				}
			}
		}
	}(s)
	return s
}
// Listen receives Slack events and triggers actions.
Listen receives Slack events and triggers actions.
// Listen receives Slack events and triggers actions .
func Listen(db *sql.DB, token string) chan []string {
	if setUserStmt, err = db.Prepare(setUserQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare set user: %v", err))
	}
	if setSwStmt, err = db.Prepare(setSwQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare set software: %v", err))
	}
	if getUserStm, err = db.Prepare(getUserQ); err != nil {
		log.Fatal(fmt.Errorf("mysql: prepare get user: %v", err))
	}
	s := make(chan []string)
	api := slack.New(token)
	rtm := api.NewRTM()
	go rtm.ManageConnection()
	go func(chan []string) {
	Loop:
		for {
			select {
			case msg := <-rtm.IncomingEvents:
				switch ev := msg.Data.(type) {
				case *slack.HelloEvent:
				case *slack.ConnectedEvent:
					rtm.SendMessage(rtm.NewOutgoingMessage("Hello again!", "#go-testing"))
				case *slack.MessageEvent:
					info := rtm.GetInfo()
					botuser := info.User.ID
					prefix := fmt.Sprintf("<@%s> ", botuser)
					if ev.User != info.User.ID && strings.HasPrefix(ev.Text, prefix) {
						respond(rtm, ev, prefix, s)
					}
				case *slack.PresenceChangeEvent:
				case *slack.LatencyReport:
				case *slack.RTMError:
					fmt.Printf("Error: %s\n", ev.Error())
				case *slack.InvalidAuthEvent:
					fmt.Println("Invalid credentials")
					close(s)
					break Loop
				default:
				}
			}
		}
	}(s)
	return s
}
func Listen ( db * sql . DB , token string ) chan [ ] string { if setUserStmt , err = db . Prepare ( setUserQ ) ; err != nil { log . Fatal ( fmt . Errorf ( " " , err ) ) } if setSwStmt , err = db . Prepare ( setSwQ ) ; err != nil { log . Fatal ( fmt . Errorf ( " " , err ) ) } if getUserStm , err = db . Prepare ( getUserQ ) ; err != nil { log . Fatal ( fmt . Errorf ( " " , err ) ) } s := make ( chan [ ] string ) api := slack . New ( token ) rtm := api . NewRTM ( ) go rtm . ManageConnection ( ) go func ( chan [ ] string ) { Loop : for { select { case msg := <- rtm . IncomingEvents : switch ev := msg . Data . ( type ) { case * slack . HelloEvent : case * slack . ConnectedEvent : rtm . SendMessage ( rtm . NewOutgoingMessage ( " " , " " ) ) case * slack . MessageEvent : info := rtm . GetInfo ( ) botuser := info . User . ID prefix := fmt . Sprintf ( " " , botuser ) if ev . User != info . User . ID && strings . HasPrefix ( ev . Text , prefix ) { respond ( rtm , ev , prefix , s ) } case * slack . PresenceChangeEvent : case * slack . LatencyReport : case * slack . RTMError : fmt . Printf ( " \n " , ev . Error ( ) ) case * slack . InvalidAuthEvent : fmt . Println ( " " ) close ( s ) break Loop default : } } } } ( s ) return s }
Listen receives Slack events and triggers actions.
Listen receives Slack events and triggers actions .
// Prepared MySQL statements. The actual SQL queries are defined as constants. // fmt.Println("Event Received: ") // Ignore hello // fmt.Println("Infos:", ev.Info) // fmt.Println("Connection counter:", ev.ConnectionCount) // fmt.Printf("Message: %v\n", ev) // Set a prefix that should be met in order to warrant a response from us // If the original message wasn’t posted by our bot AND it contains our // prefix @botuser, then we’ll respond to the channel. // if ev.User != botuser && strings.HasPrefix(ev.Text, prefix) { //	rtm.SendMessage(rtm.NewOutgoingMessage("What's up buddy!?!?", ev.Channel)) // } // fmt.Printf("Presence Change: %v\n", ev) // fmt.Printf("Current latency: %v\n", ev.Value) // Ignore other events..