Exemple #1
0
func (b *Bot) dispatchResponse(m *slack.Message) error {
	defer func() {
		if r := recover(); r != nil {
			b.Sayf(m.Channel, "there was a panic handling the message:\n> %v", r)
		}
	}()

	//b.LogIncomingMessage(m)
	user := b.FindUser(m.User)
	if user != nil {
		if m.User != "slackbot" && m.User != b.id && !user.IsBot {
			messageText := util.TrimWhitespace(core.LessMentions(m.Text))
			if core.IsUserMention(m.Text, b.id) || core.IsDM(m.Channel) {
				for _, action := range b.mentionActions {
					if core.Like(messageText, action.MessagePattern) && len(action.MessagePattern) != 0 {
						return action.Handler(b, m)
					}
				}
			}
			if b.passivesEnabled() {
				for _, action := range b.passiveActions {
					if core.Like(messageText, action.MessagePattern) && len(action.MessagePattern) != 0 {
						return action.Handler(b, m)
					}
				}
			}
		}
	}
	return nil
}
Exemple #2
0
// LogOutgoingMessage logs an outgoing message.
func (b *Bot) LogOutgoingMessage(destinationID string, components ...interface{}) {
	if core.Like(destinationID, "^C") {
		channel := b.FindChannel(destinationID)
		b.Logf("<= #%s (%s) - jarvis: %s", channel.Name, channel.ID, fmt.Sprint(components...))
	} else {
		b.Logf("<= PM - jarvis: %s", fmt.Sprint(components...))
	}
}
Exemple #3
0
func (c *Core) handleTell(b core.Bot, m *slack.Message) error {
	messageText := core.LessSpecificMention(m.Text, b.ID())
	words := strings.Split(messageText, " ")

	destinationUser := ""
	tellMessage := ""

	for x := 0; x < len(words); x++ {
		word := words[x]
		if core.Like(word, "tell") {
			continue
		} else if core.IsMention(word) {
			destinationUser = word
			tellMessage = strings.Join(words[x+1:], " ")
		}
	}
	tellMessage = core.ReplaceAny(tellMessage, "you are", "shes", "she's", "she is", "hes", "he's", "he is", "theyre", "they're", "they are")
	resultMessage := fmt.Sprintf("%s %s", destinationUser, tellMessage)
	return b.Say(m.Channel, resultMessage)
}