박찬수

전체 테스트

1 var data = require('./getid.js'); 1 var data = require('./getid.js');
2 2
3 // 입력: 팀ID, 리그ID, 시즌 입력, 반환: 경기일정 3 // 입력: 팀ID, 리그ID, 시즌 입력, 반환: 경기일정
4 -function GetGameSchedule(teamID, leagueID, season, eventObj){ 4 +function GetGameSchedule(teamID, leagueID, season, callbackFunc){
5 var request = require("request"); 5 var request = require("request");
6 var options = { 6 var options = {
7 method: 'GET', 7 method: 'GET',
...@@ -15,9 +15,12 @@ function GetGameSchedule(teamID, leagueID, season, eventObj){ ...@@ -15,9 +15,12 @@ function GetGameSchedule(teamID, leagueID, season, eventObj){
15 request(options, function (error, response, body) { 15 request(options, function (error, response, body) {
16 if (error) throw new Error(error); 16 if (error) throw new Error(error);
17 console.log(body); 17 console.log(body);
18 + callbackFunc(body);
18 }); 19 });
19 } 20 }
20 21
22 +
23 +
21 // 입력: 리그ID, 시즌(*필수) 반환: 팀 순위 24 // 입력: 리그ID, 시즌(*필수) 반환: 팀 순위
22 function GetLeagueStanding(leagueID, season, callbackFunc){ 25 function GetLeagueStanding(leagueID, season, callbackFunc){
23 var request = require("request"); 26 var request = require("request");
...@@ -88,7 +91,7 @@ exports.TopAssist = function(leagueID, callbackFunc){ ...@@ -88,7 +91,7 @@ exports.TopAssist = function(leagueID, callbackFunc){
88 } 91 }
89 92
90 // 입력: 팀ID, 시즌(*필수), 반환: 경기 일정 93 // 입력: 팀ID, 시즌(*필수), 반환: 경기 일정
91 -function GetGameSchedule_teamname(season, teamID){ 94 +function GetGameSchedule_teamname(season, teamID, callbackFunc){
92 var request = require("request"); 95 var request = require("request");
93 var options = { 96 var options = {
94 method: 'GET', 97 method: 'GET',
...@@ -102,11 +105,16 @@ function GetGameSchedule_teamname(season, teamID){ ...@@ -102,11 +105,16 @@ function GetGameSchedule_teamname(season, teamID){
102 request(options, function (error, response, body) { 105 request(options, function (error, response, body) {
103 if (error) throw new Error(error); 106 if (error) throw new Error(error);
104 console.log(body); 107 console.log(body);
108 + callbackFunc(body);
105 }); 109 });
106 } 110 }
107 111
112 +exports.GameSchehdule = function(teamID, callbackFunc){
113 + GetGameSchedule(2021, teamID, callbackFunc);
114 +}
115 +
108 // 입력: 팀ID,시즌(*필수), 반환: 소속 선수 116 // 입력: 팀ID,시즌(*필수), 반환: 소속 선수
109 -function GetTeamMembers(season, teamID){ 117 +function GetTeamMembers(season, teamID, callbackFunc){
110 var request = require("request"); 118 var request = require("request");
111 var options = { 119 var options = {
112 method: 'GET', 120 method: 'GET',
...@@ -120,9 +128,14 @@ function GetTeamMembers(season, teamID){ ...@@ -120,9 +128,14 @@ function GetTeamMembers(season, teamID){
120 request(options, function (error, response, body) { 128 request(options, function (error, response, body) {
121 if (error) throw new Error(error); 129 if (error) throw new Error(error);
122 console.log(body); 130 console.log(body);
131 + callbackFunc(body);
123 }) 132 })
124 } 133 }
125 134
135 +exports.TeamMembers = function(teamID, callbackFunc){
136 + GetTeamMembers(2021, teamID, callbackFunc);
137 +}
138 +
126 // 입력: 팀ID, 시즌*(필수), 반환: 팀 순위 139 // 입력: 팀ID, 시즌*(필수), 반환: 팀 순위
127 function GetTeamStanding(season, teamID){ 140 function GetTeamStanding(season, teamID){
128 var request = require("request"); 141 var request = require("request");
......
...@@ -219,6 +219,40 @@ function SelectLeagueInfo(eventObj, inputNum){ ...@@ -219,6 +219,40 @@ function SelectLeagueInfo(eventObj, inputNum){
219 return returnMsg; 219 return returnMsg;
220 } 220 }
221 221
222 +function SelectTeamInfo(inputNum){
223 + let returnMsg = "잘 못 고르셨습니다. 다시 골라주세요."
224 + switch(inputNum){
225 + case 1: // 경기 일정
226 + soccerAPI.GameSchehdule(currentTeamID, function(body){
227 + let gameScheduleJson = JSON.parse(body);
228 + let valueText = "";
229 + for(var i = 0; i < gameScheduleJson.response.length; i++){
230 + valueText += (i+1).toString() + "|" + gameScheduleJson.response[i].fixture.date + "|" + gameScheduleJson.response[i].league.name + "|" + gameScheduleJson.response[i].teams.home.name + "|" + gameScheduleJson.response[i].teams.away.name + "|" + gameScheduleJson.response[i].fixture.status.long + "|" + gameScheduleJson.response[i].goals.home + "|" + gameScheduleJson.response[i].goals.away + '\n';
231 + }
232 + returnMsg = MakeReplyMessage('경기 일정', '===========', valueText);
233 + Reply(eventObj, returnMsg);
234 + });
235 + break;
236 + case 2: // 명단
237 + soccerAPI.TeamMembers(currentTeamID, function(body){
238 + let teamMembersJson = JSON.parse(body);
239 + let valueText = "";
240 + for(var i = 0; i < teamMembersJson.response.length; i++){
241 + valueText += (i+1).toString() + "|" + teamMembersJson.response[i].statistics[0].team.name + "|" + teamMembersJson.response[i].statistics[0].league.name + "|" + teamMembersJson.response[i].player.name + "|" + teamMembersJson.response[i].player.nationality + "|" + teamMembersJson.response[i].player.birth.date + "|" + teamMembersJson.response[i].statistics[0].games.appearences + "|" + teamMembersJson.response[i].statistics[0].games.minutes + "|" + teamMembersJson.response[i].statistics[0].games.position + "|" + teamMembersJson.response[i].statistics[0].games.captain + '\n';
242 + }
243 + returnMsg = MakeReplyMessage('명단', '============', valueText);
244 + Reply(eventObj, returnMsg);
245 + });
246 + break;
247 + case 3: // 처음으로
248 + SetDefault(eventObj.source.userId);
249 + break;
250 + default:
251 + break;
252 + }
253 + return returnMsg;
254 +}
255 +
222 function SetDefault(userID){ 256 function SetDefault(userID){
223 step = 0; 257 step = 0;
224 push.SendMessage(DefaultSelectMessage(), userID); 258 push.SendMessage(DefaultSelectMessage(), userID);
...@@ -228,12 +262,10 @@ function MakeReplyMessage(title, keys, values){ ...@@ -228,12 +262,10 @@ function MakeReplyMessage(title, keys, values){
228 return title + '\n' + keys + '\n' + values; 262 return title + '\n' + keys + '\n' + values;
229 } 263 }
230 264
231 -function SelectTeamInfo(inputNum){ 265 +
232 - return 'You Selected ' + inputNum.toString();
233 -}
234 266
235 function DefaultSelectMessage(){ 267 function DefaultSelectMessage(){
236 - return '안녕하세요. \n리그번호 혹은 팀명을 입력해주세요.'; 268 + return '안녕하세요. \n리그번호 혹은 팀명을 입력해주세요.\n리그번호\n1. 잉글랜드 프리미어리그\n2. 스페인 라리가\n3. 이탈리아 세리에 A\n4. 독일 분데스리가 1\n5. 프랑스 리그앙\n6. 포르투갈 프리메라리가\n7. UEFA 챔피언스리그\n8. UEFA 유로파리그\n9. UEFA 컨퍼런스리그\n10. 대한민국 K-리그';
237 } 269 }
238 270
239 function SelectLeagueInfoMessage(){ 271 function SelectLeagueInfoMessage(){
...@@ -242,6 +274,6 @@ function SelectLeagueInfoMessage(){ ...@@ -242,6 +274,6 @@ function SelectLeagueInfoMessage(){
242 } 274 }
243 275
244 function SelectTeamInfoMessage(){ 276 function SelectTeamInfoMessage(){
245 - let msg = '1. 경기 일정 \n2. 소속 선수 \n3. 순위 \n4. 처음으로'; 277 + let msg = '1. 경기 일정 \n2. 선수 명단 \n3. 처음으로';
246 return msg; 278 return msg;
247 } 279 }
...\ No newline at end of file ...\ No newline at end of file
......