박찬수

all commit

......@@ -2,6 +2,7 @@ const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191';
const hostUrl = 'v3.football.api-sports.io';
var request = require('request');
var papago = require('./transmessage.js');
var sampleLeagueNum = '39';
var sampleSeasonNum = '2021';
......@@ -130,3 +131,12 @@ exports.SearchTeam = function(teamName){
return GetTeamIDByName(teamName);
}
function SayHello(basic, trans){
console.log(basic + trans);
}
function BasicHello(basic, trans){
papago.TranslateKRtoEN(basic, function(transedMsg){
SayHello(basic, transedMsg);
});
}
\ No newline at end of file
......
......@@ -32,7 +32,7 @@ app.post('/hook', function (req, res) {
console.log('[request message]', eventObj.message);
console.log("Receive Message : ", eventObj.message.text);
SelectAPI(eventObj,message.text);
SelectAPI(eventObj, eventObj.message.text);
res.sendStatus(200);
});
......@@ -97,14 +97,16 @@ function GetPlayerInfo(playerID, season, eventObj){
}
function SelectAPI(replyMsg){
if(tryParse.int(replyMsg) != null){ // 리그 선택
SelectLeague(tryParse.int(replyMsg));
function SelectAPI(eventObj, commingMsg){
if(tryParse.int(commingMsg) != null){ // 리그 선택
SelectLeague(tryParse.int(commingMsg));
}
else{ // 팀명 입력
console.log(papago.TranslateKRtoEN(replyMsg));
papago.TranslateKRtoEN(commingMsg, function(transedMsg){
Reply(eventObj, transedMsg);
});
}
Reply(papago.TranslateKRtoEN(replyMsg));
;
}
function SelectLeague(inputNum){
......
......@@ -11,8 +11,8 @@ const HTTPS = require('https');
const domain = "2018102191.osschatbot2022.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var sampleReplyMsg = "players, seasons, standings, league, Son, Neymar";
const { post } = require('request');
const req = require('express/lib/request');
function transMsg(replyMsg){
var language = "ko";
......@@ -37,14 +37,13 @@ function transMsg(replyMsg){
return replyMsg;
}
var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등"
function transMsg_toEn(replyMsg){
function transMsg_toEn(replyMsg, callbackFunc){
var language = "en";
request.post(
{
url: PAPAGO_URL,
method : post,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Naver-Client-Id': `${PAPAGO_ID}`,
......@@ -52,20 +51,20 @@ function transMsg_toEn(replyMsg){
},
body: 'source=ko&target=' + language + '&text=' + replyMsg,
json:true
},(error, response, body) => {
}, (error, response, body) => {
if(!error && response.statusCode == 200) {
let transMessage = body.message.result.translatedText;
console.log(transMessage);
return transMessage;
console.log(transMessage);
callbackFunc(transMessage);
}
});
return replyMsg;
}
exports.TranslateKRtoEN = function(transMsg){
return transMsg_toEn(transMsg);
exports.TranslateKRtoEN = function(transMsg, callbackFunc){
transMsg_toEn(transMsg, callbackFunc);
}
exports.TranslateENtoKR = function(transMsg){
return transMsg(transMsg);
}
\ No newline at end of file
}
......