Fix reminder scheduling and add group features

- Fix reminder duplicate bug: use slot-only keys to prevent multiple reminders when settings change
- Add New Jackpot announcement delay setting for groups (default 5 min)
- Cancel unpaid purchases after draw completes (prevents payments for past rounds)
- Add BotFather commands template file
- Update README documentation
This commit is contained in:
Michilis
2025-12-08 23:49:54 +00:00
parent 13fd2b8989
commit 86e2e0a321
10 changed files with 366 additions and 51 deletions

View File

@@ -242,6 +242,8 @@ async function checkAndExecuteDraws(): Promise<void> {
for (const cycle of result.rows) {
console.log(`Executing draw for cycle ${cycle.id} (${cycle.cycle_type})`);
await executeDraw(cycle.id);
// Cancel unpaid invoices for this cycle after draw
await cancelUnpaidPurchases(cycle.id);
}
} catch (error) {
@@ -249,6 +251,30 @@ async function checkAndExecuteDraws(): Promise<void> {
}
}
/**
* Cancel unpaid purchases after a draw completes
* This prevents payments for invoices from past rounds
*/
async function cancelUnpaidPurchases(cycleId: string): Promise<void> {
try {
const result = await db.query(
`UPDATE ticket_purchases
SET status = 'cancelled', updated_at = NOW()
WHERE cycle_id = $1
AND status = 'pending'
RETURNING id`,
[cycleId]
);
const cancelledCount = result.rows.length;
if (cancelledCount > 0) {
console.log(`Cancelled ${cancelledCount} unpaid purchases for cycle ${cycleId}`);
}
} catch (error) {
console.error('Error cancelling unpaid purchases:', error);
}
}
/**
* Update cycles to 'sales_open' status when appropriate
*/