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-09 03:14:20 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c2b17cc5e6305b9443d7cc2d59ef97e9d3c51417
c2b17cc5
1 parent
b29cfe64
Correct restart error
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
19 deletions
app.js
app.js
View file @
c2b17cc
...
...
@@ -16,8 +16,6 @@ const STDICT_KEY = '14AA284251F616FF2151DBE4CD7B3D4C'
const
bodyParser
=
require
(
'body-parser'
);
const
{
json
}
=
require
(
'body-parser'
);
const
{
start
}
=
require
(
'repl'
);
const
{
exit
}
=
require
(
'process'
);
const
{
callbackify
}
=
require
(
'util'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -42,21 +40,20 @@ app.post('/hook', function (req, res) {
var
playingId
=
[];
var
words
=
[];
function
getIdindex
(
userId
)
{
return
playingId
.
indexOf
(
userId
);
}
function
exit_
(
userId
)
{
var
index
=
getIdindex
(
userId
);
playingId
.
splice
(
index
,
1
);
words
.
splice
(
index
,
1
);
playingId
.
splice
(
playingId
.
indexOf
(
userId
),
1
);
words
.
splice
(
playingId
.
indexOf
(
userId
),
1
);
console
.
log
(
playingId
);
console
.
log
(
words
);
}
function
isCommand
(
message
)
{
return
message
==
'/시작'
||
message
==
'/종료'
?
true
:
false
;
}
function
all_check
(
replyToken
,
userId
,
word
,
index
)
{
if
(
words
[
index
]
!=
0
)
{
if
(
!
check_endtoend
(
word
,
index
))
{
function
all_check
(
replyToken
,
word
,
userId
)
{
if
(
words
[
playingId
.
indexOf
(
userId
)
]
!=
0
)
{
if
(
!
check_endtoend
(
word
,
playingId
.
indexOf
(
userId
)
))
{
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -116,7 +113,7 @@ function all_check(replyToken, userId, word, index) {
'Referer'
:
'https://stdict.korean.go.kr/api/search.do'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
word
}
&`
+
'req_type=json&'
+
'advanced=y&'
+
'method=exact&'
+
'type1=word'
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
word
}
&`
+
'req_type=json&'
+
'advanced=y&'
+
'method=exact&'
+
'type1=word
&'
+
'pos=1
'
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
...
...
@@ -195,7 +192,7 @@ function all_check(replyToken, userId, word, index) {
'Referer'
:
'https://stdict.korean.go.kr/api/search.do'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
word
}
&`
+
'req_type=json&'
+
'advanced=y&'
+
'method=exact&'
+
'type1=word'
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
word
}
&`
+
'req_type=json&'
+
'advanced=y&'
+
'method=exact&'
+
'type1=word
&'
+
'pos=1
'
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
...
...
@@ -256,7 +253,12 @@ function wordchain(replyToken, message, userId) {
if
(
message
==
'/시작'
)
{
playingId
.
push
(
userId
);
words
.
push
(
0
);
words
.
splice
(
playingId
.
indexOf
(
userId
),
1
,
0
);
console
.
log
(
playingId
);
console
.
log
(
words
);
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -319,10 +321,9 @@ function wordchain(replyToken, message, userId) {
});
}
else
{
var
word
=
message
;
index
=
getIdindex
(
userId
);
var
word
=
message
;;
if
(
all_check
(
replyToken
,
userId
,
word
,
index
))
{
if
(
all_check
(
replyToken
,
word
,
userId
))
{
let
letter
=
word
.
slice
(
-
1
);
request
.
post
(
...
...
@@ -332,15 +333,17 @@ function wordchain(replyToken, message, userId) {
'Referer'
:
'https://stdict.korean.go.kr/api/search.do'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
letter
}
&`
+
'req_type=json&'
+
'
advanced=y&'
+
'method=start&'
+
'type1=word&'
+
'letter_s=2
'
body
:
`key=14AA284251F616FF2151DBE4CD7B3D4C&`
+
`q=
${
letter
}
&`
+
'req_type=json&'
+
'
start=15&'
+
'advanced=y&'
+
'method=start&'
+
'type1=word&'
+
'pos=1&'
+
'letter_s=2&'
+
'letter_e=3
'
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
try
{
console
.
log
(
body
);
const
parsedData
=
JSON
.
parse
(
body
);
var
nextword
=
parsedData
.
channel
.
item
[
0
].
word
;
var
word_definition
=
parsedData
.
channel
.
item
[
0
].
sense
.
definition
;
words
.
splice
(
getIdindex
(
userId
),
1
,
nextword
);
words
.
splice
(
playingId
.
indexOf
(
userId
),
1
,
nextword
);
console
.
log
(
words
);
request
.
post
(
{
...
...
@@ -360,6 +363,32 @@ function wordchain(replyToken, message, userId) {
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
}
catch
(
error
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"다음 단어를 찾을 수 없습니다."
},
{
"type"
:
"text"
,
"text"
:
"승리했습니다."
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
exit_
(
userId
);
return
false
;
}
}
});
}
...
...
Please
register
or
login
to post a comment