From 0cb3e82f085a801df02c0a50dbb0ed515149d06b Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Tue, 13 Dec 2022 21:10:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20covid=E7=96=AB=E8=8B=97=E4=BD=99?= =?UTF-8?q?=E9=87=8F=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 2 +- schedule/covidbook.js | 27 +++++++++++++++++++++++++++ schedule/schedule.js | 4 +++- tgbot/{bot.js => tgbot.js} | 21 ++++++++++++--------- 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 schedule/covidbook.js rename tgbot/{bot.js => tgbot.js} (55%) diff --git a/app.js b/app.js index f5702a0..238d470 100644 --- a/app.js +++ b/app.js @@ -56,7 +56,7 @@ schedule(app); if (!DEBUG) { console.log("PRODUCTION MODE!该模式下TG机器人正常运行"); // 引入TG机器人 - require("./tgbot/bot"); + require("./tgbot/tgbot"); } else console.log("DEBUG MODE!该模式下将关闭TG机器人"); diff --git a/schedule/covidbook.js b/schedule/covidbook.js new file mode 100644 index 0000000..fb98d48 --- /dev/null +++ b/schedule/covidbook.js @@ -0,0 +1,27 @@ +const axios = require('axios'); +const tgbot = require("../tgbot/tgbot.js"); + +const rootPath = 'https://eservice.ssm.gov.mo/covidvacbook/' +const url = rootPath + 'Booking/GetLocationQuotaList'; + +if (!module.parent) { + // 引入环境变量 + require("dotenv").config('../.env'); +} +console.log('covidbook.js loaded') +function main() { + axios.post(url).then((res) => { + const data = res.data; + const mrnalocationquotalist = data.filter(locationquota => (locationquota.rspsrv === 'HC6' || locationquota.rspsrv === 'HC8' || locationquota.rspsrv === 'CHCSJ(MRNA)' || locationquota.rspsrv === 'CHCSJ2(MRNA)' || locationquota.rspsrv === 'SSM1(MRNA)')); + const ret = mrnalocationquotalist.filter(x => x.sum != '0') + if (ret.length != 0) { + console.log('有余量'); + const bot = tgbot.hkaliyun; + bot.sendMessage(619935997, "有余量!"); + bot.sendMessage(619935997, JSON.stringify(ret)); + } else console.log('无余量'); + }) +} + +module.exports = main; + diff --git a/schedule/schedule.js b/schedule/schedule.js index 42ff4f0..74de171 100644 --- a/schedule/schedule.js +++ b/schedule/schedule.js @@ -3,6 +3,7 @@ const leancloud = require("../utils/leancloud"); const chai = require("chai"); const chaiHttp = require("chai-http"); const cf2dns = require("./cf2dns"); +const covidbook = require("./covidbook"); function subcache(app) { console.log("Running Cron Job:subcache"); @@ -31,9 +32,10 @@ module.exports = (app) => { result }); }); + covidbook(); }); }; if (!module.parent) { - cf2dns(); + covidbook(); } diff --git a/tgbot/bot.js b/tgbot/tgbot.js similarity index 55% rename from tgbot/bot.js rename to tgbot/tgbot.js index 89a6a8f..ffab16c 100644 --- a/tgbot/bot.js +++ b/tgbot/tgbot.js @@ -1,20 +1,23 @@ require("dotenv").config({path: "../.env"}); -const memory = require("../utils/memory"); + const hkaliyun = require("./bot/hkaliyun.js"); const airportsub = require("./bot/airportsub.js"); -const bots = [ - hkaliyun(process.env.TELEGRAM_TOKEN_HKALIYUN), - airportsub(process.env.TELEGRAM_TOKEN_AIRPORTSUB), -]; +const bots = { + hkaliyun: hkaliyun(process.env.TELEGRAM_TOKEN_HKALIYUN), + airportsub: airportsub(process.env.TELEGRAM_TOKEN_AIRPORTSUB), +}; + console.log("bot.js loaded"); -memory(); -for (const bot of bots) { - bot.getMe().then((botInfo) => { + +for (const bot in bots) { + bots[bot].getMe().then((botInfo) => { console.log("Bot info:", botInfo); }); - bot.deleteWebHook(); + bots[bot].deleteWebHook(); // bot.getWebHookInfo().then((webhookInfo) => { // console.log('Webhook info:', webhookInfo); // }); } + +module.exports = bots; \ No newline at end of file