This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kingdombattles/common/throttle.js
T

31 lines
477 B
JavaScript

let CronJob = require('cron').CronJob;
let emails = [];
function throttle(email) {
emails[email] = new Date();
}
function isThrottled(email) {
if (emails[email] === undefined) {
return false;
}
if ( (emails[email] - new Date()) / 1000 > 3) { //3 seconds
return false;
}
return true;
}
//clear the memory once a day
let job = new CronJob('0 7 * * * *', () => {
emails = [];
});
job.start();
module.exports = {
throttle: throttle,
isThrottled: isThrottled
};