command.py 1.89 KB
#-*-coding: utf-8 -*-
import os
import sys
from flask import request
import datetime

import random

sys.path.append(os.path.dirname(os.path.dirname("main")))
from Functions.getInstance import *
from Functions.checkFunction import *
from Functions.updateDatabase import *
from Functions.messageTypes import *

import tones

def get_comeHere_message():
    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    # 유저 발화(utterance) 불러오기
    utterance = getUserUtteranceFromPayload(payload)
    # accountId 불러오기
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    # petId 불러오기
    petId = getPetId(kakaoUserKey)
    # petName 불러오기
    petName = getPetName(petId)
    # relation 불러오기
    relation = getRelation(kakaoUserKey, petId)
    # font 불러오기
    font = getFont(kakaoUserKey, petId)
    # 현재 시간 불러오기
    now = datetime.datetime.now()

    # 펫 이미지 리스트 불러오기
    category = ''
    imageUrls = getPetImageUrls(kakaoUserKey, category)
    imageUrl = getObjectByRandom(imageUrls)

    # 사용자가 보낸 메시지 messageLogs Collection에 저장
    addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
    contextList = []
    beforeUtterance = getContextParamValue(payload, 'utterance', 'before')
    try:
        repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat'))
    except:
        repeatCount = 1
    contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount)
    qrList = []
    qrList = addRandomHintQR(qrList, petName)
    qrList = qrList + basicButtonWindow(petName)
    outputList = tones.getMessageOutputList(font, 'comeHere', imageUrl, 0, petName, relation)
    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, outputList, now, 'none')
    return ordinaryMessageType(contextList, outputList, qrList)