Пример #1
0
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
0
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()
	})
}
Пример #3
0
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()
	})
}
Пример #4
0
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()
	})
}
Пример #5
0
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
}
Пример #6
0
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()
	})
}
Пример #7
0
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]))
			}
		}

		return bot.Stop()
	})
}