박찬수

all commit

...@@ -2,6 +2,7 @@ const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191'; ...@@ -2,6 +2,7 @@ const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191';
2 const hostUrl = 'v3.football.api-sports.io'; 2 const hostUrl = 'v3.football.api-sports.io';
3 3
4 var request = require('request'); 4 var request = require('request');
5 +var papago = require('./transmessage.js');
5 6
6 var sampleLeagueNum = '39'; 7 var sampleLeagueNum = '39';
7 var sampleSeasonNum = '2021'; 8 var sampleSeasonNum = '2021';
...@@ -130,3 +131,12 @@ exports.SearchTeam = function(teamName){ ...@@ -130,3 +131,12 @@ exports.SearchTeam = function(teamName){
130 return GetTeamIDByName(teamName); 131 return GetTeamIDByName(teamName);
131 } 132 }
132 133
134 +function SayHello(basic, trans){
135 + console.log(basic + trans);
136 +}
137 +
138 +function BasicHello(basic, trans){
139 + papago.TranslateKRtoEN(basic, function(transedMsg){
140 + SayHello(basic, transedMsg);
141 + });
142 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -32,7 +32,7 @@ app.post('/hook', function (req, res) { ...@@ -32,7 +32,7 @@ app.post('/hook', function (req, res) {
32 console.log('[request message]', eventObj.message); 32 console.log('[request message]', eventObj.message);
33 console.log("Receive Message : ", eventObj.message.text); 33 console.log("Receive Message : ", eventObj.message.text);
34 34
35 - SelectAPI(eventObj,message.text); 35 + SelectAPI(eventObj, eventObj.message.text);
36 36
37 res.sendStatus(200); 37 res.sendStatus(200);
38 }); 38 });
...@@ -97,14 +97,16 @@ function GetPlayerInfo(playerID, season, eventObj){ ...@@ -97,14 +97,16 @@ function GetPlayerInfo(playerID, season, eventObj){
97 } 97 }
98 98
99 99
100 -function SelectAPI(replyMsg){ 100 +function SelectAPI(eventObj, commingMsg){
101 - if(tryParse.int(replyMsg) != null){ // 리그 선택 101 + if(tryParse.int(commingMsg) != null){ // 리그 선택
102 - SelectLeague(tryParse.int(replyMsg)); 102 + SelectLeague(tryParse.int(commingMsg));
103 } 103 }
104 else{ // 팀명 입력 104 else{ // 팀명 입력
105 - console.log(papago.TranslateKRtoEN(replyMsg)); 105 + papago.TranslateKRtoEN(commingMsg, function(transedMsg){
106 + Reply(eventObj, transedMsg);
107 + });
106 } 108 }
107 - Reply(papago.TranslateKRtoEN(replyMsg)); 109 + ;
108 } 110 }
109 111
110 function SelectLeague(inputNum){ 112 function SelectLeague(inputNum){
......
...@@ -11,8 +11,8 @@ const HTTPS = require('https'); ...@@ -11,8 +11,8 @@ const HTTPS = require('https');
11 const domain = "2018102191.osschatbot2022.tk" 11 const domain = "2018102191.osschatbot2022.tk"
12 const sslport = 23023; 12 const sslport = 23023;
13 const bodyParser = require('body-parser'); 13 const bodyParser = require('body-parser');
14 - 14 +const { post } = require('request');
15 -var sampleReplyMsg = "players, seasons, standings, league, Son, Neymar"; 15 +const req = require('express/lib/request');
16 16
17 function transMsg(replyMsg){ 17 function transMsg(replyMsg){
18 var language = "ko"; 18 var language = "ko";
...@@ -37,14 +37,13 @@ function transMsg(replyMsg){ ...@@ -37,14 +37,13 @@ function transMsg(replyMsg){
37 return replyMsg; 37 return replyMsg;
38 } 38 }
39 39
40 -var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등" 40 +function transMsg_toEn(replyMsg, callbackFunc){
41 -
42 -function transMsg_toEn(replyMsg){
43 var language = "en"; 41 var language = "en";
44 42
45 request.post( 43 request.post(
46 { 44 {
47 url: PAPAGO_URL, 45 url: PAPAGO_URL,
46 + method : post,
48 headers: { 47 headers: {
49 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 48 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
50 'X-Naver-Client-Id': `${PAPAGO_ID}`, 49 'X-Naver-Client-Id': `${PAPAGO_ID}`,
...@@ -52,20 +51,20 @@ function transMsg_toEn(replyMsg){ ...@@ -52,20 +51,20 @@ function transMsg_toEn(replyMsg){
52 }, 51 },
53 body: 'source=ko&target=' + language + '&text=' + replyMsg, 52 body: 'source=ko&target=' + language + '&text=' + replyMsg,
54 json:true 53 json:true
55 - },(error, response, body) => { 54 + }, (error, response, body) => {
56 if(!error && response.statusCode == 200) { 55 if(!error && response.statusCode == 200) {
57 let transMessage = body.message.result.translatedText; 56 let transMessage = body.message.result.translatedText;
58 - console.log(transMessage); 57 + console.log(transMessage);
59 - return transMessage; 58 + callbackFunc(transMessage);
60 } 59 }
61 }); 60 });
62 - return replyMsg;
63 } 61 }
64 62
65 -exports.TranslateKRtoEN = function(transMsg){ 63 +exports.TranslateKRtoEN = function(transMsg, callbackFunc){
66 - return transMsg_toEn(transMsg); 64 + transMsg_toEn(transMsg, callbackFunc);
67 } 65 }
68 66
69 exports.TranslateENtoKR = function(transMsg){ 67 exports.TranslateENtoKR = function(transMsg){
70 return transMsg(transMsg); 68 return transMsg(transMsg);
71 -}
...\ No newline at end of file ...\ No newline at end of file
69 +}
70 +
......