김연우

add random sorting process

Showing 1 changed file with 44 additions and 33 deletions
1 -var express = require('express');
2 -const request = require('request');
3 -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = 'MNiReWsDC5DyJeehZ2gHoqlEVjPsno4ScaswBgXNz0lAVW3v2JizZzhF97DPKxe23jduB+YCcBum+KredegXZnxnrovFVt4fEmgeivWgxOzt/AEJ292DZfPn3uW7xrWfBZrlGXDLaL1AMIBlmwSCcwdB04t89/1O/w1cDnyilFU='
5 -const fs = require('fs');
6 -const path = require('path');
7 -const HTTPS = require('https');
8 -const domain = "2021105581.osschatbot2022.tk"
9 -const sslport = 23023;
10 1
11 var first = false; //첫 시도인지 2 var first = false; //첫 시도인지
12 var second = false; //첫번째 분류 선택했는지 3 var second = false; //첫번째 분류 선택했는지
13 var destCar = ""; 4 var destCar = "";
5 +var destination = [];
14 6
15 const bodyParser = require('body-parser'); 7 const bodyParser = require('body-parser');
16 var app = express(); 8 var app = express();
...@@ -57,7 +49,7 @@ app.post('/hook', function (req, res) { ...@@ -57,7 +49,7 @@ app.post('/hook', function (req, res) {
57 { 49 {
58 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 50 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
59 "replyToken": eventObj.replyToken, 51 "replyToken": eventObj.replyToken,
60 - "messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타 " }] 52 + "messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타\n(숫자만 입력해주세요)" }]
61 } 53 }
62 }, (error, response, body) => { 54 }, (error, response, body) => {
63 console.log(body) 55 console.log(body)
...@@ -68,7 +60,7 @@ app.post('/hook', function (req, res) { ...@@ -68,7 +60,7 @@ app.post('/hook', function (req, res) {
68 { 60 {
69 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 61 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
70 "replyToken": eventObj.replyToken, 62 "replyToken": eventObj.replyToken,
71 - "messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트" }] 63 + "messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트\n(숫자만 입력해주세요)" }]
72 } 64 }
73 }, (error, response, body) => { 65 }, (error, response, body) => {
74 console.log(body) 66 console.log(body)
...@@ -79,7 +71,7 @@ app.post('/hook', function (req, res) { ...@@ -79,7 +71,7 @@ app.post('/hook', function (req, res) {
79 { 71 {
80 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 72 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
81 "replyToken": eventObj.replyToken, 73 "replyToken": eventObj.replyToken,
82 - "messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주" }] 74 + "messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주\n(숫자만 입력해주세요)" }]
83 } 75 }
84 }, (error, response, body) => { 76 }, (error, response, body) => {
85 console.log(body) 77 console.log(body)
...@@ -90,47 +82,46 @@ app.post('/hook', function (req, res) { ...@@ -90,47 +82,46 @@ app.post('/hook', function (req, res) {
90 { 82 {
91 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 83 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
92 "replyToken": eventObj.replyToken, 84 "replyToken": eventObj.replyToken,
93 - "messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타" }] 85 + "messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타\n(숫자만 입력해주세요)" }]
94 } 86 }
95 }, (error, response, body) => { 87 }, (error, response, body) => {
96 console.log(body) 88 console.log(body)
97 }); 89 });
98 destCar = "play" 90 destCar = "play"
99 } 91 }
100 - 92 + chooseFile();
101 second = true; 93 second = true;
102 94
103 } 95 }
104 96
105 else if (first == true && second == true) { 97 else if (first == true && second == true) {
106 if (destCar == "meal") { 98 if (destCar == "meal") {
107 - if (eventObj.message.text == 1) { destination = "western"; console.log(destination) } 99 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 6); destination = results[randpick] }
108 - else if (eventObj.message.text == 2) { destination = "korean"; console.log(destination)} 100 + else if (eventObj.message.text == 2) { var randpick = randomNum(7, 19); destination = results[randpick] }
109 - else if (eventObj.message.text == 3) { destination = "chinese"; console.log(destination)} 101 + else if (eventObj.message.text == 3) { var randpick = randomNum(20, 25); destination = results[randpick] }
110 - else if (eventObj.message.text == 4) { destination = "japanese"; console.log(destination)} 102 + else if (eventObj.message.text == 4) { var randpick = randomNum(26, 36); destination = results[randpick] }
111 - else if (eventObj.message.text == 5) { destination = "meal_etc"; console.log(destination) } 103 + else if (eventObj.message.text == 5) { var randpick = randomNum(37, 46); destination = results[randpick] }
112 } 104 }
113 else if (destCar == "cafe") { 105 else if (destCar == "cafe") {
114 - if (eventObj.message.text == 1) { destination = "sns"; console.log(destination) } 106 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
115 - else if (eventObj.message.text == 2) { destination = "study"; console.log(destination)} 107 + else if (eventObj.message.text == 2) { var randpick = randomNum(6, 12); destination = results[randpick] }
116 - else if (eventObj.message.text == 3) { destination = "dessert"; console.log(destination)} 108 + else if (eventObj.message.text == 3) { var randpick = randomNum(13, 17); destination = results[randpick] }
117 } 109 }
118 else if (destCar == "bar") { 110 else if (destCar == "bar") {
119 - if (eventObj.message.text == 1) { destination = "soju"; console.log(destination) } 111 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
120 - else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)} 112 + else if (eventObj.message.text == 2) { var randpick = randomNum(6, 11); destination = results[randpick] }
121 - else if (eventObj.message.text == 3) { destination = "makgeolli"; console.log(destination)} 113 + else if (eventObj.message.text == 3) { var randpick = randomNum(12, 15); destination = results[randpick] }
122 - else if (eventObj.message.text == 4) { destination = "beer"; console.log(destination)} 114 + else if (eventObj.message.text == 4) { var randpick = randomNum(16, 20); destination = results[randpick] }
123 } 115 }
124 else if (destCar == "play") { 116 else if (destCar == "play") {
125 - if (eventObj.message.text == 1) { destination = "karaoke"; console.log(destination) } 117 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 3); destination = results[randpick] }
126 - else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)} 118 + else if (eventObj.message.text == 2) { var randpick = randomNum(4, 8); destination = results[randpick] }
127 - else if (eventObj.message.text == 3) { destination = "play_etc"; console.log(destination)} 119 + else if (eventObj.message.text == 3) { var randpick = randomNum(9, 13); destination = results[randpick] }
128 - }
129 } 120 }
130 - res.sendStatus(200);
131 121
132 122
133 - chooseFile(); 123 + }
124 + res.sendStatus(200);
134 125
135 126
136 }); 127 });
...@@ -186,4 +177,24 @@ chooseFile = function () { ...@@ -186,4 +177,24 @@ chooseFile = function () {
186 console.log(results); 177 console.log(results);
187 }); 178 });
188 } 179 }
189 - }
...\ No newline at end of file ...\ No newline at end of file
180 +}
181 +
182 +function randomNum(min, max) {
183 + var randNum = Math.floor(Math.random() * (max - min + 1)) + min;
184 + return randNum;
185 +}
186 +
187 +function getX() {
188 + return destination.x;
189 +}
190 +function getY() {
191 + return destination.y;
192 +}
193 +function getName() {
194 + return destination.name;
195 +}
196 +function getAddress() {
197 + return destination.address;
198 +}
199 +
200 +export { getX, getY, getName, getAddress }
...\ No newline at end of file ...\ No newline at end of file
......