RaptusBackend / timers /RoundTwoTimer.js
GitHub Actions
Initial commit
df72131
const { userNotification } = require("../sockets/Notification");
const { roundEnd } = require("../sockets/RoundStartEnd");
module.exports.scheduleRound2Start = function scheduleRound2Start(targetTime) {
const currentTime = new Date().getTime();
const delay = targetTime - currentTime;
const notificationDelay5Mins = delay - (5 * 60 * 1000); // 5 minutes before round start
const notificationDelay15Mins = delay - (15 * 60 * 1000); // 15 minutes before round start
if (notificationDelay15Mins > 0) {
setTimeout(callback15Mins, notificationDelay15Mins);
}
if (notificationDelay5Mins > 0) {
setTimeout(callback5Mins, notificationDelay5Mins);
}
if (delay <= 0) {
// Target time has already passed, execute the function immediately
callback1();
} else {
setTimeout(callback1, delay);
}
};
function callback15Mins() {
userNotification("Round 2 will start in 15 minutes!");
}
function callback5Mins() {
userNotification("Round 2 will start in 5 minutes!");
}
function callback1() {
userNotification("Round 2 has started!");
}
module.exports.scheduleRound2End = function scheduleRound2End(targetTime) {
const currentTime = new Date().getTime();
const delay = targetTime - currentTime;
const notificationDelay5Mins = delay - (5 * 60 * 1000); // 5 minutes before round end
const notificationDelay15Mins = delay - (15 * 60 * 1000); // 15 minutes before round end
if (notificationDelay15Mins > 0) {
setTimeout(callback15Mins2, notificationDelay15Mins);
}
if (notificationDelay5Mins > 0) {
setTimeout(callback5Mins2, notificationDelay5Mins);
}
if (delay <= 0) {
// Target time has already passed, execute the function immediately
callback2();
} else {
setTimeout(callback2, delay);
}
};
function callback15Mins2() {
userNotification("Round 2 will end in 15 minutes!");
}
function callback5Mins2() {
userNotification("Round 2 will end in 5 minutes!");
}
function callback2() {
roundEnd(2);
}