Add receipt day announcements
This commit is contained in:
45
timers/receiptTimer.js
Normal file
45
timers/receiptTimer.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
module.exports = {
|
||||||
|
timeout: 1000,
|
||||||
|
immediate: false,
|
||||||
|
name: 'Receipt Day Announcements',
|
||||||
|
data: {
|
||||||
|
channelId: '1462060674766344370',
|
||||||
|
targetHour: 0,
|
||||||
|
targetMinute: 1
|
||||||
|
},
|
||||||
|
async tick(client, timer) {
|
||||||
|
try {
|
||||||
|
// 1. Send the message
|
||||||
|
const currentDate = new Date().toLocaleDateString();
|
||||||
|
const channel = await client.channels.fetch(timer.data.channelId);
|
||||||
|
if (channel) await channel.send(`Current date is ${currentDate}`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[TIMER] Error:', error);
|
||||||
|
} finally {
|
||||||
|
// 2. Schedule the NEXT tick manually
|
||||||
|
this.scheduleNext(client, timer);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
scheduleNext(client, timer) {
|
||||||
|
const now = new Date();
|
||||||
|
const next = new Date();
|
||||||
|
|
||||||
|
next.setHours(timer.data.targetHour, timer.data.targetMinute, 0, 0);
|
||||||
|
|
||||||
|
if (next <= now) {
|
||||||
|
next.setDate(next.getDate() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const delay = next.getTime() - now.getTime();
|
||||||
|
|
||||||
|
if (timer.instance) clearTimeout(timer.instance);
|
||||||
|
|
||||||
|
timer.instance = setTimeout(() => {
|
||||||
|
this.tick(client, timer);
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
console.log(`[TIMER] Next message scheduled for: ${next.toLocaleString()}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user