示例#1
0
// Convert a slackMessage to a bot.Message
func (s *Slack) buildMessage(msg slackMessage) bot.Message {
	log.Println("DEBUG: msg: %%#v", msg)
	text := html.UnescapeString(msg.Text)

	isCmd, text := bot.IsCmd(s.config, text)

	isAction := strings.HasPrefix(text, "/me ")
	if isAction {
		text = text[3:]
	}

	user := s.getUser(msg.User)

	return bot.Message{
		User: &bot.User{
			Name: user,
		},
		Body:    text,
		Raw:     msg.Text,
		Channel: msg.Channel,
		Command: isCmd,
		Action:  isAction,
		Host:    string(msg.Id),
	}
}
示例#2
0
文件: slack.go 项目: velour/catbase
// Convert a slackMessage to a msg.Message
func (s *Slack) buildMessage(m slackMessage) msg.Message {
	log.Printf("DEBUG: msg: %#v", m)
	text := html.UnescapeString(m.Text)

	// remove <> from URLs, URLs may also be <url|description>
	text = urlDetector.ReplaceAllString(text, "${1}://${2}")

	isCmd, text := bot.IsCmd(s.config, text)

	isAction := strings.HasPrefix(text, "/me ")
	if isAction {
		text = text[3:]
	}

	u := s.getUser(m.User)

	// I think it's horseshit that I have to do this
	ts := strings.Split(m.Ts, ".")
	sec, _ := strconv.ParseInt(ts[0], 10, 64)
	nsec, _ := strconv.ParseInt(ts[1], 10, 64)
	tstamp := time.Unix(sec, nsec)

	return msg.Message{
		User: &user.User{
			Name: u,
		},
		Body:    text,
		Raw:     m.Text,
		Channel: m.Channel,
		Command: isCmd,
		Action:  isAction,
		Host:    string(m.Id),
		Time:    tstamp,
	}
}
示例#3
0
// Builds our internal message type out of a Conn & Line from irc
func (i *Irc) buildMessage(inMsg irc.Msg) bot.Message {
	// Check for the user
	user := bot.User{
		Name: inMsg.Origin,
	}

	channel := inMsg.Args[0]
	if channel == i.config.Nick {
		channel = inMsg.Args[0]
	}

	isAction := false
	var message string
	if len(inMsg.Args) > 1 {
		message = inMsg.Args[1]

		isAction = strings.HasPrefix(message, actionPrefix)
		if isAction {
			message = strings.TrimRight(message[len(actionPrefix):], "\x01")
			message = strings.TrimSpace(message)
		}

	}

	iscmd := false
	filteredMessage := message
	if !isAction {
		iscmd, filteredMessage = bot.IsCmd(i.config, message)
	}

	msg := bot.Message{
		User:    &user,
		Channel: channel,
		Body:    filteredMessage,
		Raw:     message,
		Command: iscmd,
		Action:  isAction,
		Time:    time.Now(),
		Host:    inMsg.Host,
	}

	return msg
}