Exemple #1
0
func pingRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)(ping|syn)`, true)
	for {
		pm := <-cb.Chan
		pm.Event.Reply(randReply())
	}
}
Exemple #2
0
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)
}
Exemple #3
0
func helpRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)help`, true)
	for {
		pm := <-cb.Chan
		go getHelp(b, &pm)
	}
}
func tableflipRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)(table)*flip(table)*`, false)
	for {
		pm := <-cb.Chan
		pm.Event.Respond(`(╯°□°)╯︵ ┻━┻`)
	}
}
Exemple #5
0
func getGIF(b *lazlo.Broker) {
	g := giphy.DefaultClient
	str := []string{}
	cb := b.MessageCallback(`(?i)gif ((?i)search|translate) (\w+)`, false)
	for {
		pm := <-cb.Chan
		cmd := pm.Match[1]
		lazlo.Logger.Debug(cmd)
		if matched, _ := regexp.MatchString(`(?i)search`, cmd); matched {
			str := append(str, pm.Match[2])
			lazlo.Logger.Debug(str)
			resp, err := g.Search(str)
			if err != nil {
				lazlo.Logger.Error(err)
			}
			pm.Event.Reply(resp.Data[0].URL)
		} else if matched, _ := regexp.MatchString(`(?i)translate`, cmd); matched {
			str := append(str, pm.Match[2])
			lazlo.Logger.Debug(str)
			resp, err := g.Translate(str)
			if err != nil {
				lazlo.Logger.Error(err)
			}
			pm.Event.Reply(resp.Data.URL)
		}
	}
}
Exemple #6
0
func baconRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)bacon`, false)
	for {
		pm := <-cb.Chan
		pm.Event.Respond("MMMMMMMMmmm ... omgbacon")
	}
}
Exemple #7
0
func belittleUser(broker *lazlo.Broker) {
	cb := broker.MessageCallback(`(?i)(belittle) (@*[\w-]+)`, true)
	for {
		select {
		case newReq := <-cb.Chan:
			go makeFunOfUser(b, newReq)
		}
	}
}
Exemple #8
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)
}
Exemple #9
0
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)
}
Exemple #10
0
func catFactsRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)\b(cat|gato|miau|meow|garfield|lolcat)[s|z]?\b`, false)
	for {
		pm := <-cb.Chan
		data := &facts{}
		err := web.GetJSON(catFactsURL, data)
		if err != nil || len(data.Facts) == 0 {
			return
		}
		pm.Event.Respond(fmt.Sprintf("I love cats! Here's a fact: %v", data.Facts[0]))
	}
}
Exemple #11
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)
}
Exemple #12
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`,
		})
	}
}
Exemple #13
0
func gifmeRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)gif me (.*)`, true)
	for {
		pm := <-cb.Chan

		search := pm.Match[1]
		q := url.QueryEscape(search)
		myurl := fmt.Sprintf("http://api.giphy.com/v1/gifs/random?rating=pg-13&api_key=dc6zaTOxFJmzC&tag=%s", q)
		g := new(gifyout)
		resp, _ := http.Get(myurl)
		dec := json.NewDecoder(resp.Body)
		dec.Decode(g)
		pm.Event.Respond(g.Data.Image_url)
	}
}
Exemple #14
0
func goDocRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)^godoc ([^\s]+)$`, false)
	for {
		pm := <-cb.Chan
		data := &godocResults{}

		url, _ := url.Parse(godocSearchURL)
		q := url.Query()
		q.Set("q", pm.Match[1])
		url.RawQuery = q.Encode()
		err := web.GetJSON(url.String(), data)
		if err != nil {
			pm.Event.Respond(fmt.Sprintf("Error: ", err.Error()))
		}

		if len(data.Results) == 0 {
			pm.Event.Respond(noPackagesFound)
		}
		a := []lazlo.Attachment{
			lazlo.Attachment{
				Color:      "#ff0000",
				Title:      fmt.Sprintf(`Results of "%v"`, pm.Match[1]),
				MarkdownIn: []string{"fields"},
				Fields:     []lazlo.AttachmentField{},
			},
		}

		for i := 0; i < len(data.Results); i++ {
			if i == 10 {
				break
			}
			if data.Results[i].Synopsis == "" {
				data.Results[i].Synopsis = "_No description_"
			}
			a[0].Fields = append(a[0].Fields, lazlo.AttachmentField{
				Title: fmt.Sprintf("%s", data.Results[i].Path),
				Value: fmt.Sprintf("%s\n<%s/%s|full GoDoc>", data.Results[i].Synopsis, godocSiteURL, data.Results[i].Path),
			})
		}

		pm.Event.RespondAttachments(a)
	}
}
func loveAndWarRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)(love|insult) (@*\w+)$`, true)
	for {
		pm := <-cb.Chan
		var reply string
		act := pm.Match[1]
		user := pm.Match[2]
		if isme, _ := regexp.MatchString(`(?i)^me$`, user); isme {
			user = b.SlackMeta.GetUserName(pm.Event.User)
		}
		now := time.Now()
		rand.Seed(int64(now.Unix()))
		if isLove, _ := regexp.MatchString(`(?i)love`, act); isLove {
			reply = makeLove(user)
		} else if isWar, _ := regexp.MatchString(`(?i)insult`, act); isWar {
			reply = makeWar(user)
		}
		pm.Event.Respond(reply)
	}
}
Exemple #16
0
func ikrRun(b *lazlo.Broker) {
	cb := b.MessageCallback(genPattern(), false)
	for {
		pm := <-cb.Chan

		now := time.Now()
		rand.Seed(int64(now.Unix()))
		//be less annoying by only firing half the time
		if rand.Intn(100) >= 50 {
			lazlo.Logger.Debug("Let's not spam this time")
			return
		}
		replies := []string{
			"*I know right?!*",
			"*OMG* couldn't agree more",
			":+1:",
			"+1",
			":arrow_up: THAT",
			":arrow_up: you complete me :arrow_up:",
			"so true",
			"agreed.",
			"that's the fact jack",
			"YUUUUUUP",
			"that's what I'm talkin bout",
			"*IKR?!*",
			"singit",
			"^droppin the truth bombs :boom: :boom: :boom:",
			"#legit",
			"_nods emphatically in agreement_",
			"for REALZ though",
			"FOR REALSIES",
			"it's like you *literally* just read my mind right now",
		}
		reply := replies[rand.Intn(len(replies)-1)]
		pm.Event.Reply(reply)
	}
}
Exemple #17
0
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)
}
Exemple #18
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)
	b.Register(modules.Giphy)
	return nil
}