func (m *RoomModel) Create(room *model.Room, conn redis.Conn) error {
	m.syncing.Wait()
	//defer m.sync()

	if room.ID == "" {
		if uuid, err := uuid.NewRandom(); err != nil {
			return err
		} else {
			room.ID = uuid.String()
		}
	}

	_, err := m.save(room.ID, room, conn)
	return err
}
func (m *ThingModel) Create(thing *model.Thing, conn redis.Conn) error {
	m.syncing.Wait()
	//defer m.sync()

	if thing.ID == "" {
		if uuid, err := uuid.NewRandom(); err != nil {
			return err
		} else {
			thing.ID = uuid.String()
		}
	}

	_, err := m.save(thing.ID, thing, conn)

	return err
}
Example #3
0
func (s *SlackLink) forwardSlackMessageToChatLink(msg *slack.MessageEvent, specialAcknowledgement bool) {
	if strings.HasPrefix(msg.Text, ".") {
		msg.Text = "/" + msg.Text[1:]
	}

	minecraftAccount := s.getMinecraftFromSlack(msg.User)
	if minecraftAccount == nil {
		// They aren't associated with an account. Ignore.
		return
	}

	muuid, _ := uuid.NewRandom()

	cmi := &ChatMessageIn{
		Server:  "Slack",
		Context: muuid,
		Type:    messages.MessageType_TEXT,

		From: minecraftAccount,

		Timestamp: parseSlackTimestamp(msg.Timestamp),

		Contents: msg.Text,
	}

	s.addContextAssociation(cmi.Context, msg.Channel)
	if specialAcknowledgement {
		cleanedMessage := cmi.Contents
		if strings.HasPrefix(cleanedMessage, "#") {
			cleanedMessage = cleanedMessage[1:]
		}

		ref := slack.NewRefToMessage(msg.Channel, msg.Timestamp)
		s.addSpecialAcknowledgementContext(cmi.Context, &ref, cleanedMessage)
	}

	s.chatLinkOut <- CMIToProtoCMI(cmi)
}