• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang core.Gobot类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/collinvandyck/gesture/core.Gobot的典型用法代码示例。如果您正苦于以下问题:Golang Gobot类的具体用法?Golang Gobot怎么用?Golang Gobot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Gobot类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	bot.ListenFor("!all", func(msg core.Message, matches []string) core.Response {
		names := make([]string, 0)
		for _, name := range msg.Names() {
			if name != msg.User && name != bot.Name {
				names = append(names, name)
			}
		}
		if len(names) > 0 {
			sort.Strings(names)
			msg.Send("cc: " + strings.Join(names, " "))
		}
		return bot.Stop()
	})
}
开发者ID:blinsay,项目名称:gesture,代码行数:15,代码来源:all.go


示例2: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	prefix, found := config["prefix"].(string)
	if !found {
		log.Printf("Can't find graphite prefix!")
		return
	}

	pattern := fmt.Sprintf(`%s(\S+)`, prefix)
	bot.ListenFor(pattern, func(msg core.Message, matches []string) core.Response {
		url := matches[0]
		if !strings.HasSuffix(url, ".png") {
			msg.Ftfy(url + "&lol.png")
		}
		return bot.Stop()
	})
}
开发者ID:blinsay,项目名称:gesture,代码行数:16,代码来源:graphite.go


示例3: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	name := bot.Name

	bot.ListenFor(fmt.Sprintf("(?i)kill %s", name), func(msg core.Message, matches []string) core.Response {
		msg.Reply("EAT SHIT")
		return bot.Stop()
	})

	bot.ListenFor(fmt.Sprintf("(?i)(hey|h(a?)i|hello) %s", name), func(msg core.Message, matches []string) core.Response {
		msg.Send(fmt.Sprintf("why, hello there %s", msg.User))
		return bot.Stop()
	})
}
开发者ID:blinsay,项目名称:gesture,代码行数:13,代码来源:identity.go


示例4: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	if len(config) == 0 {
		log.Printf("No pagerduty config found")
		return
	}

	account := pagerduty.SetupAccount(config["subdomain"].(string), config["apiKey"].(string))

	bot.ListenFor("^pd (.*)", func(msg core.Message, matches []string) core.Response {
		switch matches[1] {
		case "incidents":
			params := map[string]string{
				"status": "acknowledged,triggered",
			}

			incidents, err := account.Incidents(params)
			if err != nil {
				return bot.Error(err)
			}

			msg.Send(fmt.Sprintf("There are currently %d OPEN (ack,unack) incidents.", len(incidents)))
		}

		return bot.Stop()
	})
}
开发者ID:pkwarren,项目名称:gesture,代码行数:26,代码来源:pagerduty.go


示例5: 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


示例6: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	defaultUrl, useDefault := config["default"].(string)
	exclusions := getExclusions(config)
	bot.ListenFor("^gis (.*)", func(msg core.Message, matches []string) core.Response {
		for _, ex := range exclusions {
			if ex == msg.Channel {
				return bot.Stop()
			}
		}
		link, err := search(matches[1])
		if err != nil {
			if useDefault {
				link = defaultUrl
			} else {
				return bot.Error(err)
			}
		}
		msg.Ftfy(link)
		return bot.Stop()
	})
}
开发者ID:blinsay,项目名称:gesture,代码行数:21,代码来源:gis.go


示例7: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	results, ok := config["results"].(float64)
	if !ok {
		log.Print("Failed to load config for 'youtube' plugin. Using default result count of 1")
		results = 1
	}

	bot.ListenFor("^yt (.*)", func(msg core.Message, matches []string) core.Response {
		link, err := search(matches[1], int(results))
		if err != nil {
			return bot.Error(err)
		}
		if link != "" {
			msg.Ftfy(link)
		}
		return bot.Stop()
	})
}
开发者ID:pkwarren,项目名称:gesture,代码行数:18,代码来源:youtube.go


示例8: Create

