champion.js
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const express = require('express');
const app = express();
const logger = require('morgan');
const bodyParser = require('body-parser');
const apiRouter = express.Router();
const moment = require('moment');
require('moment-timezone');
const fs = require('fs');
exports.championFunction = function(req, res) {
var responseBody = {};
const championName = req.body["action"]["params"]["champion_name"];
moment.tz.setDefault(req.body["userRequest"]["timezone"]);
console.log(moment().format('YYYY-MM-DD HH:mm:ss'));
let championRawData = fs.readFileSync('Data/Json/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
}
],
"buttons":[
{
"action": "block",
"label": "메뉴로 돌아가기",
"blockId": "5ee0eef3e0d4e2000176b3f7"
}
]
}
}
]
}
}
res.status(200).send(responseBody);
}
}