command.py
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#-*-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)