장재훈

Add galaxy.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 +const galaxyRawData = fs.readFileSync('data/json data/galaxies.json');
9 +const galaxyData = JSON.parse(galaxyRawData);
10 +
11 +
12 +exports.galaxyFunction = function(req,res){
13 + var responseBody = {};
14 + const galaxyName = req.body["action"]["params"]["galaxy_name"];
15 + console.log(galaxyName);
16 + if (galaxyName == undefined){
17 + var galaxyList = "현재 시즌의 은하계 체계 목록 :\n"
18 + for (var i = 0; i < galaxyData.length; ++i){
19 + galaxyList += galaxyData[i].name + '\n';
20 + }
21 + responseBody = {
22 + "version": "2.0",
23 + "template": {
24 + "outputs": [
25 + {
26 + "simpleText": {
27 + "text": "원하시는 은하계 체계 정보를 검색하신다면 해당 체계에 대한 정보를 확인할 수 있습니다!\n\n현재 존재하는 은하계 체계 목록 :\n" + galaxyList
28 +
29 + }
30 + }
31 + ]
32 + }
33 + }
34 + res.status(200).send(responseBody);
35 + }
36 +
37 + else{
38 + var index = 0;
39 + for (index; index < galaxyData.length; ++index){
40 + if(galaxyData[index].name == galaxyName){
41 + break;
42 + }
43 + };
44 +
45 + responseBody = {
46 + "version": "2.0",
47 + "template": {
48 + "outputs": [
49 + {
50 + "basicCard": {
51 + "title": galaxyName,
52 + "description": "효과 : " + galaxyData[index].description,
53 + "thumbnail": {
54 + "imageUrl": "http://tft-helper.tk:23023/static/etc/galaxy.png"
55 + },
56 + "buttons":[
57 + {
58 + "action": "block",
59 + "label": "메뉴로 돌아가기",
60 + "blockId": "5ee0eef3e0d4e2000176b3f7"
61 + }
62 + ]
63 + }
64 + }
65 + ]
66 + }
67 + }
68 + res.status(200).send(responseBody);
69 + }
70 +};
...\ No newline at end of file ...\ No newline at end of file