minigame.py
28.1 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
#-*-coding: utf-8 -*-
import os
import sys
from flask import request
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
game_369_clap = '짝👏!'
game_369_one = '일!'
game_369_two = '이!'
game_369_three = '삼!'
game_369_four = '사!'
game_369_five = '오!'
game_369_six = '육!'
game_369_seven = '칠!'
game_369_eight = '팔!'
game_369_nine = '구!'
game_369_ten = '십!!'
def get_start_rsp_game_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, 'start_rsp_game')
contextList = []
outputList = tones.getMessageOutputList(font, 'start_rsp_game', imageUrl, 90, petName, relation)
qrList = []
qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_process_rsp_game_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()
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
outputList = []
contextList = []
qrList = []
rv = random.randrange(0,20)
if utterance == '가위✌':
if 0 <= rv < 18:
# 상대 보자기: 승리
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('보!!'))
outputList = outputList + tones.getMessageOutputList(font, 'win_rsp_game_s', imageUrl, 90, petName, relation)
qrList.append(blockQuickReply('이겼다😆!', '이겼다😆!', '5e411ec292690d0001fcc7c5'))
contextList.append(contextValue('rsp', 1, {'result': 'win'}))
elif rv == 18:
# 상대 바위: 패배
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('바위!!'))
outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif rv == 19:
# 상대 가위: 재시작
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('가위!!'))
outputList = outputList + tones.getMessageOutputList(font, 'restart_rsp_game', imageUrl, 90, petName, relation)
qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3'))
elif utterance == '바위✊':
# 상대 보: 무조건 패배
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('보!!'))
outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif utterance == '보✋':
if 0 <= rv < 16:
# 상대 보자기: 재시작
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('보!!'))
outputList = outputList + tones.getMessageOutputList(font, 'restart_rsp_game', imageUrl, 90, petName, relation)
qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3'))
qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3'))
elif 16 <= rv < 18:
# 상대 바위: 승리
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('바위!!'))
outputList = outputList + tones.getMessageOutputList(font, 'win_rsp_game_p', imageUrl, 90, petName, relation)
qrList.append(blockQuickReply('이겼다😆!', '이겼다😆!', '5e411ec292690d0001fcc7c5'))
contextList.append(contextValue('rsp', 1, {'result': 'win'}))
elif 18 <= rv < 20:
# 상대 가위: 패배
imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw'))
outputList.append(simpleText('가위!!'))
outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_rsp_game')
return ordinaryMessageType(contextList, outputList, qrList)
# 게임에 대한 보상 제공
def get_finish_rsp_game_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()
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
outputList = []
outputList = tones.getMessageOutputList(font, 'reward_rsp_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'finish_rsp_game')
return ordinaryMessageType(contextList, outputList, qrList)
def get_start_369_game_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 = []
outputList = tones.getMessageOutputList(font, 'start_369_game', imageUrl, 90, petName, relation)
qrList = []
contextList.append(contextValue('369', 1, {'result': '1'}))
qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('이!', '이!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('삼!', '삼!', '5e44e054ffa7480001f94ab4'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'start_369_game')
return ordinaryMessageType(contextList, outputList, qrList)
def get_process_369_game_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()
outputList = []
qrList = []
contextList = []
rv = random.randrange(0, 10)
if checkContextParamValue(payload, '369', 'result', '1'):
if utterance == '이!':
# 박수쳐서 계속 감: 90%
if 0 <= rv < 9:
imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, ''))
outputList.append(simpleImage(imageUrl))
outputList.append(simpleText('짝👏!'))
qrList.append(blockQuickReply('사!', '사!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('오!', '오!', '5e44e054ffa7480001f94ab4'))
contextList.append(contextValue('369', 1, {'result': '3'}))
# 까먹어서 사용자 승리: 10%
elif rv == 9:
outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '2'}))
# 사용자 패배
elif utterance == '짝👏!' or utterance == '삼!':
outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif checkContextParamValue(payload, '369', 'result', '3'):
if utterance == '사!':
# 계속 감: 60%
if 0 <= rv < 6:
outputList.append(simpleText('오!'))
qrList.append(blockQuickReply('칠!', '칠!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('육!', '육!', '5e44e054ffa7480001f94ab4'))
contextList.append(contextValue('369', 1, {'result': '5'}))
# 까먹어서 사용자 승리: 40%
elif 6 <= rv < 10:
outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '4'}))
# 사용자 패배
elif utterance == '짝👏!' or utterance == '오!':
outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif checkContextParamValue(payload, '369', 'result', '5'):
if utterance == '짝👏!':
# 계속 감: 30%
if 0 <= rv < 3:
outputList.append(simpleText('칠!'))
qrList.append(blockQuickReply('구!', '구!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('팔!', '팔!', '5e44e054ffa7480001f94ab4'))
contextList.append(contextValue('369', 1, {'result': '7'}))
# 박수 잘못쳐서 사용자 승리: 30%
elif 3 <= rv < 6:
outputList = tones.getMessageOutputList(font, 'finish_369_game_mistake', '', 0, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '6'}))
# 까먹어서 사용자 승리: 40%
elif 6 <= rv < 10:
outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '6'}))
# 사용자 패배
elif utterance == '칠!' or utterance == '육!':
outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif checkContextParamValue(payload, '369', 'result', '7'):
if utterance == '팔!':
# 계속 감: 20%
if 0 <= rv < 2:
imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, ''))
outputList.append(simpleImage(imageUrl))
outputList.append(simpleText('짝👏!'))
qrList.append(blockQuickReply('십!!', '십!!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('십일!', '십일!', '5e44e054ffa7480001f94ab4'))
qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4'))
contextList.append(contextValue('369', 1, {'result': '9'}))
# 까먹어서 사용자 승리: 80%
elif 2 <= rv < 10:
outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '8'}))
# 사용자 패배
elif utterance == '짝👏!' or utterance == '팔!':
outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
elif checkContextParamValue(payload, '369', 'result', '9'):
if utterance == '십!!':
imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, ''))
outputList = tones.getMessageOutputList(font, 'win_369_game', imageUrl, 90, petName, relation)
qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6'))
contextList.append(contextValue('369', 1, {'result': '10'}))
# 사용자 패배
elif utterance == '십일!' or '짝👏!':
outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_369_game')
return ordinaryMessageType(contextList, outputList, qrList)
# 게임에 대한 보상 제공
def get_finish_369_game_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()
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
outputList = []
outputList = tones.getMessageOutputList(font, 'reward_369_game', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'finish_369_game')
return ordinaryMessageType(contextList, outputList, qrList)
# 넌센스 퀴즈 시작
def get_start_nonsense_quiz_message():
contextList = []
qrList = []
payload = request.get_json()
utterance = getUserUtteranceFromPayload(payload)
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none')
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 한 퀴즈는 4개의 대사로 구성되어 있기 때문에 4로 나눠서 퀴즈의 갯수를 구함
quizCount = int(tones.getCountUsingIntent('cute', 'nonsense_quiz') / 4)
randomQuizNumber = str(random.randrange(1, quizCount + 1))
outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + randomQuizNumber + '_Q', imageUrl, 90, petName, relation)
answerList = tones.getKeywordListUsingIntent('cute', 'nonsense_quiz_' + randomQuizNumber + '_keyword')
contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'start', 'nonsense_quiz_number': randomQuizNumber, 'nq_answer_list': answerList}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'start_nonsense_quiz')
return ordinaryMessageType(contextList, outputList, qrList)
# 넌센스퀴즈 결과 확인
def get_process_nonsense_quiz_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
now = datetime.datetime.now()
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
outputList = []
quizNumber = getContextParamValue(payload, 'utterance', 'nonsense_quiz_number')
answers = getContextParamValue(payload, 'utterance', 'nq_answer_list')
answers = answers.replace('[', '')
answers = answers.replace(']', '')
answers = answers.replace("\"", "")
answerList = answers.split(',')
correct = False
for answer in answerList:
if answer in utterance:
correct = True
if correct:
contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'correct', 'nonsense_quiz_number': quizNumber}))
outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_O', '', 0, petName, relation)
else:
contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'incorrect', 'nonsense_quiz_number': quizNumber}))
outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_X', '', 0, petName, relation)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_nonsense_quiz')
return ordinaryMessageType(contextList, outputList, qrList)
#TODO 넌센스퀴즈 결과에 대한 보상 제공(아직 미구현)
def get_finish_nonsense_quiz_message():
contextList = []
qrList = []
outputList = []
return ordinaryMessageType(contextList, outputList, qrList)
def get_start_word_relay_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
# 펫 이미지 리스트 불러오기
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none')
contextList = []
qrList = []
outputList = tones.getMessageOutputList(font, 'start_word_relay', imageUrl, 0, petName, relation)
# 끝말잇기 대본에서 db 가져오기
words = tones.getKeywordListUsingIntent('cute', 'word_relay_db')[0][0]
keywordList = wordRelayDBList(words, petName, relation)
# 랜덤하게 하나 고르기
keyword = random.choice(keywordList)
outputList.append(simpleText(keyword+'!!'))
contextList.append(contextValue('utterance', 1, {'wr_keyword': keyword, 'word_relay': 'process', 'wr_repeat_count': 0}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'start_word_relay')
return ordinaryMessageType(contextList, outputList, qrList)
def get_process_word_relay_message():
contextList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none')
# 펫 이미지 리스트 불러오기
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 끝말잇기 대본에서 db 가져오기
words = tones.getKeywordListUsingIntent('cute', 'word_relay_db')[0][0]
keywordList = wordRelayDBList(words, petName, relation)
outputList = []
# 끝말잇기 반복한 횟수
repeatCount = int(getContextParamValue(payload, 'utterance', 'wr_repeat_count')) + 1
# 5번 반복했으면 종료
if repeatCount == 5:
outputList = tones.getMessageOutputList(font, 'perfect_win_word_relay', imageUrl, 30, petName, relation)
qrList.append(blockQuickReply('이겼다!', '이겼다!', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'win', 'wr_repeat_count': repeatCount}))
# 글자수가 한개인 경우 사용자 패배
elif len(list(utterance)) == 1:
outputList.append(simpleText(utterance + '??'))
outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation)
qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount}))
# 특수문자가 포함되어있는 경우 사용자 패배
elif '?' in utterance or '!' in utterance or '^' in utterance or ';' in utterance:
outputList.append(simpleText(utterance + '??'))
outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation)
qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount}))
# 글자수가 5초과인 경우 사용자 패배
elif len(list(utterance)) > 5:
outputList.append(simpleText(utterance + '??'))
outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation)
qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount}))
# 중간에 띄어쓰기가 있는 경우 사용자 패배
elif ' ' in utterance:
outputList.append(simpleText(utterance + '??'))
outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation)
qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount}))
# 끝말잇기 규칙에 어긋나지 않은 경우 db에서 매칭되는 단어를 찾기
else:
find = False
beforeKeyWord = getContextParamValue(payload, 'utterance', 'wr_keyword')
# 사용자가 펫이 제시한 단어에 맞지 않는 응답을 한 경우
if beforeKeyWord[-1] != utterance[0]:
outputList = tones.getMessageOutputList(font, 'lose_word_relay', imageUrl, 0, petName, relation)
qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount}))
else:
lastWord = utterance[-1]
for keyword in keywordList:
# 사용자의 응답에 펫이 이어서 끝말잇기를 진행하는 경우
if keyword[0] == lastWord:
outputList.append(simpleText(utterance + '..?'))
outputList += tones.getMessageOutputList(font, 'process_word_relay', imageUrl, 0, petName, relation)
outputList.append(simpleText(keyword + '!'))
contextList.append(contextValue('utterance', 1, {'wr_keyword': keyword, 'word_relay': 'process', 'wr_repeat_count': repeatCount}))
find = True
break
# 사용자의 응답에 펫이 응답을 하지 못하는 경우(db에서 찾지못함)
if not find:
outputList.append(simpleText(utterance + '?!'))
outputList += tones.getMessageOutputList(font, 'win_word_relay', imageUrl, 30, petName, relation)
qrList.append(blockQuickReply('이겼다!', '이겼다!', '5e5cbe0d7b777800010f7d95'))
contextList.append(contextValue('utterance', 1, {'word_relay': 'win', 'wr_repeat_count': repeatCount}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'process_word_relay')
return ordinaryMessageType(contextList, outputList, qrList)
def get_finish_word_relay_message():
contextList = []
qrList = []
outputList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
outputList += tones.getMessageOutputList(font, 'finish_word_relay', imageUrl, 90, petName, relation)
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'finish_word_relay')
return ordinaryMessageType(contextList, outputList, qrList)