Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장재훈
/
TFT_Chat_Bot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
장재훈
2020-06-24 22:37:30 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
018838fffa94bd2e2daa579f41370d2972934856
018838ff
1 parent
77e00369
Add champion.js and item.js
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
201 additions
and
72 deletions
data/champion.js
data/item.js
data/json data/items.json
data/main.js
data/champion.js
0 → 100644
View file @
018838f
const
express
=
require
(
'express'
);
const
app
=
express
();
const
logger
=
require
(
'morgan'
);
const
bodyParser
=
require
(
'body-parser'
);
const
apiRouter
=
express
.
Router
();
const
fs
=
require
(
'fs'
);
exports
.
championFunction
=
function
(
req
,
res
)
{
var
responseBody
=
{};
const
championName
=
req
.
body
[
"action"
][
"params"
][
"champion_name"
];
let
championRawData
=
fs
.
readFileSync
(
'data/json data/champions.json'
);
let
championData
=
JSON
.
parse
(
championRawData
);
console
.
log
(
championName
);
if
(
championName
==
undefined
){
var
championList
=
""
;
for
(
var
i
=
0
;
i
<
championData
.
length
;
++
i
){
championList
+=
(
championData
[
i
].
name
+
'\n'
);
};
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"simpleText"
:
{
"text"
:
"원하시는 챔피언 이름(줄임말 포함)을 입력하시면 해당 챔피언에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 챔피언 목록 :\n"
+
championList
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
else
{
var
i
=
0
;
for
(
i
;
i
<
championData
.
length
;
++
i
){
if
(
championData
[
i
].
name
==
championName
){
break
;
}
};
const
championEnglishName
=
championData
[
i
].
championId
.
substring
(
5
).
toLowerCase
();
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"basicCard"
:
{
"title"
:
championName
,
"description"
:
"비용 : "
+
championData
[
i
].
cost
+
"\n"
+
"시너지 : "
+
championData
[
i
].
traits
,
"thumbnail"
:
{
"imageUrl"
:
"http://tft-helper.tk:23023/static/champions/"
+
championEnglishName
+
".png"
},
"buttons"
:
[
{
"action"
:
"webLink"
,
"label"
:
"상세한 정보 확인"
,
"webLinkUrl"
:
"https://lolchess.gg/champions/set3.5/"
+
championEnglishName
}
]
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
}
\ No newline at end of file
data/item.js
0 → 100644
View file @
018838f
const
express
=
require
(
'express'
);
const
app
=
express
();
const
logger
=
require
(
'morgan'
);
const
bodyParser
=
require
(
'body-parser'
);
const
apiRouter
=
express
.
Router
();
const
fs
=
require
(
'fs'
);
const
itemRawData
=
fs
.
readFileSync
(
'data/json data/items.json'
);
const
itemData
=
JSON
.
parse
(
itemRawData
);
exports
.
basicItemFunction
=
function
(
req
,
res
){
var
responseBody
=
{};
const
itemName
=
req
.
body
[
"action"
][
"params"
][
"basic_item_name"
];
if
(
itemName
==
undefined
){
var
itemList
=
""
;
for
(
var
i
=
0
;
i
<
itemData
.
length
;
++
i
){
if
(
itemData
[
i
].
type
==
"basic"
)
itemList
+=
(
itemData
[
i
].
name
+
'\n'
);
};
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"simpleText"
:
{
"text"
:
"원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 기본 아이템 목록 :\n"
+
itemList
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
else
{
var
index
=
0
;
for
(
index
;
index
<
itemData
.
length
;
++
index
){
if
(
itemData
[
index
].
name
==
itemName
){
break
;
}
};
var
itemCombination
=
{};
for
(
const
elem1
in
itemData
[
index
].
comination
){
for
(
var
i
=
0
;
i
<
itemData
.
length
;
++
i
){
if
(
itemData
[
i
].
id
==
elem1
){
for
(
const
elem2
in
itemData
[
i
].
material
){
for
(
var
j
=
0
;
j
<
itemData
.
length
;
++
i
){
if
(
itemData
[
j
].
id
==
elem2
&&
itemData
[
j
].
id
!=
itemData
[
index
].
id
){
itemCombination
+=
(
itemData
[
index
].
name
+
" + "
+
itemData
[
j
].
name
+
" = "
+
itemData
[
i
].
name
+
'\n'
);
}
}
}
}
}
}
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"basicCard"
:
{
"title"
:
itemName
,
"description"
:
"효과 : "
+
itemData
[
i
].
effect
+
"\n"
+
"조합가능한 아이템 : "
+
itemCombination
,
"thumbnail"
:
{
"imageUrl"
:
"http://tft-helper.tk:23023/static/items/"
+
itemData
[
index
].
id
+
".png"
}
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
}
exports
.
completedItemFunction
=
function
(
req
,
res
){
var
responseBody
=
{};
const
itemName
=
req
.
body
[
"action"
][
"params"
][
"completed_item_name"
];
if
(
itemName
==
undefined
){
var
itemList
=
""
;
for
(
var
i
=
0
;
i
<
itemData
.
length
;
++
i
){
if
(
itemData
[
i
].
type
==
"completed"
)
itemList
+=
(
itemData
[
i
].
name
+
'\n'
);
};
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"simpleText"
:
{
"text"
:
"원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 완성 아이템 목록 :\n"
+
itemList
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
}
exports
.
consumableItemFunction
=
function
(
req
,
res
){
var
responseBody
=
{};
const
itemName
=
req
.
body
[
"action"
][
"params"
][
"consumable_item_name"
];
if
(
itemName
==
undefined
){
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"simpleText"
:
{
"text"
:
"원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 완성 아이템 목록 :\n니코의 도움"
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
}
\ No newline at end of file
data/json data/items.json
View file @
018838f
This diff is collapsed. Click to expand it.
data/main.js
View file @
018838f
...
...
@@ -2,86 +2,22 @@ const express = require('express');
const
app
=
express
();
const
logger
=
require
(
'morgan'
);
const
bodyParser
=
require
(
'body-parser'
);
const
fs
=
require
(
'fs'
);
const
apiRouter
=
express
.
Router
();
const
champion
=
require
(
'./champion.js'
)
const
item
=
require
(
'./item.js'
)
app
.
use
(
'/static'
,
express
.
static
(
'data/Image data'
));
app
.
use
(
logger
(
'dev'
,
{}));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
'/static'
,
express
.
static
(
'data/Image data'
));
app
.
use
(
'/api'
,
apiRouter
);
apiRouter
.
post
(
'/champion'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
body
);
var
responseBody
=
{};
const
championName
=
req
.
body
[
"action"
][
"params"
][
"champion_name"
];
console
.
log
(
championName
);
if
(
championName
==
undefined
){
var
championList
=
""
;
let
championRawData
=
fs
.
readFileSync
(
'data/json data/champions.json'
);
let
championData
=
JSON
.
parse
(
championRawData
);
for
(
var
i
=
0
;
i
<
championData
.
length
;
++
i
){
championList
+=
(
championData
[
i
].
name
+
'\n'
);
};
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"simpleText"
:
{
"text"
:
"원하시는 챔피언 이름(줄임말 포함)을 입력하시면 해당 챔피언에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 챔피언 목록 :\n"
+
championList
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
else
{
let
championRawData
=
fs
.
readFileSync
(
'data/json data/champions.json'
);
let
championData
=
JSON
.
parse
(
championRawData
);
var
i
=
0
;
for
(
i
;
i
<
championData
.
length
;
++
i
){
if
(
championData
[
i
].
name
==
championName
){
break
;
}
};
const
championEnglishName
=
championData
[
i
].
championId
.
substring
(
5
).
toLowerCase
();
responseBody
=
{
"version"
:
"2.0"
,
"template"
:
{
"outputs"
:
[
{
"basicCard"
:
{
"title"
:
championName
,
"description"
:
"비용 : "
+
championData
[
i
].
cost
+
"\n"
+
"시너지 : "
+
championData
[
i
].
traits
,
"thumbnail"
:
{
"imageUrl"
:
"http://tft-helper.tk:23023/static/champions/"
+
championEnglishName
+
".png"
},
"buttons"
:
[
{
"action"
:
"webLink"
,
"label"
:
"상세한 정보 확인"
,
"webLinkUrl"
:
"https://lolchess.gg/champions/set3.5/"
+
championEnglishName
}
]
}
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
});
apiRouter
.
post
(
'/champion'
,
champion
.
championFunction
);
apiRouter
.
post
(
'/basicItem'
,
item
.
basicItemFunction
);
apiRouter
.
post
(
'/completedItem'
,
item
.
completedItemFunction
);
apiRouter
.
post
(
'/consumableItem'
,
item
.
consumableItemFunction
);
app
.
listen
(
23023
,
function
()
{
console
.
log
(
'
Example s
kill server listening on port 23023!'
);
console
.
log
(
'
S
kill server listening on port 23023!'
);
});
...
...
Please
register
or
login
to post a comment