当前位置: 首页>>代码示例>>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;未经允许,请勿转载。