Toggle navigation
Toggle navigation
This project
Loading...
Sign in
전세계
/
FakerQuiz
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ubuntu
2020-06-21 11:39:27 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd9d6d7fe343b90535b575d353228d04a36767a9
dd9d6d7f
1 parent
2941130c
기능: 오답시 관련 정보 소개, 정답 안내 메시지 추가
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
12 deletions
app.js
app.js
View file @
dd9d6d7
...
...
@@ -23,6 +23,8 @@ var fakerData = {};
var
quizList
=
[];
var
isWaitAns
=
false
;
var
users
=
{};
var
sumOfStreak
=
0
;
var
sumOfTry
=
0
;
async
function
checkData
()
{
try
{
...
...
@@ -285,11 +287,11 @@ app.post('/hook', async function (req, res) {
quizAns
:
null
,
quizInfo
:
null
};
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
,
true
);
}
else
if
(
isWaitAns
)
{
if
(
checkAns
(
eventObj
.
source
.
userId
,
eventObj
.
message
.
text
))
{
users
[
eventObj
.
source
.
userId
].
streak
++
;
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
,
false
);
}
else
{
endQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
}
...
...
@@ -298,13 +300,32 @@ app.post('/hook', async function (req, res) {
res
.
sendStatus
(
200
);
});
function
sendQuiz
(
replyToken
,
id
)
{
function
sendQuiz
(
replyToken
,
id
,
isInit
)
{
var
randomQuiz
=
quizList
[
Math
.
floor
(
Math
.
random
()
*
quizList
.
length
)];
var
quizText
=
randomQuiz
.
quiz
;
var
messages
;
users
[
id
].
quizAns
=
randomQuiz
.
ans
;
users
[
id
].
quizInfo
=
randomQuiz
.
info
;
if
(
isInit
)
{
messages
=
[
{
"type"
:
"text"
,
"text"
:
quizText
}
];
}
else
{
messages
=
[
{
"type"
:
"text"
,
"text"
:
'정답입니다.'
},
{
"type"
:
"text"
,
"text"
:
quizText
}
];
}
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -313,12 +334,7 @@ function sendQuiz(replyToken, id) {
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
quizText
}
]
"messages"
:
messages
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
...
...
@@ -338,7 +354,9 @@ function checkAns(id, ans) {
function
endQuiz
(
replyToken
,
id
)
{
isWaitAns
=
false
;
sumOfTry
++
;
sumOfStreak
+=
users
[
id
].
streak
;
var
averageStreak
=
sumOfStreak
/
sumOfTry
;
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -350,7 +368,19 @@ function endQuiz(replyToken, id) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
`
${
users
[
id
].
streak
}
문제 연속 정답!`
"text"
:
"오답입니다."
},
{
"type"
:
"text"
,
"text"
:
users
[
id
].
quizInfo
},
{
"type"
:
"text"
,
"text"
:
`
${
users
[
id
].
streak
}
문제 연속 정답!\n(유저 평균 :
${
averageStreak
.
toFixed
(
1
)}
문제)`
},
{
"type"
:
"text"
,
"text"
:
"퀴즈를 다시 시작하려면 '시작'을 입력해주세요."
}
]
}
...
...
Please
register
or
login
to post a comment