Added Notifications, Auto-Reassign on Timer Expiration, Add Randomizer

This commit is contained in:
2026-06-09 21:08:52 +02:00
parent 11102fc3a5
commit 346cf6d863
7 changed files with 440 additions and 27 deletions
+76
View File
@@ -0,0 +1,76 @@
const { mClient } = require('../index');
function getRemaining(timer) {
if (timer.state !== 'running') {
return timer.timeRemaining;
}
return Math.max(
0,
timer.timeRemaining - (Date.now() - timer.startedAt)
);
}
module.exports = {
name: 'timerCheck',
async execute(client) {
const db = mClient.db('neo-db');
const wgeColl = db.collection('timer_wge');
const timers = await wgeColl.find({
state: { $ne: 'stopped' }
}).toArray();
const now = Date.now();
for (const timer of timers) {
const remaining = getRemaining(timer);
// -------------------------
// HALF TIME (3.5 days left)
// -------------------------
if (
!timer.notifications?.half &&
remaining <= 3.5 * 24 * 60 * 60 * 1000
) {
await wgeColl.updateOne(
{ _id: timer._id },
{ $set: { "notifications.half": true } }
);
client.emit('timerHalf', timer);
}
// -------------------------
// 24H WARNING
// -------------------------
if (
!timer.notifications?.day24 &&
remaining <= 24 * 60 * 60 * 1000
) {
await wgeColl.updateOne(
{ _id: timer._id },
{ $set: { "notifications.day24": true } }
);
client.emit('timer24h', timer);
}
// -------------------------
// COMPLETION
// -------------------------
if (
!timer.notifications?.complete &&
remaining <= 0
) {
await wgeColl.updateOne(
{ _id: timer._id },
{ $set: { "notifications.complete": true } }
);
client.emit('timerComplete', timer);
}
}
}
};