Ubuntu

기능: 퀴즈 출제시 저장된 답과 비교하여 정답여부 결정

Showing 1 changed file with 16 additions and 3 deletions
...@@ -286,12 +286,14 @@ app.post('/hook', async function (req, res) { ...@@ -286,12 +286,14 @@ app.post('/hook', async function (req, res) {
286 quizInfo: null 286 quizInfo: null
287 }; 287 };
288 sendQuiz(eventObj.replyToken, eventObj.source.userId); 288 sendQuiz(eventObj.replyToken, eventObj.source.userId);
289 - } else if (isWaitAns && eventObj.message.text == '정답') { 289 + } else if (isWaitAns) {
290 - users[eventObj.source.userId].streak ++; 290 + if (checkAns(eventObj.source.userId, eventObj.message.text)) {
291 + users[eventObj.source.userId].streak++;
291 sendQuiz(eventObj.replyToken, eventObj.source.userId); 292 sendQuiz(eventObj.replyToken, eventObj.source.userId);
292 - } else if (isWaitAns && eventObj.message.text == '오답') { 293 + } else {
293 endQuiz(eventObj.replyToken, eventObj.source.userId); 294 endQuiz(eventObj.replyToken, eventObj.source.userId);
294 } 295 }
296 + }
295 297
296 res.sendStatus(200); 298 res.sendStatus(200);
297 }); 299 });
...@@ -300,6 +302,9 @@ function sendQuiz(replyToken, id) { ...@@ -300,6 +302,9 @@ function sendQuiz(replyToken, id) {
300 var randomQuiz = quizList[Math.floor(Math.random()*quizList.length)]; 302 var randomQuiz = quizList[Math.floor(Math.random()*quizList.length)];
301 var quizText = randomQuiz.quiz; 303 var quizText = randomQuiz.quiz;
302 304
305 + users[id].quizAns = randomQuiz.ans;
306 + users[id].quizInfo = randomQuiz.info;
307 +
303 request.post( 308 request.post(
304 { 309 {
305 url: TARGET_URL, 310 url: TARGET_URL,
...@@ -323,6 +328,14 @@ function sendQuiz(replyToken, id) { ...@@ -323,6 +328,14 @@ function sendQuiz(replyToken, id) {
323 isWaitAns = true; 328 isWaitAns = true;
324 } 329 }
325 330
331 +function checkAns(id, ans) {
332 + if (ans.toUpperCase() == users[id].quizAns.toUpperCase()) {
333 + return true;
334 + } else {
335 + return false;
336 + }
337 +}
338 +
326 function endQuiz(replyToken, id) { 339 function endQuiz(replyToken, id) {
327 isWaitAns = false; 340 isWaitAns = false;
328 341
......