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


Golang Gobot.KeepGoing方法代碼示例

本文整理匯總了Golang中github.com/collinvandyck/gesture/core.Gobot.KeepGoing方法的典型用法代碼示例。如果您正苦於以下問題:Golang Gobot.KeepGoing方法的具體用法?Golang Gobot.KeepGoing怎麽用?Golang Gobot.KeepGoing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/collinvandyck/gesture/core.Gobot的用法示例。


在下文中一共展示了Gobot.KeepGoing方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	token, ok := config["token"].(string)
	if !ok {
		log.Println("Could not find token in config. Twitter plugin won't work")
		return
	}

	bot.ListenFor("^describe (\\w+)", func(msg core.Message, matches []string) core.Response {
		described, err := describe(token, matches[1])
		if err != nil {
			return bot.Error(err)
		}
		msg.Send(described)
		return bot.Stop()
	})

	bot.ListenFor("twitter\\.com/(\\w+)/status/(\\d+)", func(msg core.Message, matches []string) core.Response {
		user, tweet, err := getTweet(token, matches[2])
		if err != nil {
			return bot.Error(err)
		}
		if err == nil && tweet != "" {
			// Split multi-line tweets into separate PRIVMSG calls
			fields := strings.FieldsFunc(tweet, func(r rune) bool {
				return r == '\r' || r == '\n'
			})
			for _, field := range fields {
				if field != "" {
					msg.Send(fmt.Sprintf("%s: %s", user, field))
				}
			}
		}
		return bot.KeepGoing()
	})
}
開發者ID:blinsay,項目名稱:gesture,代碼行數:35,代碼來源:twitter.go

示例2: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	// matches is actually a map[string]string
	matches, found := config["matches"]
	if !found {
		log.Printf("Can't find matcher/matches plugin conf. Plugin will not run.")
		return
	}

	switch matches := matches.(type) {
	case map[string]interface{}:
		for pattern, replacement := range matches {
			switch replacement := replacement.(type) {
			case string:
				bot.ListenFor(pattern, func(msg core.Message, matches []string) core.Response {
					msg.Send(replacement)
					return bot.KeepGoing()
				})
			}
		}
	}

}
開發者ID:pkwarren,項目名稱:gesture,代碼行數:22,代碼來源:matcher.go

示例3: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	if err := pluginState.Load(&markov); err != nil {
		log.Printf("Could not load plugin state: %s", err)
	}

	bot.ListenFor("^ *markov *$", func(msg core.Message, matches []string) core.Response {
		mutex.Lock()
		defer mutex.Unlock()
		output, err := generateRandom()
		if err != nil {
			return bot.Error(err)
		}
		msg.Send(output)
		return bot.KeepGoing()
	})

	// generate a chain for the specified user
	bot.ListenFor("^ *markov +(.+)", func(msg core.Message, matches []string) core.Response {
		mutex.Lock()
		defer mutex.Unlock()
		output, err := generate(matches[1])
		if err != nil {
			return bot.Error(err)
		}
		msg.Send(output)
		return bot.KeepGoing()
	})

	// listen to everything
	bot.ListenFor("(.*)", func(msg core.Message, matches []string) core.Response {
		mutex.Lock()
		defer mutex.Unlock()
		user := msg.User
		text := matches[0]
		record(user, text)
		return bot.KeepGoing()
	})
}
開發者ID:blinsay,項目名稱:gesture,代碼行數:38,代碼來源:markov.go


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