Showing
1 changed file
with
36 additions
and
25 deletions
| ... | @@ -10,14 +10,40 @@ app.use(bodyParser.json()); | ... | @@ -10,14 +10,40 @@ app.use(bodyParser.json()); |
| 10 | app.use(bodyParser.urlencoded({ | 10 | app.use(bodyParser.urlencoded({ |
| 11 | extended: true | 11 | extended: true |
| 12 | })); | 12 | })); |
| 13 | +app.use('/static', express.static('data/Image data')); | ||
| 13 | 14 | ||
| 14 | app.use('/api', apiRouter); | 15 | app.use('/api', apiRouter); |
| 15 | 16 | ||
| 17 | + | ||
| 16 | apiRouter.post('/champion', function(req, res) { | 18 | apiRouter.post('/champion', function(req, res) { |
| 17 | - const championName = req.body["userRequest"]["utterance"]; | 19 | + console.log(req.body); |
| 18 | - const imageUrl = "data/Image data/champions/" + championName + ".png"; | 20 | + var responseBody = {}; |
| 19 | - // data/Image data/champions/갱플랭크.png | 21 | + const championName = req.body["action"]["params"]["champion_name"]; |
| 20 | - console.log(imageUrl); | 22 | + console.log(championName); |
| 23 | + if (championName == undefined){ | ||
| 24 | + var championList = ""; | ||
| 25 | + let championRawData = fs.readFileSync('data/json data/champions.json'); | ||
| 26 | + let championData = JSON.parse(championRawData); | ||
| 27 | + for (var i = 0; i < championData.length; ++i){ | ||
| 28 | + championList += (championData[i].name + '\n'); | ||
| 29 | + }; | ||
| 30 | + responseBody = { | ||
| 31 | + "version": "2.0", | ||
| 32 | + "template": { | ||
| 33 | + "outputs": [ | ||
| 34 | + { | ||
| 35 | + "simpleText": { | ||
| 36 | + "text": "원하시는 챔피언 이름(줄임말 포함)을 입력하시면 해당 챔피언에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 챔피언 목록 :\n" + championList | ||
| 37 | + | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + ] | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + res.status(200).send(responseBody); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + else{ | ||
| 21 | let championRawData = fs.readFileSync('data/json data/champions.json'); | 47 | let championRawData = fs.readFileSync('data/json data/champions.json'); |
| 22 | let championData = JSON.parse(championRawData); | 48 | let championData = JSON.parse(championRawData); |
| 23 | var i = 0; | 49 | var i = 0; |
| ... | @@ -26,8 +52,8 @@ apiRouter.post('/champion', function(req, res) { | ... | @@ -26,8 +52,8 @@ apiRouter.post('/champion', function(req, res) { |
| 26 | break; | 52 | break; |
| 27 | } | 53 | } |
| 28 | }; | 54 | }; |
| 29 | - const championQuery = championData[i].championId.substring(4); | 55 | + const championEnglishName = championData[i].championId.substring(5).toLowerCase(); |
| 30 | - const responseBody = { | 56 | + responseBody = { |
| 31 | "version": "2.0", | 57 | "version": "2.0", |
| 32 | "template": { | 58 | "template": { |
| 33 | "outputs": [ | 59 | "outputs": [ |
| ... | @@ -36,13 +62,13 @@ apiRouter.post('/champion', function(req, res) { | ... | @@ -36,13 +62,13 @@ apiRouter.post('/champion', function(req, res) { |
| 36 | "title": championName, | 62 | "title": championName, |
| 37 | "description": "비용 : " + championData[i].cost + "\n" + "시너지 : " + championData[i].traits, | 63 | "description": "비용 : " + championData[i].cost + "\n" + "시너지 : " + championData[i].traits, |
| 38 | "thumbnail": { | 64 | "thumbnail": { |
| 39 | - "imageUrl": "data/Image data/champions/" + championName + ".png" | 65 | + "imageUrl": "http://tft-helper.tk:23023/static/champions/" + championEnglishName + ".png" |
| 40 | }, | 66 | }, |
| 41 | "buttons": [ | 67 | "buttons": [ |
| 42 | { | 68 | { |
| 43 | "action": "webLink", | 69 | "action": "webLink", |
| 44 | "label": "상세한 정보 확인", | 70 | "label": "상세한 정보 확인", |
| 45 | - "webLinkUrl": "https://lolchess.gg/champions/set3.5/" + championQuery | 71 | + "webLinkUrl": "https://lolchess.gg/champions/set3.5/" + championEnglishName |
| 46 | } | 72 | } |
| 47 | ] | 73 | ] |
| 48 | } | 74 | } |
| ... | @@ -50,27 +76,12 @@ apiRouter.post('/champion', function(req, res) { | ... | @@ -50,27 +76,12 @@ apiRouter.post('/champion', function(req, res) { |
| 50 | ] | 76 | ] |
| 51 | } | 77 | } |
| 52 | } | 78 | } |
| 53 | - | ||
| 54 | res.status(200).send(responseBody); | 79 | res.status(200).send(responseBody); |
| 80 | + } | ||
| 81 | + | ||
| 55 | }); | 82 | }); |
| 56 | 83 | ||
| 57 | 84 | ||
| 58 | app.listen(23023, function() { | 85 | app.listen(23023, function() { |
| 59 | console.log('Example skill server listening on port 23023!'); | 86 | console.log('Example skill server listening on port 23023!'); |
| 60 | }); | 87 | }); |
| 61 | - | ||
| 62 | -/* | ||
| 63 | -const fs = require('fs'); | ||
| 64 | -app.post('/champion',function(req,res){ | ||
| 65 | - let championRawData = fs.readFileSync('data/json data/champions.json'); | ||
| 66 | - let championData = JSON.parse(championRawData); | ||
| 67 | - const input = "갱플랭크" | ||
| 68 | - for (var i = 0; i < championData.length; ++i){ | ||
| 69 | - if(championData[i].name == input){ | ||
| 70 | - console.log(championData[i].name) | ||
| 71 | - console.log("비용 : " + championData[i].cost) | ||
| 72 | - console.log("시너지 : " + championData[i].traits); | ||
| 73 | - } | ||
| 74 | - } | ||
| 75 | -}) | ||
| 76 | -*/ | ... | ... |
-
Please register or login to post a comment