func Create(bot *core.Gobot, config map[string]interface{}) error {
	username, password, err := loadCredentials(config)
	if err != nil {
		log.Printf("Error starting up memegenerator plugin: %s", err)
		return err
	}

	fry := memeGen{username, password, fryGenerator, fryImage}

	bot.ListenFor(`(?i)(not sure|unsure) if (.*) or (.*)`, func(msg core.Message, matches []string) core.Response {
		result, err := fry.generate(matches[1]+" if "+matches[2], " or "+matches[3])
		if err != nil {
			return bot.Error(err)
		}
		if result != "" {
			msg.Reply(result)
		}
		return bot.Stop()
	})
	return nil
}
开发者ID:pkwarren,项目名称:gesture,代码行数:21,代码来源:memegenerator.go


示例9: Create

func Create(bot *core.Gobot, config map[string]interface{}) {
	if len(config) == 0 {
		log.Printf("No sensu config found")
		return
	}

	envs := make(map[string]string)
	for e, u := range config["environments"].(map[string]interface{}) {
		envs[e] = fmt.Sprintf("%s", u)
	}

	bot.ListenFor("^sensu (.*)", func(msg core.Message, matches []string) core.Response {
		cmdArgs := strings.Split(matches[1], " ")
		switch cmdArgs[0] {
		case "events":
			if len(cmdArgs) > 1 {
				if err, events := getEvents(envs[cmdArgs[1]]); err != nil {
					return bot.Error(err)
				} else {
					msg.Send(fmt.Sprintf("%s: Total events: %d.", cmdArgs[1], len(events)))

					for _, event := range events {
						msg.SendPriv(fmt.Sprintf("%s: %s", cmdArgs[1], event.toString()))
					}
				}
			} else {
				for env, url := range envs {
					if err, events := getEvents(url); err != nil {
						return bot.Error(err)
					} else {
						msg.Send(fmt.Sprintf("%s: Total events: %d.", env, len(events)))

						for _, event := range events {
							msg.SendPriv(fmt.Sprintf("%s: %s", env, event.toString()))
						}
					}
				}
			}
		case "silence":
			var (
				env    string
				target string
			)

			if len(cmdArgs) > 2 {
				env = envs[cmdArgs[1]]
				target = cmdArgs[2]
			} else {
				env = ""
				target = cmdArgs[1]
			}

			if err := silence(env, target); err != nil {
				return bot.Error(err)
			} else {
				msg.Send(fmt.Sprintf("silenced %s in env: %s", cmdArgs[2], cmdArgs[1]))
			}
		case "silenced":
			if len(cmdArgs) > 1 {
				if err, silenced := getSilenced(envs[cmdArgs[1]]); err != nil {
					return bot.Error(err)
				} else {
					msg.Send(fmt.Sprintf("%s: Total silenced: %d.", cmdArgs[1], len(silenced)))

					for _, s := range silenced {
						msg.SendPriv(fmt.Sprintf("%s: %s", cmdArgs[1], s))
					}
				}
			} else {
				for env, url := range envs {
					if err, silenced := getSilenced(url); err != nil {
						return bot.Error(err)
					} else {
						msg.Send(fmt.Sprintf("%s: Total silenced: %d.", env, len(silenced)))

						for _, s := range silenced {
							msg.SendPriv(fmt.Sprintf("%s: %s", env, s))
						}
					}
				}
			}
		case "unsilence":
			var (
				env    string
				target string
			)

			if len(cmdArgs) > 2 {
				env = envs[cmdArgs[1]]
				target = cmdArgs[2]
			} else {
				env = ""
				target = cmdArgs[1]
			}

			if err := unsilence(env, target); err != nil {
				fmt.Println(err)
			} else {
				msg.Send(fmt.Sprintf("silenced %s in env: %s", cmdArgs[2], cmdArgs[1]))
			}
//.........这里部分代码省略.........
开发者ID:pkwarren,项目名称:gesture,代码行数:101,代码来源:sensu.go


示例10: 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


示例11: 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



注:本文中的github.com/collinvandyck/gesture/core.Gobot类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang peer.CRStatesThreadsafe类代码示例发布时间:2022-05-23
下一篇:
Golang hadoop_hdfs.LocatedBlockProto类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap