本文整理汇总了Golang中github.com/djosephsen/lazlo/lib.Broker类的典型用法代码示例。如果您正苦于以下问题:Golang Broker类的具体用法?Golang Broker怎么用?Golang Broker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Broker类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pingRun
func pingRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)(ping|syn)`, true)
for {
pm := <-cb.Chan
pm.Event.Reply(randReply())
}
}
开发者ID:rahart,项目名称:lazlo,代码行数:7,代码来源:ping.go
示例2: newQuestion
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)
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:7,代码来源:qtest.go
示例3: helpRun
func helpRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)help`, true)
for {
pm := <-cb.Chan
go getHelp(b, &pm)
}
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:7,代码来源:help.go
示例4: tableflipRun
func tableflipRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)(table)*flip(table)*`, false)
for {
pm := <-cb.Chan
pm.Event.Respond(`(╯°□°)╯︵ ┻━┻`)
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:7,代码来源:tableflip.go
示例5: 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)
}
}
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:27,代码来源:giphy.go
示例6: baconRun
func baconRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)bacon`, false)
for {
pm := <-cb.Chan
pm.Event.Respond("MMMMMMMMmmm ... omgbacon")
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:7,代码来源:bacon.go
示例7: belittleUser
func belittleUser(broker *lazlo.Broker) {
cb := broker.MessageCallback(`(?i)(belittle) (@*[\w-]+)`, true)
for {
select {
case newReq := <-cb.Chan:
go makeFunOfUser(b, newReq)
}
}
}
开发者ID:rahart,项目名称:lazlo,代码行数:9,代码来源:belittle.go
示例8: newLink
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)
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:10,代码来源:linktest.go
示例9: getHelp
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)
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:12,代码来源:help.go
示例10: 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]))
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:12,代码来源:catfacts.go
示例11: newChoice
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)
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:15,代码来源:linktest.go
示例12: rtmrun
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`,
})
}
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:15,代码来源:rtmping.go
示例13: 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)
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:15,代码来源:gifme.go
示例14: 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)
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:43,代码来源:godoc.go
示例15: 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)
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:20,代码来源:lovaAndWar.go
示例16: 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)
}
}
开发者ID:klaidliadon,项目名称:lazlo-modules,代码行数:37,代码来源:ikr.go
示例17: runTest
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)
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:12,代码来源:qtest.go
示例18: initModules
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
}
开发者ID:sharadgana,项目名称:lazlo,代码行数:11,代码来源:loadModules.go
注:本文中的github.com/djosephsen/lazlo/lib.Broker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论