scheduler.ts
· 1.4 KiB · TypeScript
Raw
import cron from "node-cron";
import { TextChannel } from "discord.js";
// Lock poll at TG start (20:00), reveal Submit Score button at TG end (20:35)
// Runs daily — no-ops silently if no poll is active for that slot.
cron.schedule("0 20 * * *", async () => {
const slot = 20;
const state = polls.get(slot);
if (!state || state.locked) return;
lockPoll(slot);
const channel = await client.channels.fetch(cfg("pollChannelId")) as TextChannel;
await updatePollMessage(channel, slot, cfg("lockMessage"));
console.log(`[${new Date().toISOString()}] Poll locked for ${slot}:00.`);
});
cron.schedule("35 20 * * *", async () => {
const slot = 20;
const state = polls.get(slot);
if (!state) return;
const channel = await client.channels.fetch(cfg("pollChannelId")) as TextChannel;
await updatePollMessage(channel, slot, undefined, true); // showSubmit = true
console.log(`[${new Date().toISOString()}] Submit Score button shown for ${slot}:00 TG.`);
});
// ─── NOTE on future slots ─────────────────────────────────────────────────────
//
// Right now only slot 20 has an active poll. When we add more votable slots,
// pull the active slot from cfg("slots").filter(s => s.active) and schedule
// dynamically, or make the cron time configurable in config.json.
| 1 | import cron from "node-cron"; |
| 2 | import { 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 | |
| 7 | cron.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 | |
| 19 | cron.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. |