박찬수

초기화 기능 추가

1 +const { send } = require('express/lib/response');
1 const request = require('request'); 2 const request = require('request');
2 const TARGET_URL = 'https://api.line.me/v2/bot/message/push' 3 const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
3 const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' 4 const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
...@@ -31,7 +32,9 @@ const USER_ID = '사Uc4258407a7677769f74ba184ec036651' ...@@ -31,7 +32,9 @@ const USER_ID = '사Uc4258407a7677769f74ba184ec036651'
31 32
32 33
33 // Multicast User 34 // Multicast User
34 -request.post( 35 +
36 +function Multicast(sendMsg){
37 + request.post(
35 { 38 {
36 url: MULTI_TARGET_URL, 39 url: MULTI_TARGET_URL,
37 headers: { 40 headers: {
...@@ -42,7 +45,7 @@ request.post( ...@@ -42,7 +45,7 @@ request.post(
42 "messages":[ 45 "messages":[
43 { 46 {
44 "type":"text", 47 "type":"text",
45 - "text":"This is push message." 48 + "text":sendMsg
46 }, 49 },
47 { 50 {
48 "type":"text", 51 "type":"text",
...@@ -53,27 +56,32 @@ request.post( ...@@ -53,27 +56,32 @@ request.post(
53 },(error, response, body) => { 56 },(error, response, body) => {
54 console.log(body) 57 console.log(body)
55 }); 58 });
59 +}
56 60
57 61
58 -// Broadcast
59 - request.post(
60 - {
61 - url: BROAD_TARGET_URL,
62 - headers: {
63 - 'Authorization': `Bearer ${TOKEN}`
64 - },
65 - json: {
66 - "messages":[
67 - {
68 - "type":"text",
69 - "text":"This is broadcast message."
70 - },
71 - {
72 - "type":"text",
73 - "text":"May I help you?"
74 - }
75 - ]
76 - }
77 - },(error, response, body) => {
78 - console.log(body)
79 - });
...\ No newline at end of file ...\ No newline at end of file
62 +exports.SendMessage = function(sendMessage){
63 + Multicast(sendMessage);
64 +}
65 +
66 +// // Broadcast
67 +// request.post(
68 +// {
69 +// url: BROAD_TARGET_URL,
70 +// headers: {
71 +// 'Authorization': `Bearer ${TOKEN}`
72 +// },
73 +// json: {
74 +// "messages":[
75 +// {
76 +// "type":"text",
77 +// "text":"This is broadcast message."
78 +// },
79 +// {
80 +// "type":"text",
81 +// "text":"May I help you?"
82 +// }
83 +// ]
84 +// }
85 +// },(error, response, body) => {
86 +// console.log(body)
87 +// });
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,8 +13,10 @@ const sslport = 23023; ...@@ -13,8 +13,10 @@ const sslport = 23023;
13 13
14 var data = require('./getid.js'); 14 var data = require('./getid.js');
15 var soccerAPI = require('./appfunctions.js'); 15 var soccerAPI = require('./appfunctions.js');
16 +var push = require('./push.js');
16 17
17 const bodyParser = require('body-parser'); 18 const bodyParser = require('body-parser');
19 +const { defaultProxyHeaderExclusiveList } = require('request/request');
18 20
19 var isLeagueInfo = false; 21 var isLeagueInfo = false;
20 var step = 0; 22 var step = 0;
...@@ -22,6 +24,8 @@ var step = 0; ...@@ -22,6 +24,8 @@ var step = 0;
22 var currentLeagueID = 0; 24 var currentLeagueID = 0;
23 var currentTeamID = 0; 25 var currentTeamID = 0;
24 26
27 +push.SendMessage(DefaultSelectMessage());
28 +
25 data.SetData(); 29 data.SetData();
26 30
27 var app = express(); 31 var app = express();
...@@ -180,15 +184,34 @@ function SelectLeagueInfo(eventObj, inputNum){ ...@@ -180,15 +184,34 @@ function SelectLeagueInfo(eventObj, inputNum){
180 for(var i = 0; i < 20; i++){ 184 for(var i = 0; i < 20; i++){
181 valueText += standingJson.response[0].league.standings[0][i].rank + "|" + standingJson.response[0].league.standings[0][i].team.name + "|" + standingJson.response[0].league.standings[0][i].all.played + "|" + standingJson.response[0].league.standings[0][i].points + "|" + standingJson.response[0].league.standings[0][i].all.win + "|" + standingJson.response[0].league.standings[0][i].all.draw + "|" + standingJson.response[0].league.standings[0][i].all.lose + "|" + standingJson.response[0].league.standings[0][i].all.goals.for + "|" + standingJson.response[0].league.standings[0][i].all.goals.against + '\n'; 185 valueText += standingJson.response[0].league.standings[0][i].rank + "|" + standingJson.response[0].league.standings[0][i].team.name + "|" + standingJson.response[0].league.standings[0][i].all.played + "|" + standingJson.response[0].league.standings[0][i].points + "|" + standingJson.response[0].league.standings[0][i].all.win + "|" + standingJson.response[0].league.standings[0][i].all.draw + "|" + standingJson.response[0].league.standings[0][i].all.lose + "|" + standingJson.response[0].league.standings[0][i].all.goals.for + "|" + standingJson.response[0].league.standings[0][i].all.goals.against + '\n';
182 } 186 }
183 - returnMsg = MakeReplyMessage('팀 순위', '순위|팀명|경기|득점|승리|무승부|패배|득점|??', valueText); 187 + returnMsg = MakeReplyMessage('팀 순위', '순위|팀명|경기|득점|승리|무승부|패배|득점|실점', valueText);
184 Reply(eventObj, returnMsg); 188 Reply(eventObj, returnMsg);
185 }); 189 });
186 break; 190 break;
187 case 2: // 득점 순위 191 case 2: // 득점 순위
192 + soccerAPI.TopScorer(currentLeagueID, function(body){
193 + let standingJson = JSON.parse(body);
194 + let valueText = "";
195 + for(var i = 0; i < 20; i++){
196 + valueText += (i+1).toString() + "|" + topScorerJson.response[i].player.name + "|" + topScorerJson.response[i].statistics[0].team.name + "|" + topScorerJson.response[i].statistics[0].games.appearences + "|" + topScorerJson.response[i].statistics[0].goals.total + '\n';
197 + }
198 + returnMsg = MakeReplyMessage('득점 순위', '순위|이름|소속팀|경기|득점', valueText);
199 + Reply(eventObj, returnMsg);
200 + });
188 break; 201 break;
189 case 3: // 도움 순위 202 case 3: // 도움 순위
203 + soccerAPI.TopAssist(currentLeagueID, function(body){
204 + let standingJson = JSON.parse(body);
205 + let valueText = "";
206 + for(var i = 0; i < 20; i++){
207 + valueText += (i+1).toString() + "|" + topAssistJson.response[i].player.name + "|" + topAssistJson.response[i].statistics[0].team.name + "|" + topAssistJson.response[i].statistics[0].games.appearences + "|" + topAssistJson.response[i].statistics[0].goals.assists + '\n';
208 + }
209 + returnMsg = MakeReplyMessage('도움 순위', '순위|이름|소속팀|경기|도움', valueText);
210 + Reply(eventObj, returnMsg);
211 + });
190 break; 212 break;
191 case 4: // 처음으로 213 case 4: // 처음으로
214 + SetDefault();
192 break; 215 break;
193 default: 216 default:
194 break; 217 break;
...@@ -196,6 +219,11 @@ function SelectLeagueInfo(eventObj, inputNum){ ...@@ -196,6 +219,11 @@ function SelectLeagueInfo(eventObj, inputNum){
196 return returnMsg; 219 return returnMsg;
197 } 220 }
198 221
222 +function SetDefault(){
223 + step = 0;
224 + push.SendMessage(DefaultSelectMessage());
225 +}
226 +
199 function MakeReplyMessage(title, keys, values){ 227 function MakeReplyMessage(title, keys, values){
200 return title + '\n' + keys + '\n' + values; 228 return title + '\n' + keys + '\n' + values;
201 } 229 }
...@@ -205,7 +233,7 @@ function SelectTeamInfo(inputNum){ ...@@ -205,7 +233,7 @@ function SelectTeamInfo(inputNum){
205 } 233 }
206 234
207 function DefaultSelectMessage(){ 235 function DefaultSelectMessage(){
208 - return '환영합니다.'; 236 + return '안녕하세요. \n리그번호 혹은 팀명을 입력해주세요.';
209 } 237 }
210 238
211 function SelectLeagueInfoMessage(){ 239 function SelectLeagueInfoMessage(){
......