Exemple #1
0
func (j *Jobs) handleJobEnable(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	pieces := strings.Split(messageWithoutMentions, " ")
	if len(pieces) > 1 {
		taskName := pieces[len(pieces)-1]
		b.JobManager().EnableJob(taskName)
		return b.Sayf(m.Channel, "enabled job `%s`", taskName)
	}
	return exception.New("unhandled response.")
}
Exemple #2
0
func (c *Core) handlePassiveCatchAll(b core.Bot, m *slack.Message) error {
	message := util.TrimWhitespace(core.LessMentions(m.Text))
	if optionValue, hasOption := b.Configuration()[ConfigOptionPassiveCatchAll]; hasOption && optionValue == "true" {
		if core.IsAngry(message) {
			user := b.FindUser(m.User)
			response := []string{"slow down %s", "maybe calm down %s", "%s you should really relax", "chill %s", "it's ok %s, let it out"}
			return b.Sayf(m.Channel, core.Random(response), strings.ToLower(user.Profile.FirstName))
		}
	}

	return nil
}
Exemple #3
0
func (c *Config) handleConfigGet(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^config:(.+)")

	if len(parts) < 2 {
		return exception.Newf("malformed message for `%s`", ActionConfigGet)
	}

	key := parts[1]
	value := b.Configuration()[key]
	return b.Sayf(m.Channel, "> %s: `%s` = %s", ActionConfigGet, key, value)
}
Exemple #4
0
func (j *Jobs) handleJobRun(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	pieces := strings.Split(messageWithoutMentions, " ")
	if len(pieces) > 1 {
		jobName := pieces[len(pieces)-1]
		b.JobManager().RunJob(jobName)
		return b.Sayf(m.Channel, "ran job `%s`", jobName)
	}

	b.JobManager().RunAllJobs()
	return b.Say(m.Channel, "ran all jobs")
}
Exemple #5
0
func (c *Config) handleConfigSet(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^config:(.+) (.+)")

	if len(parts) < 3 {
		return exception.Newf("malformed message for `%s`", ActionConfigSet)
	}

	key := parts[1]
	value := parts[2]

	setting := value
	if core.LikeAny(value, "true", "yes", "on", "1") {
		setting = "true"
	} else if core.LikeAny(value, "false", "off", "0") {
		setting = "false"
	}
	b.Configuration()[key] = setting
	return b.Sayf(m.Channel, "> %s: `%s` = %s", ActionConfigSet, key, setting)
}
Exemple #6
0
func (s *Stocks) handleStockPrice(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	pieces := core.ExtractSubMatches(messageWithoutMentions, "^stock:price (.*)")

	if len(pieces) < 2 {
		return exception.Newf("invalid input for %s", ActionStockPrice)
	}

	rawTicker := pieces[1]
	tickers := []string{}
	if strings.Contains(rawTicker, ",") {
		tickers = strings.Split(rawTicker, ",")
	} else {
		tickers = []string{rawTicker}
	}
	stockInfo, err := external.StockPrice(tickers)
	if err != nil {
		return err
	}
	if len(stockInfo) == 0 {
		return b.Sayf(m.Channel, "No stock information returned for: `%s`", strings.Join(tickers, ", "))
	}
	return s.announceStocks(b, m.Channel, stockInfo)
}
Exemple #7
0
func (c *Config) handleUnloadModule(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^module:unload (.+)")
	if len(parts) < 2 {
		return exception.Newf("malformed message for `%s`", ActionModuleUnload)
	}

	key := parts[1]
	if !b.LoadedModules().Contains(key) {
		return b.Sayf(m.Channel, "Module `%s` isn't loaded.", key)
	}
	if !b.RegisteredModules().Contains(key) {
		return b.Sayf(m.Channel, "Module `%s` isn't registered.", key)
	}

	b.UnloadModule(key)
	return b.Sayf(m.Channel, "Unloaded Module `%s`.", key)
}
Exemple #8
0
func (c *Core) handleUnknown(b core.Bot, m *slack.Message) error {
	return b.Sayf(m.Channel, "I don't know how to respond to this\n>%s", m.Text)
}
Exemple #9
0
func (c *Core) handleSalutation(b core.Bot, m *slack.Message) error {
	user := b.FindUser(m.User)
	salutation := []string{"hey %s", "hi %s", "hello %s", "ohayo gozaimasu %s", "salut %s", "bonjour %s", "yo %s", "sup %s"}
	return b.Sayf(m.Channel, core.Random(salutation), strings.ToLower(user.Profile.FirstName))
}