Showing
11 changed files
with
197 additions
and
78 deletions
... | @@ -84,8 +84,6 @@ function SetTeamDataDictionary(){ | ... | @@ -84,8 +84,6 @@ function SetTeamDataDictionary(){ |
84 | IDNameDict[array[i]] = array[i+1]; | 84 | IDNameDict[array[i]] = array[i+1]; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | - console.log("SetTeamDataDictionary()"); | ||
88 | - console.log(IDNameDict); | ||
89 | } | 87 | } |
90 | 88 | ||
91 | function GetTeamIDByName(teamName){ | 89 | function GetTeamIDByName(teamName){ |
... | @@ -124,5 +122,11 @@ exports.SetData = function(){ | ... | @@ -124,5 +122,11 @@ exports.SetData = function(){ |
124 | FindDataFile(); | 122 | FindDataFile(); |
125 | } | 123 | } |
126 | 124 | ||
127 | -FindDataFile(); | 125 | +exports.SearchLeague = function(){ |
126 | + return 0; | ||
127 | +} | ||
128 | + | ||
129 | +exports.SearchTeam = function(teamName){ | ||
130 | + return GetTeamIDByName(teamName); | ||
131 | +} | ||
128 | 132 | ... | ... |
... | @@ -890,6 +890,11 @@ | ... | @@ -890,6 +890,11 @@ |
890 | "node": ">=0.8" | 890 | "node": ">=0.8" |
891 | } | 891 | } |
892 | }, | 892 | }, |
893 | + "node_modules/tryparse": { | ||
894 | + "version": "0.0.2", | ||
895 | + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz", | ||
896 | + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE=" | ||
897 | + }, | ||
893 | "node_modules/tunnel-agent": { | 898 | "node_modules/tunnel-agent": { |
894 | "version": "0.6.0", | 899 | "version": "0.6.0", |
895 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | 900 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | ... | ... |
node_modules/tryparse/.npmignore
0 → 100644
node_modules/tryparse/README.md
0 → 100644
1 | +TryParse | ||
2 | +======== | ||
3 | + | ||
4 | +TryParse allows you to test if a value is an integer, a float | ||
5 | + | ||
6 | +Installation | ||
7 | +```bash | ||
8 | +npm install tryparse | ||
9 | +``` | ||
10 | + | ||
11 | +Usage | ||
12 | +```node | ||
13 | +var tryparse = require('tryparse') | ||
14 | + | ||
15 | +// Good values, as good as using parseInt or parseFloat | ||
16 | +var myInt = tryparse.int(4) | ||
17 | +> 4 | ||
18 | +var myFloat = tryparse.float(4.5) | ||
19 | +> 4.5 | ||
20 | + | ||
21 | +// Bad values, return null | ||
22 | +var notInt = tryParse.int('fhjdsk') | ||
23 | +> null | ||
24 | +var notFloat = tryParse.float('dhgjsjkg') | ||
25 | +> null | ||
26 | + | ||
27 | +// Good values as strings | ||
28 | +var myIntString = tryparse.int("4") | ||
29 | +> 4 | ||
30 | +var myFloatString = tryparse.float("4.5") | ||
31 | +> 4.5 | ||
32 | + | ||
33 | +``` | ||
34 | + | ||
35 | +Run Tests (requires tap: https://npmjs.org/package/tap) | ||
36 | +```bash | ||
37 | +npm test | ||
38 | +``` |
node_modules/tryparse/index.js
0 → 100644
1 | +function tryparse () {} | ||
2 | + | ||
3 | +tryparse.prototype.integer = tryparse.prototype.int = function (value) { | ||
4 | + return (parseInt(value) == value && parseFloat(value) !== NaN) ? parseInt(value) : null; | ||
5 | +} | ||
6 | + | ||
7 | +tryparse.prototype.float = function (value) { | ||
8 | + return (parseFloat(value) == value && parseFloat(value) !== NaN) ? parseFloat(value) : null; | ||
9 | +} | ||
10 | + | ||
11 | +module.exports = new tryparse; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
node_modules/tryparse/package.json
0 → 100644
1 | +{ | ||
2 | + "name": "tryparse", | ||
3 | + "version": "0.0.2", | ||
4 | + "description": "TryParse allows you to test if a value is an integer, a float", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "tap ./test" | ||
8 | + }, | ||
9 | + "repository": { | ||
10 | + "type": "git", | ||
11 | + "url": "git@github.com:MRdNk/TryParse.git" | ||
12 | + }, | ||
13 | + "devDependencies": { | ||
14 | + "tap": "0.4.x" | ||
15 | + }, | ||
16 | + "keywords": [ | ||
17 | + "tryparse" | ||
18 | + ], | ||
19 | + "author": "mrdnk", | ||
20 | + "license": "MIT" | ||
21 | +} |
node_modules/tryparse/test/index.js
0 → 100644
1 | +var test = require('tap').test | ||
2 | +var tryparse = require('../index.js') | ||
3 | +test("if a integer is correctly returned", function (t) { | ||
4 | + t.equal(tryparse.int(4), 4, "Is Integer") | ||
5 | + t.end() | ||
6 | +}) | ||
7 | + | ||
8 | +test("if a integer string is correctly returned", function (t) { | ||
9 | + t.equal(tryparse.int("4"), 4, "Is Integer string") | ||
10 | + t.end() | ||
11 | +}) | ||
12 | + | ||
13 | +test("if a float is correctly returned", function (t) { | ||
14 | + t.equal(tryparse.float(4.5), 4.5, "Is Float") | ||
15 | + t.end() | ||
16 | +}) | ||
17 | + | ||
18 | +test("if a float string is correctly returned", function (t) { | ||
19 | + t.equal(tryparse.float("4.5"), 4.5, "Is Float string") | ||
20 | + t.end() | ||
21 | +}) | ||
22 | + | ||
23 | +test("if a non-integer is returned as null on tryparse.int", function (t) { | ||
24 | + t.equal(tryparse.int('s'), null, "Is Not Integer") | ||
25 | + t.end() | ||
26 | +}) | ||
27 | + | ||
28 | +test("if a non-float is return as null on tryparse.float", function (t) { | ||
29 | + t.equal(tryparse.float('4q'), null, "Is Not a Float") | ||
30 | + t.end() | ||
31 | +}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -11,7 +11,8 @@ | ... | @@ -11,7 +11,8 @@ |
11 | "dependencies": { | 11 | "dependencies": { |
12 | "express": "^4.18.1", | 12 | "express": "^4.18.1", |
13 | "JSON": "^1.0.0", | 13 | "JSON": "^1.0.0", |
14 | - "request": "^2.88.2" | 14 | + "request": "^2.88.2", |
15 | + "tryparse": "^0.0.2" | ||
15 | } | 16 | } |
16 | }, | 17 | }, |
17 | "node_modules/accepts": { | 18 | "node_modules/accepts": { |
... | @@ -900,6 +901,11 @@ | ... | @@ -900,6 +901,11 @@ |
900 | "node": ">=0.8" | 901 | "node": ">=0.8" |
901 | } | 902 | } |
902 | }, | 903 | }, |
904 | + "node_modules/tryparse": { | ||
905 | + "version": "0.0.2", | ||
906 | + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz", | ||
907 | + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE=" | ||
908 | + }, | ||
903 | "node_modules/tunnel-agent": { | 909 | "node_modules/tunnel-agent": { |
904 | "version": "0.6.0", | 910 | "version": "0.6.0", |
905 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | 911 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", |
... | @@ -1663,6 +1669,11 @@ | ... | @@ -1663,6 +1669,11 @@ |
1663 | "punycode": "^2.1.1" | 1669 | "punycode": "^2.1.1" |
1664 | } | 1670 | } |
1665 | }, | 1671 | }, |
1672 | + "tryparse": { | ||
1673 | + "version": "0.0.2", | ||
1674 | + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz", | ||
1675 | + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE=" | ||
1676 | + }, | ||
1666 | "tunnel-agent": { | 1677 | "tunnel-agent": { |
1667 | "version": "0.6.0", | 1678 | "version": "0.6.0", |
1668 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | 1679 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | +var tryParse = require('tryparse'); | ||
3 | +var papago = require('./transmessage.js'); | ||
2 | const request = require('request'); | 4 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api | 5 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api |
4 | const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU=' | 6 | const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU=' |
... | @@ -30,7 +32,7 @@ app.post('/hook', function (req, res) { | ... | @@ -30,7 +32,7 @@ app.post('/hook', function (req, res) { |
30 | console.log('[request message]', eventObj.message); | 32 | console.log('[request message]', eventObj.message); |
31 | console.log("Receive Message : ", eventObj.message.text); | 33 | console.log("Receive Message : ", eventObj.message.text); |
32 | 34 | ||
33 | - GetPlayerInfo(276, 2019, eventObj); | 35 | + SelectAPI(eventObj,message.text); |
34 | 36 | ||
35 | res.sendStatus(200); | 37 | res.sendStatus(200); |
36 | }); | 38 | }); |
... | @@ -40,8 +42,6 @@ try { | ... | @@ -40,8 +42,6 @@ try { |
40 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 42 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), |
41 | key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | 43 | key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), |
42 | cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | 44 | cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), |
43 | - //key : fs.readFileSync('./rootca.key'), | ||
44 | - // cert : fs.readFileSync('./rootca.crt') | ||
45 | }; | 45 | }; |
46 | 46 | ||
47 | HTTPS.createServer(option, app).listen(sslport, () => { | 47 | HTTPS.createServer(option, app).listen(sslport, () => { |
... | @@ -54,15 +54,6 @@ try { | ... | @@ -54,15 +54,6 @@ try { |
54 | 54 | ||
55 | function Reply(eventObj,replyMsg){ | 55 | function Reply(eventObj,replyMsg){ |
56 | 56 | ||
57 | - let replyMsgJSON = JSON.parse(replyMsg); | ||
58 | - | ||
59 | - let playerMsg = JSON.stringify(replyMsgJSON.response[0].player.name); | ||
60 | - let jsonMsg = JSON.stringify(replyMsgJSON); | ||
61 | - | ||
62 | - console.log(typeof(playerMsg)); | ||
63 | - console.log("Player Message ", playerMsg); | ||
64 | - console.log("JSON Message ", jsonMsg); | ||
65 | - | ||
66 | request.post( | 57 | request.post( |
67 | { | 58 | { |
68 | url: TARGET_URL, | 59 | url: TARGET_URL, |
... | @@ -74,7 +65,7 @@ function Reply(eventObj,replyMsg){ | ... | @@ -74,7 +65,7 @@ function Reply(eventObj,replyMsg){ |
74 | "messages":[ | 65 | "messages":[ |
75 | { | 66 | { |
76 | "type":"text", | 67 | "type":"text", |
77 | - "text":playerMsg | 68 | + "text":replyMsg |
78 | }, | 69 | }, |
79 | { | 70 | { |
80 | "type":"text", | 71 | "type":"text", |
... | @@ -85,7 +76,6 @@ function Reply(eventObj,replyMsg){ | ... | @@ -85,7 +76,6 @@ function Reply(eventObj,replyMsg){ |
85 | },(error, response, body) => { | 76 | },(error, response, body) => { |
86 | console.log(body); | 77 | console.log(body); |
87 | }); | 78 | }); |
88 | - | ||
89 | } | 79 | } |
90 | 80 | ||
91 | function GetPlayerInfo(playerID, season, eventObj){ | 81 | function GetPlayerInfo(playerID, season, eventObj){ |
... | @@ -105,3 +95,54 @@ function GetPlayerInfo(playerID, season, eventObj){ | ... | @@ -105,3 +95,54 @@ function GetPlayerInfo(playerID, season, eventObj){ |
105 | Reply(eventObj,response.body); | 95 | Reply(eventObj,response.body); |
106 | }); | 96 | }); |
107 | } | 97 | } |
98 | + | ||
99 | + | ||
100 | +function SelectAPI(replyMsg){ | ||
101 | + if(tryParse.int(replyMsg) != null){ // 리그 선택 | ||
102 | + SelectLeague(tryParse.int(replyMsg)); | ||
103 | + } | ||
104 | + else{ // 팀명 입력 | ||
105 | + console.log(papago.TranslateKRtoEN(replyMsg)); | ||
106 | + } | ||
107 | + Reply(papago.TranslateKRtoEN(replyMsg)); | ||
108 | +} | ||
109 | + | ||
110 | +function SelectLeague(inputNum){ | ||
111 | + let leagueID = 0; | ||
112 | + switch(inputNum){ | ||
113 | + case 1: // 잉글랜드 프리미어리그 | ||
114 | + leagueID = 39; | ||
115 | + break; | ||
116 | + case 2: // 스페인 라리가 | ||
117 | + leagueID = 140; | ||
118 | + break; | ||
119 | + case 3: // 이탈리아 세리에 A | ||
120 | + leagueID = 135; | ||
121 | + break; | ||
122 | + case 4: // 독일 분데스리가 | ||
123 | + leagueID = 78; | ||
124 | + break; | ||
125 | + case 5: // 프랑스 리그앙 | ||
126 | + leagueID = 61; | ||
127 | + break; | ||
128 | + case 6: // 포르투칼 프리메라리가 | ||
129 | + leagueID = 94; | ||
130 | + break; | ||
131 | + case 7: // UEFA 챔피언스리그 | ||
132 | + leagueID = 2; | ||
133 | + break; | ||
134 | + case 8: // UEFA 유로파리그 | ||
135 | + leagueID = 4; | ||
136 | + break; | ||
137 | + case 9: // UEFA 컨퍼런스리그 | ||
138 | + leagueID = 848; | ||
139 | + break; | ||
140 | + case 10: // 대한민국 K리그 | ||
141 | + leagueID = 292; | ||
142 | + break; | ||
143 | + default: | ||
144 | + break; | ||
145 | + } | ||
146 | + console.log("Returned League ID : %d", leagueID); | ||
147 | + return leagueID; | ||
148 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
transmessage.js
deleted
100644 → 0
1 | -var express = require('express'); | ||
2 | -const request = require('request'); | ||
3 | -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
4 | -const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU=' | ||
5 | -const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | ||
6 | -const PAPAGO_ID = 'UZMyxEhDtcZQ4JNNeohy' | ||
7 | -const PAPAGO_SECRET = 'J2yR82NwYK' | ||
8 | -const fs = require('fs'); | ||
9 | -const path = require('path'); | ||
10 | -const HTTPS = require('https'); | ||
11 | -const domain = "2018102191.osschatbot2022.tk" | ||
12 | -const sslport = 23023; | ||
13 | -const bodyParser = require('body-parser'); | ||
14 | - | ||
15 | -var sampleReplyMsg = "players, seasons, standings, league, Son, Neymar"; | ||
16 | - | ||
17 | -function transMsg(replyMsg){ | ||
18 | - var language = "ko"; | ||
19 | - | ||
20 | - request.post( | ||
21 | - { | ||
22 | - url: PAPAGO_URL, | ||
23 | - headers: { | ||
24 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
25 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
26 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
27 | - }, | ||
28 | - body: 'source=en&target=' + language + '&text=' + replyMsg, | ||
29 | - json:true | ||
30 | - },(error, response, body) => { | ||
31 | - if(!error && response.statusCode == 200) { | ||
32 | - let transMessage = body.message.result.translatedText; | ||
33 | - console.log(transMessage); | ||
34 | - } | ||
35 | - }); | ||
36 | -} | ||
37 | - | ||
38 | -var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등" | ||
39 | - | ||
40 | -function transMsg_toEn(replyMsg){ | ||
41 | - var language = "en"; | ||
42 | - | ||
43 | - request.post( | ||
44 | - { | ||
45 | - url: PAPAGO_URL, | ||
46 | - headers: { | ||
47 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
48 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
49 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
50 | - }, | ||
51 | - body: 'source=ko&target=' + language + '&text=' + replyMsg, | ||
52 | - json:true | ||
53 | - },(error, response, body) => { | ||
54 | - if(!error && response.statusCode == 200) { | ||
55 | - let transMessage = body.message.result.translatedText; | ||
56 | - console.log(transMessage); | ||
57 | - } | ||
58 | - }); | ||
59 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment