func tableflipRun(b *lazlo.Broker) { cb := b.MessageCallback(`(?i)(table)*flip(table)*`, false) for { pm := <-cb.Chan pm.Event.Respond(`(╯°□°)╯︵ ┻━┻`) } }
func helpRun(b *lazlo.Broker) { cb := b.MessageCallback(`(?i)help`, true) for { pm := <-cb.Chan go getHelp(b, &pm) } }
func pingRun(b *lazlo.Broker) { cb := b.MessageCallback(`(?i)(ping|syn)`, true) for { pm := <-cb.Chan pm.Event.Reply(randReply()) } }
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) } } }
func baconRun(b *lazlo.Broker) { cb := b.MessageCallback(`(?i)bacon`, false) for { pm := <-cb.Chan pm.Event.Respond("MMMMMMMMmmm ... omgbacon") } }
func belittleUser(broker *lazlo.Broker) { cb := broker.MessageCallback(`(?i)(belittle) (@*[\w-]+)`, true) for { select { case newReq := <-cb.Chan: go makeFunOfUser(b, newReq) } } }
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])) } }
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) } }
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) } }
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) } }