Exemplo n.º 1
0
func (c *Config) handleLoadModule(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^module:load (.+)")
	if len(parts) < 2 {
		return exception.Newf("malformed message for `%s`", ActionModuleLoad)
	}

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

	b.LoadModule(key)
	return b.Sayf(m.Channel, "Loaded Module `%s`.", key)
}