예제 #1
0
func (a actionList) handle(message *slack.Message, command bool) bool {
	handled := false

	var action Action
	for _, action = range a {
		matches := action.Regex.FindStringSubmatch(message.Text)

		if len(matches) > 0 {
			response := action.Answerer(message)

			if response != "" {
				handled = true
				log.Printf("me-> %s", response)
				if command {
					if err := message.Respond(response); err != nil {
						// gulp!
						log.Printf("Error responding to message: %s\nwith Message: '%s'", err, response)
					}
				} else {
					if err := message.Send(response); err != nil {
						// gulp!
						log.Printf("Error responding to message: %s\nwith Message: '%s'", err, response)
					}
				}

			}
		}
	}

	return handled
}
예제 #2
0
func onAskedMessage(message *slack.Message) {
	log.Printf("%s-> %s", message.From, message.Text)

	matches := tellCommand.FindStringSubmatch(message.Text)
	if len(matches) > 0 {
		message.Tell(matches[3], matches[1]+": "+matches[4])
		return
	}

	handled := commands.handle(message, true)

	if !handled {
		var response string

		if defaultAction != nil {
			// if sentence not matched to a supported request then fallback to a default
			response = defaultAction(message)
		} else {
			response = "Je comprends pas.\n_Dis-moi_ `help` _pour avoir la liste des commandes_"
		}

		log.Printf("me-> %s", response)
		if err := message.Respond(response); err != nil {
			// gulp!
			log.Printf("Error responding to message: %s\nwith Message: '%s'", err, response)
		}
	}
}