Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정윤지
/
Word_Chain_Chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
EC2 Default User
2021-12-08 17:22:37 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
57494e1dbb3caada46563aefe5738bf307c43ecd
57494e1d
1 parent
1026934b
Distinguish id being played
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
14 deletions
app.js
app.js
View file @
57494e1
...
...
@@ -21,6 +21,7 @@ app.use(bodyParser.json());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
console
.
log
(
eventObj
);
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
...
...
@@ -30,17 +31,91 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request source] '
,
source
);
console
.
log
(
'[request message]'
,
message
);
wordchain
(
eventObj
.
replyToken
,
message
.
text
);
wordchain
(
eventObj
.
replyToken
,
message
.
text
,
source
.
userId
);
res
.
sendStatus
(
200
);
});
function
wordchain
(
replyToken
,
message
)
{
var
playingId
=
[];
function
isCommand
(
message
)
{
return
message
==
'/시작'
||
message
==
'/종료'
?
true
:
false
;
}
let
letter
=
message
.
slice
(
-
1
);
function
wordchain
(
replyToken
,
message
,
userId
)
{
if
(
isCommand
(
message
)){
request
.
post
(
if
(
message
==
'/시작'
)
{
playingId
.
push
(
userId
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"게임이 시작되었습니다.\n단어를 제시해주세요"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
}
else
{
var
num
=
playingId
.
indexOf
(
userId
);
playingId
.
splice
(
num
,
1
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"게임이 종료되었습니다."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
};
}
else
{
if
(
!
playingId
.
includes
(
userId
))
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"안녕하세요. 끝말잇기봇입니다.\n-표준어 내의 명사만 가능\n\t(표준국어대사전에 근거)\n-한 글자 단어 금지\n-중복 단어 금지\n시작: '/시작', 종료: '/종료' 입력"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
}
else
{
var
word
=
message
;
let
letter
=
word
.
slice
(
-
1
);
console
.
log
(
letter
);
request
.
post
(
{
url
:
STDICT_URL
,
headers
:
{
...
...
@@ -56,11 +131,8 @@ function wordchain(replyToken, message) {
var
nextword
=
parsedData
.
channel
.
item
[
0
].
word
;
var
word_definition
=
parsedData
.
channel
.
item
[
0
].
sense
.
definition
;
request
.
post
(
{
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
...
...
@@ -70,11 +142,7 @@ function wordchain(replyToken, message) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
nextword
},
{
"type"
:
"text"
,
"text"
:
': '
+
word_definition
"text"
:
nextword
+
': '
+
word_definition
}
]
}
...
...
@@ -83,7 +151,8 @@ function wordchain(replyToken, message) {
});
}
});
}
}
}
//SSL
...
...
Please
register
or
login
to post a comment