Example #1
0
File: qtest.go Project: src-d/lazlo
func newQuestion(b *lazlo.Broker, req lazlo.PatternMatch) {
	lazlo.Logger.Info("new question")
	qcb := b.QuestionCallback(req.Event.User, req.Match[2])
	answer := <-qcb.Answer
	response := fmt.Sprintf("You answered: '%s'", answer)
	b.Say(response, qcb.DMChan)
}
Example #2
0
File: ping.go Project: src-d/lazlo
func pingRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)(ping|syn)`, true)
	for {
		pm := <-cb.Chan
		pm.Event.Reply(randReply())
	}
}
Example #3
0
File: help.go Project: src-d/lazlo
func helpRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)help`, true)
	for {
		pm := <-cb.Chan
		go getHelp(b, &pm)
	}
}
Example #4
0
func newLink(b *lazlo.Broker, path string, clickChan chan string) string {
	link_cb := b.LinkCallback(path)
	go func(link_cb *lazlo.LinkCallback, clickChan chan string) {
		for {
			<-link_cb.Chan
			clickChan <- link_cb.Path
		}
	}(link_cb, clickChan)
	return fmt.Sprintf("Ok, <%s|here> is a link on %s", link_cb.URL, path)
}
Example #5
0
File: help.go Project: src-d/lazlo
func getHelp(b *lazlo.Broker, pm *lazlo.PatternMatch) {
	dmChan := b.GetDM(pm.Event.User)
	reply := `########## Modules In use: `
	for _, m := range b.Modules {
		if strings.Contains(m.Usage, `%HIDDEN%`) {
			continue
		}
		usage := strings.Replace(m.Usage, `%BOTNAME%`, b.Config.Name, -1)
		reply = fmt.Sprintf("%s\n%s", reply, usage)
	}
	b.Say(reply, dmChan)
}
Example #6
0
func newChoice(b *lazlo.Broker, clickChan chan string) string {
	opt1 := b.LinkCallback(`option1`)
	opt2 := b.LinkCallback(`option2`)
	go func(opt1 *lazlo.LinkCallback, opt2 *lazlo.LinkCallback, clickChan chan string) {
		for {
			select {
			case <-opt1.Chan:
				clickChan <- `THIS`
			case <-opt2.Chan:
				clickChan <- `THAT`
			}
		}
	}(opt1, opt2, clickChan)
	return fmt.Sprintf("you can get with <%s|THIS> or you can get with <%s|THAT>", opt1.URL, opt2.URL)
}
Example #7
0
func rtmrun(b *lazlo.Broker) {
	for {
		// get a timer callback
		timer := b.TimerCallback(`*/20 * * * * * *`)

		// block waiting for an alarm from the timer
		<-timer.Chan

		//send a ping
		b.Send(&lazlo.Event{
			Type: `ping`,
			Text: `just pingin`,
		})
	}
}
Example #8
0
func initModules(b *lazlo.Broker) error {
	b.Register(modules.Syn)
	//	b.Register(modules.RTMPing)
	b.Register(modules.LinkTest)
	b.Register(modules.BrainTest)
	b.Register(modules.Help)
	b.Register(modules.LuaMod)
	b.Register(modules.QuestionTest)
	return nil
}
Example #9
0
File: qtest.go Project: src-d/lazlo
func runTest(b *lazlo.Broker, req lazlo.PatternMatch) {
	dmChan := b.GetDM(req.Event.User)
	user := b.SlackMeta.GetUserName(req.Event.User)
	b.Say(fmt.Sprintf(`hi %s! I'm going to ask you a few questions.`, user), dmChan)
	qcb := b.QuestionCallback(req.Event.User, `what is your name?`)
	name := <-qcb.Answer
	qcb = b.QuestionCallback(req.Event.User, `what is your quest?`)
	quest := <-qcb.Answer
	qcb = b.QuestionCallback(req.Event.User, `what is your favorite color?`)
	color := <-qcb.Answer
	b.Say(fmt.Sprintf(`awesome. you said your name is %s, your quest is %s and your favorite color is %s`, name, quest, color), dmChan)
}