suhyunpark

Make show_result methods

Showing 1 changed file with 151 additions and 38 deletions
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2019102175.oss-2021.tk"
const sslport = 23023;
var spring = 0
var summer = 0
var fall = 0
var winter = 0
var season_color = [spring, summer, fall, winter]
var files = [
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY0/MDAxNjIyNzI5NzM5NTQ5.JOX6SurxlH4Ip7rET53jG93MqyxB74mwouBh7beB7X0g.aC9QPmJmQPlFG9gMaGYJv_4uc0NZLeUI8GX0Gq6CRFUg.PNG.shinee_p98/brown.png',
......@@ -38,9 +38,8 @@ var previews = [
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY5/MDAxNjIyNzI5ODYwMjUw.Y1ancRsttM8SsbqE482zIpnrQS5HzJhzeC8YkuNav20g.5oC4Rclbpv65ntWPjdW8a_W3RgPUBQNjfRkIOoMuVkog.PNG.shinee_p98/white/preview.png',
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjkw/MDAxNjIyNzI5ODY0OTcw.r2_Ug2vWSRNnpLlOJjA_8G1Nj_RU3GxQE--0u-vxfxcg.bNJ1n-oZXx9F1YcLktt4Q3OyAiFnea0lOv_nN92XFUEg.PNG.shinee_p98/yellow/preview.png'
]
var number = [3, 5, 6, 7, 9]
var i = 0
var count = 10
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
......@@ -67,7 +66,7 @@ request.post(
},
{
"type": "text",
"text": "퍼스널 컬러 진단 테스트를 시작하시겠습니까? [Y/N]"
"text": "퍼스널 컬러 진단 테스트를 시작하려면 'start'를 입력하세요 "
}
]
}
......@@ -83,16 +82,15 @@ app.post('/hook', function (req, res) {
var source = eventObj.source;
var message = eventObj.message;
//start(eventObj.replyToken, eventObj.message.text)
test1(eventObj.replyToken, eventObj.message.text)
test2(eventObj.replyToken, eventObj.message.text)
Start(eventObj.replyToken, eventObj.message.text)
Color_Test(eventObj.replyToken, eventObj.message.text)
Get_Color(eventObj.replyToken, eventObj.message.text)
res.sendStatus(200);
});
function test1(replyToken, message) {
if (message == "Y") {
function Start(replyToken, message) {
if (message == "start") {
request.post(
{
url: TARGET_URL,
......@@ -113,12 +111,12 @@ function test1(replyToken, message) {
}, (error, response, body) => {
console.log(body)
});
}
}
function test2(replyToken, message) {
var index = 0
function Color_Test(replyToken, message) {
if (message == "1" || message == "2" || message == "3" || message == "4") {
request.post(
......@@ -134,8 +132,27 @@ function test2(replyToken, message) {
"type": "image",
"originalContentUrl": files[i],
"previewImageUrl": previews[i],
// "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
// "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
if (count == 0) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "테스트가 완료되었습니다. 결과를 확인하시겠습니까? [Y/N] "
},
],
......@@ -145,38 +162,134 @@ function test2(replyToken, message) {
});
}
if (message == "1") spring += 1
else if (message == "2") summer += 1
else if (message == "3") fall += 1
else if (message == "4") winter += 1
console.log(spring, summer, fall, winter)
i += 1
count -= 1
YourColorIs(spring, summer, fall, winter)
if (YourColorIs(spring, summer, fall, winter) == 0) console.log("봄웜")
if (YourColorIs(spring, summer, fall, winter) == 1) console.log("여름쿨")
if (YourColorIs(spring, summer, fall, winter) == 2) console.log("가을웜")
if (YourColorIs(spring, summer, fall, winter) == 3) console.log("겨울쿨")
}
function YourColorIs(spring, summer, fall, winter) {
var season_color = [spring, summer, fall, winter]
var max = season_color[0]
for (var i = 0; i < 4; i++) {
if (season_color[i] > max) {
max = season_color[i]
index = i
}
}
console.log("index", index)
return index
}
// function start(replyToken, message) {
// if (message == "Y") {
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "replyToken": replyToken,
// "messages": [
// {
// "type": "text",
// "text": "네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요"
// }
// ]
// }
// }, (error, response, body) => {
// console.log(body)
// });
// }
// }
function Get_Color(replyToken, message) {
if (message == "Y") {
if (YourColorIs(spring, summer, fall, winter) == 0) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "너는 봄웜"
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
if (YourColorIs(spring, summer, fall, winter) == 1) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "너는 여름쿨"
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
if (YourColorIs(spring, summer, fall, winter) == 2) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "너는 가을웜"
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
if (YourColorIs(spring, summer, fall, winter) == 4) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "너는 겨울쿨"
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
}
}
try {
......