示例#1
0
func (templateData *MessageTemplateData) parseMessageType(sender, command, message string) {
	switch strings.ToUpper(command) {
	case "ACTION":
		templateData.class = append(templateData.class, "user-action")
		templateData.Clipboard = fmt.Sprintf("* %s %s", templateData.Sender, templateData.Message)
	case irc.JOIN:
		templateData.Message = fmt.Sprintf("joined %s", templateData.Message)
		templateData.Clipboard = fmt.Sprintf("%s %s", templateData.Sender, templateData.Message)
		templateData.class = append(templateData.class, "secondary-action", "joinpart")
	case irc.PART:
		fallthrough
	case irc.QUIT:
		templateData.Message = fmt.Sprintf("left: %s", templateData.Message)
		templateData.Clipboard = fmt.Sprintf("%s %s", templateData.Sender, templateData.Message)
		templateData.class = append(templateData.class, "secondary-action", "joinpart")
	case irc.KICK:
		index := strings.Index(message, ":")
		kicker := templateData.Sender
		sender = message[:index]
		message = message[index+1:]
		templateData.Sender = sender
		templateData.Message = fmt.Sprintf("was kicked by <b>%s</b>: <b>%s</b>", kicker, util.Linkify(html.EscapeString(message)))
		templateData.class = append(templateData.class, "secondary-action", "kick")
		templateData.Clipboard = fmt.Sprintf("%s was kicked by %s: %s", sender, kicker, message)
	case irc.MODE:
		parts := strings.Split(message, " ")
		if len(parts) > 0 {
			templateData.Message = fmt.Sprintf("set mode <b>%s</b> for <b>%s</b>", parts[0], parts[1])
			templateData.Clipboard = fmt.Sprintf("set mode %s for %s", parts[0], parts[1])
		} else {
			templateData.Message = fmt.Sprintf("set channel mode <b>%s</b>", parts[0])
			templateData.Clipboard = fmt.Sprintf("set channel mode %s", parts[0])
		}
		templateData.class = append(templateData.class, "secondary-action", "modechange")
	case irc.NICK:
		templateData.Message = fmt.Sprintf("is now known as <b>%s</b>", message)
		templateData.class = append(templateData.class, "secondary-action", "nickchange")
		templateData.Clipboard = fmt.Sprintf("%s is now known as %s", sender, message)
	case irc.TOPIC:
		templateData.Message = fmt.Sprintf("changed the topic to <b>%s</b>", message)
		templateData.class = append(templateData.class, "secondary-action", "topicchange")
		templateData.Clipboard = fmt.Sprintf("%s changed the topic to %s", sender, message)
	default:
		templateData.IsAction = false
	}
}
示例#2
0
func parseMessage(msg messages.Message) *MessageTemplateData {
	templateData := &MessageTemplateData{
		Sender:    msg.Sender,
		Date:      time.Unix(msg.Timestamp, 0).Format("15:04:05"),
		DateFull:  time.Unix(msg.Timestamp, 0).Format("Monday, 2 Jan 2006 (MST)"),
		ID:        msg.ID,
		class:     []string{"message"},
		wrapClass: []string{"message-wrapper"},
		Highlight: false,
		OwnMsg:    msg.OwnMsg,
		Joined:    TryJoinMessage(msg),
		Message:   util.Linkify(html.EscapeString(msg.Message)),
		Clipboard: msg.Message,
		Timestamp: msg.Timestamp,
		IsAction:  true,
		Preview:   PreviewTemplateData{},
	}
	templateData.parsePreview(msg.Preview)
	templateData.parseMessageType(msg.Sender, msg.Command, msg.Message)
	templateData.parseHighlight(msg.Network)
	templateData.updateTemplateVariables()

	return templateData
}