Ostatnio aktywny 3 weeks ago

scheduler.ts Surowy
1import cron from "node-cron";
2import { TextChannel } from "discord.js";
3
4// Lock poll at TG start (20:00), reveal Submit Score button at TG end (20:35)
5// Runs daily — no-ops silently if no poll is active for that slot.
6
7cron.schedule("0 20 * * *", async () => {
8 const slot = 20;
9 const state = polls.get(slot);
10 if (!state || state.locked) return;
11
12 lockPoll(slot);
13
14 const channel = await client.channels.fetch(cfg("pollChannelId")) as TextChannel;
15 await updatePollMessage(channel, slot, cfg("lockMessage"));
16 console.log(`[${new Date().toISOString()}] Poll locked for ${slot}:00.`);
17});
18
19cron.schedule("35 20 * * *", async () => {
20 const slot = 20;
21 const state = polls.get(slot);
22 if (!state) return;
23
24 const channel = await client.channels.fetch(cfg("pollChannelId")) as TextChannel;
25 await updatePollMessage(channel, slot, undefined, true); // showSubmit = true
26 console.log(`[${new Date().toISOString()}] Submit Score button shown for ${slot}:00 TG.`);
27});
28
29// ─── NOTE on future slots ─────────────────────────────────────────────────────
30//
31// Right now only slot 20 has an active poll. When we add more votable slots,
32// pull the active slot from cfg("slots").filter(s => s.active) and schedule
33// dynamically, or make the cron time configurable in config.json.