Alexandre Bodin a7d8889a6a Add telemtry
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-07-08 11:48:48 +02:00

28 lines
595 B
JavaScript

'use strict';
/**
* @param events a list of events that need to be limited
*/
module.exports = (sender, { limitedEvents = [] } = {}) => {
let currentDay = new Date().getDate();
const eventCache = new Map();
return async (event, ...args) => {
if (!limitedEvents.includes(event)) {
return sender(event, ...args);
}
if (new Date().getDate() !== currentDay) {
eventCache.clear();
currentDay = new Date().getDate();
}
if (eventCache.has(event)) {
return false;
}
eventCache.set(event, true);
return sender(event, ...args);
};
};