43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const dateFormat = require('dateformat');
|
|
const { decode } = require('querystring');
|
|
|
|
/** Postback */
|
|
class PostbackClass {
|
|
constructor(app) {
|
|
this.app = app;
|
|
}
|
|
|
|
Postback(event) {
|
|
let action = event.postback.data;
|
|
let data = decode(action);
|
|
switch (data["action"]) {
|
|
case 'hasgame': {
|
|
this.HasGame(event, data);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
HasGame(event, data) {
|
|
let game_date = data["game_date"];
|
|
let time = data["time"];
|
|
let nowUNIXtime = Date.now();
|
|
let gameUNIXtime = new Date(`${game_date} ${time}`).getTime();
|
|
let IsStart = nowUNIXtime - gameUNIXtime > 0;
|
|
if (IsStart) {
|
|
this.app.CPBL.AddTime({
|
|
GameSno: data["GameSno"],
|
|
access_token: data["access_token"],
|
|
LineID: event.source.userId
|
|
}, event);
|
|
} else {
|
|
let replyMsg = `比賽還沒開始\n時間是${game_date} ${time}`;
|
|
event.reply(replyMsg);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = PostbackClass |