This repository has been archived on 2024-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
line-cost-js/PostbackClass.js
2021-12-26 15:15:28 +08:00

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