當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lib.Broker類代碼示例

本文整理匯總了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)
	}
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:7,代碼來源:help.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:evangelistcollective,項目名稱:hustlebot,代碼行數:7,代碼來源:qtest.go

示例3: pingRun

func pingRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)(ping|syn)`, true)
	for {
		pm := <-cb.Chan
		pm.Event.Reply(randReply())
	}
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:7,代碼來源:ping.go

示例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)
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:10,代碼來源:linktest.go

示例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)
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:12,代碼來源:help.go

示例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`,
		})
	}
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:15,代碼來源:rtmping.go

示例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)
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:15,代碼來源:linktest.go

示例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
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:10,代碼來源:loadModules.go

示例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)
}
開發者ID:evangelistcollective,項目名稱:hustlebot,代碼行數:12,代碼來源:qtest.go


注:本文中的github.com/djosephsen/hustlebot/lib.Broker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。