장재훈

Add champion.js and item.js

1 +const express = require('express');
2 +const app = express();
3 +const logger = require('morgan');
4 +const bodyParser = require('body-parser');
5 +const apiRouter = express.Router();
6 +const fs = require('fs');
7 +
8 +exports.championFunction = function(req, res) {
9 + var responseBody = {};
10 + const championName = req.body["action"]["params"]["champion_name"];
11 + let championRawData = fs.readFileSync('data/json data/champions.json');
12 + let championData = JSON.parse(championRawData);
13 + console.log(championName);
14 + if (championName == undefined){
15 + var championList = "";
16 + for (var i = 0; i < championData.length; ++i){
17 + championList += (championData[i].name + '\n');
18 + };
19 + responseBody = {
20 + "version": "2.0",
21 + "template": {
22 + "outputs": [
23 + {
24 + "simpleText": {
25 + "text": "원하시는 챔피언 이름(줄임말 포함)을 입력하시면 해당 챔피언에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 챔피언 목록 :\n" + championList
26 +
27 + }
28 + }
29 + ]
30 + }
31 + }
32 + res.status(200).send(responseBody);
33 + }
34 +
35 + else{
36 + var i = 0;
37 + for (i; i < championData.length; ++i){
38 + if(championData[i].name == championName){
39 + break;
40 + }
41 + };
42 + const championEnglishName = championData[i].championId.substring(5).toLowerCase();
43 + responseBody = {
44 + "version": "2.0",
45 + "template": {
46 + "outputs": [
47 + {
48 + "basicCard": {
49 + "title": championName,
50 + "description": "비용 : " + championData[i].cost + "\n" + "시너지 : " + championData[i].traits,
51 + "thumbnail": {
52 + "imageUrl": "http://tft-helper.tk:23023/static/champions/" + championEnglishName + ".png"
53 + },
54 + "buttons": [
55 + {
56 + "action": "webLink",
57 + "label": "상세한 정보 확인",
58 + "webLinkUrl": "https://lolchess.gg/champions/set3.5/" + championEnglishName
59 + }
60 + ]
61 + }
62 + }
63 + ]
64 + }
65 + }
66 + res.status(200).send(responseBody);
67 + }
68 +
69 + }
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require('express');
2 +const app = express();
3 +const logger = require('morgan');
4 +const bodyParser = require('body-parser');
5 +const apiRouter = express.Router();
6 +const fs = require('fs');
7 +
8 +const itemRawData = fs.readFileSync('data/json data/items.json');
9 +const itemData = JSON.parse(itemRawData);
10 +
11 +exports.basicItemFunction = function(req,res){
12 + var responseBody = {};
13 + const itemName = req.body["action"]["params"]["basic_item_name"];
14 + if (itemName == undefined){
15 + var itemList = "";
16 + for (var i = 0; i < itemData.length; ++i){
17 + if (itemData[i].type == "basic")
18 + itemList += (itemData[i].name + '\n');
19 + };
20 + responseBody = {
21 + "version": "2.0",
22 + "template": {
23 + "outputs": [
24 + {
25 + "simpleText": {
26 + "text": "원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 기본 아이템 목록 :\n" + itemList
27 +
28 + }
29 + }
30 + ]
31 + }
32 + }
33 + res.status(200).send(responseBody);
34 + }
35 +
36 + else{
37 + var index = 0;
38 + for (index; index < itemData.length; ++index){
39 + if(itemData[index].name == itemName){
40 + break;
41 + }
42 + };
43 +
44 + var itemCombination = {};
45 + for (const elem1 in itemData[index].comination){
46 + for (var i = 0; i < itemData.length; ++i){
47 + if (itemData[i].id == elem1){
48 + for (const elem2 in itemData[i].material){
49 + for (var j = 0; j < itemData.length; ++i){
50 + if (itemData[j].id == elem2 && itemData[j].id != itemData[index].id){
51 + itemCombination += (itemData[index].name + " + " + itemData[j].name + " = " + itemData[i].name + '\n');
52 + }
53 + }
54 + }
55 +
56 + }
57 + }
58 + }
59 + responseBody = {
60 + "version": "2.0",
61 + "template": {
62 + "outputs": [
63 + {
64 + "basicCard": {
65 + "title": itemName,
66 + "description": "효과 : " + itemData[i].effect + "\n" + "조합가능한 아이템 : " + itemCombination,
67 + "thumbnail": {
68 + "imageUrl": "http://tft-helper.tk:23023/static/items/" + itemData[index].id + ".png"
69 + }
70 + }
71 + }
72 + ]
73 + }
74 + }
75 + res.status(200).send(responseBody);
76 + }
77 +}
78 +
79 +exports.completedItemFunction = function(req,res){
80 + var responseBody = {};
81 + const itemName = req.body["action"]["params"]["completed_item_name"];
82 + if (itemName == undefined){
83 + var itemList = "";
84 + for (var i = 0; i < itemData.length; ++i){
85 + if (itemData[i].type == "completed")
86 + itemList += (itemData[i].name + '\n');
87 + };
88 + responseBody = {
89 + "version": "2.0",
90 + "template": {
91 + "outputs": [
92 + {
93 + "simpleText": {
94 + "text": "원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 완성 아이템 목록 :\n" + itemList
95 +
96 + }
97 + }
98 + ]
99 + }
100 + }
101 + res.status(200).send(responseBody);
102 + }
103 +}
104 +
105 +exports.consumableItemFunction = function(req,res){
106 + var responseBody = {};
107 + const itemName = req.body["action"]["params"]["consumable_item_name"];
108 + if (itemName == undefined){
109 + responseBody = {
110 + "version": "2.0",
111 + "template": {
112 + "outputs": [
113 + {
114 + "simpleText": {
115 + "text": "원하시는 아이템 이름(줄임말 포함)을 입력하시면 해당 아이템에 대한 정보를 확인할 수 있습니다!\n현재 존재하는 완성 아이템 목록 :\n니코의 도움"
116 +
117 + }
118 + }
119 + ]
120 + }
121 + }
122 + res.status(200).send(responseBody);
123 + }
124 +}
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
...@@ -2,86 +2,22 @@ const express = require('express'); ...@@ -2,86 +2,22 @@ const express = require('express');
2 const app = express(); 2 const app = express();
3 const logger = require('morgan'); 3 const logger = require('morgan');
4 const bodyParser = require('body-parser'); 4 const bodyParser = require('body-parser');
5 -const fs = require('fs');
6 const apiRouter = express.Router(); 5 const apiRouter = express.Router();
6 +const champion = require('./champion.js')
7 +const item = require('./item.js')
7 8
9 +app.use('/static', express.static('data/Image data'));
8 app.use(logger('dev', {})); 10 app.use(logger('dev', {}));
9 app.use(bodyParser.json()); 11 app.use(bodyParser.json());
10 app.use(bodyParser.urlencoded({ 12 app.use(bodyParser.urlencoded({
11 extended: true 13 extended: true
12 })); 14 }));
13 -app.use('/static', express.static('data/Image data'));
14 -
15 app.use('/api', apiRouter); 15 app.use('/api', apiRouter);
16 - 16 +apiRouter.post('/champion', champion.championFunction);
17 - 17 +apiRouter.post('/basicItem',item.basicItemFunction);
18 -apiRouter.post('/champion', function(req, res) { 18 +apiRouter.post('/completedItem',item.completedItemFunction);
19 - console.log(req.body); 19 +apiRouter.post('/consumableItem',item.consumableItemFunction);
20 - var responseBody = {};
21 - const championName = req.body["action"]["params"]["champion_name"];
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{
47 - let championRawData = fs.readFileSync('data/json data/champions.json');
48 - let championData = JSON.parse(championRawData);
49 - var i = 0;
50 - for (i; i < championData.length; ++i){
51 - if(championData[i].name == championName){
52 - break;
53 - }
54 - };
55 - const championEnglishName = championData[i].championId.substring(5).toLowerCase();
56 - responseBody = {
57 - "version": "2.0",
58 - "template": {
59 - "outputs": [
60 - {
61 - "basicCard": {
62 - "title": championName,
63 - "description": "비용 : " + championData[i].cost + "\n" + "시너지 : " + championData[i].traits,
64 - "thumbnail": {
65 - "imageUrl": "http://tft-helper.tk:23023/static/champions/" + championEnglishName + ".png"
66 - },
67 - "buttons": [
68 - {
69 - "action": "webLink",
70 - "label": "상세한 정보 확인",
71 - "webLinkUrl": "https://lolchess.gg/champions/set3.5/" + championEnglishName
72 - }
73 - ]
74 - }
75 - }
76 - ]
77 - }
78 - }
79 - res.status(200).send(responseBody);
80 - }
81 -
82 -});
83 -
84 20
85 app.listen(23023, function() { 21 app.listen(23023, function() {
86 - console.log('Example skill server listening on port 23023!'); 22 + console.log('Skill server listening on port 23023!');
87 }); 23 });
......