本文整理汇总了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()
})
}
示例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()
})
}
}
}
}
示例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()
})
}