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 10:53:43 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
563dea4e7def8cb80f4d14f76e0e3caf9b2e23cf
563dea4e
1 parent
d2aaed35
기능: userId별로 연속 정답 횟수 기록, 오답시 결과 전송
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
3 deletions
app.js
app.js
View file @
563dea4
...
...
@@ -21,6 +21,8 @@ const dataFileName = 'data.json';
var
fakerData
=
{};
var
quizList
=
[];
var
isWaitAns
=
false
;
var
users
=
{};
async
function
checkData
()
{
try
{
...
...
@@ -276,15 +278,25 @@ app.post('/hook', async function (req, res) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
eventObj
.
message
.
text
==
'시작'
)
{
if
(
!
isWaitAns
&&
eventObj
.
message
.
text
==
'시작'
)
{
await
checkData
();
sendQuiz
(
eventObj
.
replyToken
);
users
[
eventObj
.
source
.
userId
]
=
{
streak
:
0
,
quizAns
:
null
,
quizInfo
:
null
};
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
}
else
if
(
isWaitAns
&&
eventObj
.
message
.
text
==
'정답'
)
{
users
[
eventObj
.
source
.
userId
].
streak
++
;
sendQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
}
else
if
(
isWaitAns
&&
eventObj
.
message
.
text
==
'오답'
)
{
endQuiz
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
}
res
.
sendStatus
(
200
);
});
function
sendQuiz
(
replyToken
,
message
)
{
function
sendQuiz
(
replyToken
,
id
)
{
var
randomQuiz
=
quizList
[
Math
.
floor
(
Math
.
random
()
*
quizList
.
length
)];
var
quizText
=
randomQuiz
.
quiz
;
...
...
@@ -307,6 +319,32 @@ function sendQuiz(replyToken, message) {
console
.
log
(
body
)
}
);
isWaitAns
=
true
;
}
function
endQuiz
(
replyToken
,
id
)
{
isWaitAns
=
false
;
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
`
${
users
[
id
].
streak
}
문제 연속 정답!`
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
}
);
}
try
{
...
...
Please
register
or
login
to post a comment