Update cron expression

This commit is contained in:
Myx
2023-10-13 20:36:53 +02:00
parent b9c782e04c
commit 507edc1dea

14
bot.ts
View File

@@ -110,9 +110,13 @@ async function joinRandomChannel(retries = 12) {
function scheduleNextJoin(){ function scheduleNextJoin(){
const randomInterval = Math.floor(Math.random() * (maxTime - minTime + 1)) + minTime; const randomInterval = Math.floor(Math.random() * (maxTime - minTime + 1)) + minTime;
log(randomInterval); log(randomInterval);
schedule.scheduleJob(`*/${randomInterval} * * * *`, function(){ const minutes = randomInterval % 60;
const hours = Math.floor(randomInterval / 60);
schedule.scheduleJob(`${minutes} ${hours == 0 ? '*' : hours } * * *`, function(){
joinRandomChannel(); joinRandomChannel();
}); });
} }
@@ -123,12 +127,14 @@ function convertHoursToMinutes(hours: number){
function log(waitTime: number){ function log(waitTime: number){
const currentTime = new Date(); const currentTime = new Date();
const nextJoinTime = new Date(currentTime.getTime() + waitTime * 60 * 1000); // Convert waitTime from minutes to milliseconds const nextJoinTime = new Date(currentTime.getTime() + waitTime * 60000);
const minutes = waitTime % 60;
const hours = Math.floor(waitTime / 60);
console.log( console.log(
LoggerColors.Cyan, ` LoggerColors.Cyan, `
Wait time: ${waitTime} minutes, Wait time: ${waitTime} minutes,
Current time: ${currentTime.toLocaleTimeString()}, Current time: ${currentTime.toLocaleTimeString()},
Next join time: ${nextJoinTime.toLocaleTimeString()}` Next join time: ${nextJoinTime.toLocaleTimeString()},
Cron: ${minutes} ${hours == 0 ? '*' : hours } * * *`
); );
} }