Toggle navigation
Toggle navigation
This project
Loading...
Sign in
유재상
/
LoL-chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
유재상
2022-06-17 02:47:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
95f01f5d444973eaa10576192dffe4bb0c379e8d
95f01f5d
1 parent
783ea621
Error fixed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
49 deletions
app.js
app.js
View file @
95f01f5
...
...
@@ -30,6 +30,7 @@ app.post('/hook', function (req, res) {
var
timestamp
=
+
new
Date
();
request
(
summoner_url
,
function
(
error
,
response
,
body
){
var
summoner_info
=
JSON
.
parse
(
body
);
var
summoner_puuid
=
summoner_info
.
puuid
;
if
(
error
){
...
...
@@ -62,66 +63,92 @@ app.post('/hook', function (req, res) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"정확한 소환사명을 입력해주세요."
"text"
:
"정확한
한국 서버
소환사명을 입력해주세요."
}
]
}
});
}
else
{
var
recent_matches_url
=
"https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/"
+
summoner_puuid
+
"/ids?queue=420&start=0&count=5&api_key="
+
riot_api_key
;
request
(
recent_matches_url
,
function
(
error
,
response
,
body
){
var
match_ids
=
JSON
.
parse
(
body
);
var
match_info_url
=
[];
for
(
var
i
=
0
;
i
<
5
;
i
++
){
match_info_url
.
push
(
"https://asia.api.riotgames.com/lol/match/v5/matches/"
+
match_ids
[
i
]
+
"?api_key="
+
riot_api_key
);
}
request
(
match_info_url
[
4
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
if
(
timestamp
-
match_info
.
info
.
gameEndTimestamp
>
86400000
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"24시간 내에 충분한 경기가 진행되지 않았습니다."
var
recent_matches_url
=
"https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/"
+
summoner_puuid
+
"/ids?queue=420&start=0&count=5&api_key="
+
riot_api_key
;
request
(
recent_matches_url
,
function
(
error
,
response
,
body
){
var
match_ids
=
JSON
.
parse
(
body
);
if
(
IsObjLessThan5
(
match_ids
)){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"24시간 내에 충분한 솔로 랭크 경기가 진행되지 않았습니다."
}
]
}
]
}
});
}
else
{
var
wins
=
0
;
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
0
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
1
],
function
(
error
,
response
,
body
){
});
}
else
{
var
match_info_url
=
[];
for
(
var
i
=
0
;
i
<
5
;
i
++
){
match_info_url
.
push
(
"https://asia.api.riotgames.com/lol/match/v5/matches/"
+
match_ids
[
i
]
+
"?api_key="
+
riot_api_key
);
}
request
(
match_info_url
[
4
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
2
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
if
(
timestamp
-
match_info
.
info
.
gameEndTimestamp
>
86400000
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"24시간 내에 충분한 솔로 랭크 경기가 진행되지 않았습니다."
}
]
}
});
}
else
{
var
wins
=
0
;
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
3
],
function
(
error
,
response
,
body
){
request
(
match_info_url
[
0
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
Condition
(
eventObj
.
replyToken
,
wins
);
});
});
});
});
}
})
})
request
(
match_info_url
[
1
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
2
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
request
(
match_info_url
[
3
],
function
(
error
,
response
,
body
){
var
match_info
=
JSON
.
parse
(
body
);
wins
=
IsWin
(
match_info
,
summoner_puuid
,
wins
);
Condition
(
eventObj
.
replyToken
,
wins
);
});
});
});
});
}
})
}
})
}
})
res
.
sendStatus
(
200
);
...
...
@@ -191,6 +218,11 @@ function Condition(replyToken,wins){
});
}
function
IsObjLessThan5
(
obj
)
{
return
Object
.
keys
(
obj
).
length
<
5
;
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
...
...
@@ -204,4 +236,5 @@ try {
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment