박찬수

all commit

......@@ -84,8 +84,6 @@ function SetTeamDataDictionary(){
IDNameDict[array[i]] = array[i+1];
}
}
console.log("SetTeamDataDictionary()");
console.log(IDNameDict);
}
function GetTeamIDByName(teamName){
......@@ -124,5 +122,11 @@ exports.SetData = function(){
FindDataFile();
}
FindDataFile();
exports.SearchLeague = function(){
return 0;
}
exports.SearchTeam = function(teamName){
return GetTeamIDByName(teamName);
}
......
......@@ -890,6 +890,11 @@
"node": ">=0.8"
}
},
"node_modules/tryparse": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
"integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
},
"node_modules/tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
......
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
npm-debug.log
node_modules/
TryParse
========
TryParse allows you to test if a value is an integer, a float
Installation
```bash
npm install tryparse
```
Usage
```node
var tryparse = require('tryparse')
// Good values, as good as using parseInt or parseFloat
var myInt = tryparse.int(4)
> 4
var myFloat = tryparse.float(4.5)
> 4.5
// Bad values, return null
var notInt = tryParse.int('fhjdsk')
> null
var notFloat = tryParse.float('dhgjsjkg')
> null
// Good values as strings
var myIntString = tryparse.int("4")
> 4
var myFloatString = tryparse.float("4.5")
> 4.5
```
Run Tests (requires tap: https://npmjs.org/package/tap)
```bash
npm test
```
function tryparse () {}
tryparse.prototype.integer = tryparse.prototype.int = function (value) {
return (parseInt(value) == value && parseFloat(value) !== NaN) ? parseInt(value) : null;
}
tryparse.prototype.float = function (value) {
return (parseFloat(value) == value && parseFloat(value) !== NaN) ? parseFloat(value) : null;
}
module.exports = new tryparse;
\ No newline at end of file
{
"name": "tryparse",
"version": "0.0.2",
"description": "TryParse allows you to test if a value is an integer, a float",
"main": "index.js",
"scripts": {
"test": "tap ./test"
},
"repository": {
"type": "git",
"url": "git@github.com:MRdNk/TryParse.git"
},
"devDependencies": {
"tap": "0.4.x"
},
"keywords": [
"tryparse"
],
"author": "mrdnk",
"license": "MIT"
}
var test = require('tap').test
var tryparse = require('../index.js')
test("if a integer is correctly returned", function (t) {
t.equal(tryparse.int(4), 4, "Is Integer")
t.end()
})
test("if a integer string is correctly returned", function (t) {
t.equal(tryparse.int("4"), 4, "Is Integer string")
t.end()
})
test("if a float is correctly returned", function (t) {
t.equal(tryparse.float(4.5), 4.5, "Is Float")
t.end()
})
test("if a float string is correctly returned", function (t) {
t.equal(tryparse.float("4.5"), 4.5, "Is Float string")
t.end()
})
test("if a non-integer is returned as null on tryparse.int", function (t) {
t.equal(tryparse.int('s'), null, "Is Not Integer")
t.end()
})
test("if a non-float is return as null on tryparse.float", function (t) {
t.equal(tryparse.float('4q'), null, "Is Not a Float")
t.end()
})
\ No newline at end of file
......@@ -11,7 +11,8 @@
"dependencies": {
"express": "^4.18.1",
"JSON": "^1.0.0",
"request": "^2.88.2"
"request": "^2.88.2",
"tryparse": "^0.0.2"
}
},
"node_modules/accepts": {
......@@ -900,6 +901,11 @@
"node": ">=0.8"
}
},
"node_modules/tryparse": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
"integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
},
"node_modules/tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
......@@ -1663,6 +1669,11 @@
"punycode": "^2.1.1"
}
},
"tryparse": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
"integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
......
......@@ -15,6 +15,7 @@
"dependencies": {
"express": "^4.18.1",
"JSON": "^1.0.0",
"request": "^2.88.2"
"request": "^2.88.2",
"tryparse": "^0.0.2"
}
}
......
var express = require('express');
var tryParse = require('tryparse');
var papago = require('./transmessage.js');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
......@@ -30,7 +32,7 @@ app.post('/hook', function (req, res) {
console.log('[request message]', eventObj.message);
console.log("Receive Message : ", eventObj.message.text);
GetPlayerInfo(276, 2019, eventObj);
SelectAPI(eventObj,message.text);
res.sendStatus(200);
});
......@@ -40,8 +42,6 @@ try {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
//key : fs.readFileSync('./rootca.key'),
// cert : fs.readFileSync('./rootca.crt')
};
HTTPS.createServer(option, app).listen(sslport, () => {
......@@ -74,7 +74,7 @@ function Reply(eventObj,replyMsg){
"messages":[
{
"type":"text",
"text":playerMsg
"text":replyMsg
},
{
"type":"text",
......@@ -85,7 +85,6 @@ function Reply(eventObj,replyMsg){
},(error, response, body) => {
console.log(body);
});
}
function GetPlayerInfo(playerID, season, eventObj){
......@@ -104,4 +103,55 @@ function GetPlayerInfo(playerID, season, eventObj){
console.log(response.body);
Reply(eventObj,response.body);
});
}
function SelectAPI(replyMsg){
if(tryParse.int(replyMsg) != null){ // 리그 선택
SelectLeague(tryParse.int(replyMsg));
}
else{ // 팀명 입력
console.log(papago.TranslateKRtoEN(replyMsg));
}
Reply(papago.TranslateKRtoEN(replyMsg));
}
function SelectLeague(inputNum){
let leagueID = 0;
switch(inputNum){
case 1: // 잉글랜드 프리미어리그
leagueID = 39;
break;
case 2: // 스페인 라리가
leagueID = 140;
break;
case 3: // 이탈리아 세리에 A
leagueID = 135;
break;
case 4: // 독일 분데스리가
leagueID = 78;
break;
case 5: // 프랑스 리그앙
leagueID = 61;
break;
case 6: // 포르투칼 프리메라리가
leagueID = 94;
break;
case 7: // UEFA 챔피언스리그
leagueID = 2;
break;
case 8: // UEFA 유로파리그
leagueID = 4;
break;
case 9: // UEFA 컨퍼런스리그
leagueID = 848;
break;
case 10: // 대한민국 K리그
leagueID = 292;
break;
default:
break;
}
console.log("Returned League ID : %d", leagueID);
return leagueID;
}
\ No newline at end of file
......
......@@ -31,8 +31,10 @@ function transMsg(replyMsg){
if(!error && response.statusCode == 200) {
let transMessage = body.message.result.translatedText;
console.log(transMessage);
return transMessage;
}
});
return replyMsg;
}
var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등"
......@@ -54,6 +56,16 @@ function transMsg_toEn(replyMsg){
if(!error && response.statusCode == 200) {
let transMessage = body.message.result.translatedText;
console.log(transMessage);
return transMessage;
}
});
}
\ No newline at end of file
return replyMsg;
}
exports.TranslateKRtoEN = function(transMsg){
return transMsg_toEn(transMsg);
}
exports.TranslateENtoKR = function(transMsg){
return transMsg(transMsg);
}
\ No newline at end of file
......