박찬수

초기화 기능 추가

const { send } = require('express/lib/response');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
......@@ -31,42 +32,20 @@ const USER_ID = '사Uc4258407a7677769f74ba184ec036651'
// Multicast User
request.post(
{
url: MULTI_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": [`${USER_ID}`],
"messages":[
{
"type":"text",
"text":"This is push message."
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
// Broadcast
function Multicast(sendMsg){
request.post(
{
url: BROAD_TARGET_URL,
url: MULTI_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": [`${USER_ID}`],
"messages":[
{
"type":"text",
"text":"This is broadcast message."
"text":sendMsg
},
{
"type":"text",
......@@ -76,4 +55,33 @@ request.post(
}
},(error, response, body) => {
console.log(body)
});
\ No newline at end of file
});
}
exports.SendMessage = function(sendMessage){
Multicast(sendMessage);
}
// // Broadcast
// request.post(
// {
// url: BROAD_TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "messages":[
// {
// "type":"text",
// "text":"This is broadcast message."
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
\ No newline at end of file
......
......@@ -13,8 +13,10 @@ const sslport = 23023;
var data = require('./getid.js');
var soccerAPI = require('./appfunctions.js');
var push = require('./push.js');
const bodyParser = require('body-parser');
const { defaultProxyHeaderExclusiveList } = require('request/request');
var isLeagueInfo = false;
var step = 0;
......@@ -22,6 +24,8 @@ var step = 0;
var currentLeagueID = 0;
var currentTeamID = 0;
push.SendMessage(DefaultSelectMessage());
data.SetData();
var app = express();
......@@ -180,15 +184,34 @@ function SelectLeagueInfo(eventObj, inputNum){
for(var i = 0; i < 20; i++){
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';
}
returnMsg = MakeReplyMessage('팀 순위', '순위|팀명|경기|득점|승리|무승부|패배|득점|??', valueText);
returnMsg = MakeReplyMessage('팀 순위', '순위|팀명|경기|득점|승리|무승부|패배|득점|실점', valueText);
Reply(eventObj, returnMsg);
});
break;
case 2: // 득점 순위
soccerAPI.TopScorer(currentLeagueID, function(body){
let standingJson = JSON.parse(body);
let valueText = "";
for(var i = 0; i < 20; i++){
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';
}
returnMsg = MakeReplyMessage('득점 순위', '순위|이름|소속팀|경기|득점', valueText);
Reply(eventObj, returnMsg);
});
break;
case 3: // 도움 순위
soccerAPI.TopAssist(currentLeagueID, function(body){
let standingJson = JSON.parse(body);
let valueText = "";
for(var i = 0; i < 20; i++){
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';
}
returnMsg = MakeReplyMessage('도움 순위', '순위|이름|소속팀|경기|도움', valueText);
Reply(eventObj, returnMsg);
});
break;
case 4: // 처음으로
SetDefault();
break;
default:
break;
......@@ -196,6 +219,11 @@ function SelectLeagueInfo(eventObj, inputNum){
return returnMsg;
}
function SetDefault(){
step = 0;
push.SendMessage(DefaultSelectMessage());
}
function MakeReplyMessage(title, keys, values){
return title + '\n' + keys + '\n' + values;
}
......@@ -205,7 +233,7 @@ function SelectTeamInfo(inputNum){
}
function DefaultSelectMessage(){
return '환영합니다.';
return '안녕하세요. \n리그번호 혹은 팀명을 입력해주세요.';
}
function SelectLeagueInfoMessage(){
......