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

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-04-27 00:42:22 +00:00
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) {
2021-12-26 07:15:28 +00:00
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);
}
2021-04-27 00:42:22 +00:00
}
}
2021-04-24 13:18:34 +00:00
module.exports = PostbackClass