本文整理汇总了Golang中github.com/djosephsen/hustlebot/lib.Broker类的典型用法代码示例。如果您正苦于以下问题:Golang Broker类的具体用法?Golang Broker怎么用?Golang Broker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Broker类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: helpRun
func helpRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)help`, true)
for {
pm := <-cb.Chan
go getHelp(b, &pm)
}
}
示例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)
}
示例3: pingRun
func pingRun(b *lazlo.Broker) {
cb := b.MessageCallback(`(?i)(ping|syn)`, true)
for {
pm := <-cb.Chan
pm.Event.Reply(randReply())
}
}
示例4: 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)
}
示例5: 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)
}
示例6: 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`,
})
}
}
示例7: 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)
}
示例8: 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)
return nil
}
示例9: 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)
}