Skip to content

Commit

Permalink
add cron job for pvx functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhamrawat5 committed Jan 4, 2024
1 parent 0c7cbaf commit b384caa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"googlethis": "^1.7.1",
"insta-fetcher": "^1.3.25",
"node-cache": "^5.1.2",
"node-cron": "^3.0.3",
"node-telegram-bot-api": "^0.61.0",
"openai": "^3.3.0",
"pg": "^8.7.3",
Expand All @@ -52,6 +53,7 @@
"@types/adm-zip": "^0.5.0",
"@types/express": "^4.17.17",
"@types/fluent-ffmpeg": "^2.1.21",
"@types/node-cron": "^3.0.11",
"@types/node-telegram-bot-api": "^0.61.6",
"@types/pg": "^8.10.1",
"@types/string-similarity": "^4.0.0",
Expand Down
7 changes: 4 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import makeWASocket, {
} from "@whiskeysockets/baileys";

import pino from "pino";
import cron from "node-cron";

/* ----------------------------- add local files ---------------------------- */
import { setAuth, getAuth } from "./db/authDB";
Expand All @@ -34,7 +35,7 @@ import { pvxFunctionsEnabled } from "./utils/config";

stats.started = getIndianDateTime().toDateString();

let dateCheckerInterval: NodeJS.Timeout;
let cronJob: cron.ScheduledTask | undefined;

let milestonesDefault: MilestonesDefault = {};

Expand Down Expand Up @@ -79,7 +80,7 @@ const startBot = async () => {
commandsOwners,
allCommandsName,
} = await addCommands();
clearInterval(dateCheckerInterval);
cronJob?.stop();

const { version, isLatest } = await fetchLatestBaileysVersion();
console.log(`using WA v${version.join(".")}, isLatest: ${isLatest}`);
Expand All @@ -106,7 +107,7 @@ const startBot = async () => {
store?.bind(bot.ev);

if (pvxFunctionsEnabled === "true") {
dateCheckerInterval = await pvxFunctions(bot);
cronJob = await pvxFunctions(bot);
}

let botNumberJid = bot.user ? bot.user.id : ""; // '1506xxxxx54:[email protected]'
Expand Down
9 changes: 5 additions & 4 deletions src/functions/pvxFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cron from "node-cron";
import { ownerNumberWithJid } from "../utils/config";
import { pvxgroups } from "../utils/constants";
import { deleteOldNews } from "../db/newsDB";
Expand All @@ -7,11 +8,11 @@ import { getIndianDateTime, getOldIndianDateTime } from "./getIndianDateTime";
import postStudyInfo from "./postStudyInfo";
import { postTechNewsHeadline, postTechNewsList } from "./postTechNews";

const pvxFunctions = async (bot: Bot) => {
const pvxFunctions = async (bot: Bot): Promise<cron.ScheduledTask> => {
let usedDate = getIndianDateTime().toDateString();

return setInterval(async () => {
console.log("SET INTERVAL.");
return cron.schedule("0 */20 * ? * *", async () => {
console.log("Cron 20 min !");
const date = getIndianDateTime();
const todayDate = date.toDateString();

Expand Down Expand Up @@ -53,7 +54,7 @@ const pvxFunctions = async (bot: Bot) => {
});
}
}
}, 1000 * 60 * 30); // 30 min
});
};

export default pvxFunctions;

0 comments on commit b384caa

Please sign in to comment.