本文整理匯總了Golang中github.com/djosephsen/lazlo/lib.Broker.MessageCallback方法的典型用法代碼示例。如果您正苦於以下問題:Golang Broker.MessageCallback方法的具體用法?Golang Broker.MessageCallback怎麽用?Golang Broker.MessageCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/djosephsen/lazlo/lib.Broker
的用法示例。
在下文中一共展示了Broker.MessageCallback方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: tableflipRun
func tableflipRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)(table)*flip(table)*`, false)
for {
pm := <-cb.Chan
pm.Event.Respond(`(╯°□°)╯︵ ┻━┻`)
}
}
示例2: helpRun
func helpRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)help`, true)
for {
pm := <-cb.Chan
go getHelp(b, &pm)
}
}
示例3: pingRun
func pingRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)(ping|syn)`, true)
for {
pm := <-cb.Chan
pm.Event.Reply(randReply())
}
}
示例4: getGIF
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)
}
}
}
示例5: baconRun
func baconRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)bacon`, false)
for {
pm := <-cb.Chan
pm.Event.Respond("MMMMMMMMmmm ... omgbacon")
}
}
示例6: belittleUser
func belittleUser(broker *lazlo.Broker) {
cb := broker.MessageCallback(`(?i)(belittle) (@*[\w-]+)`, true)
for {
select {
case newReq := <-cb.Chan:
go makeFunOfUser(b, newReq)
}
}
}
示例7: catFactsRun
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]))
}
}
示例8: gifmeRun
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)
}
}
示例9: goDocRun
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)
}
}
示例10: loveAndWarRun
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)
}
}
示例11: ikrRun
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)
}
}