Maintenance mode activates after current draw completes

- When admin enables maintenance, it's set to 'pending' state
- Maintenance activates automatically after the current draw completes
- Admin can use immediate=true to force immediate activation
- Frontend shows 'Maintenance Scheduled' banner when pending
- Telegram bot warns users but still allows purchases when pending
- Both mode and pending status tracked in system_settings table
This commit is contained in:
Michilis
2025-12-09 00:46:55 +00:00
parent 0eb8a6c580
commit 404fdf2610
12 changed files with 474 additions and 4 deletions

View File

@@ -33,6 +33,26 @@ export async function handleBuyCommand(
logUserAction(userId, 'Initiated ticket purchase');
try {
// Check maintenance mode first
const maintenance = await apiClient.checkMaintenanceStatus();
if (maintenance.enabled) {
await bot.sendMessage(
chatId,
messages.errors.maintenance(maintenance.message || 'System is under maintenance.'),
{ parse_mode: 'Markdown' }
);
return;
}
// Warn if maintenance is pending (but still allow purchase)
if (maintenance.pending) {
await bot.sendMessage(
chatId,
messages.errors.maintenancePending,
{ parse_mode: 'Markdown' }
);
}
const user = await stateManager.getUser(userId);
if (!user) {

View File

@@ -20,6 +20,17 @@ export const messages = {
checkStatusFailed: '❌ Failed to check status',
noPendingPurchase: '❌ No pending purchase. Please start again with /buyticket',
setAddressFirst: '❌ Please set your Lightning Address first.',
maintenance: (message: string) => `🔧 *Maintenance Mode*
${message}
Please try again later. We'll be back soon! ⚡`,
maintenancePending: `⏳ *Maintenance Scheduled*
Maintenance will begin after the current draw completes.
This is your *last chance* to buy tickets for the current round! 🎟️`,
},
// ═══════════════════════════════════════════════════════════════════════════

View File

@@ -138,6 +138,25 @@ class ApiClient {
return false;
}
}
/**
* Check if system is in maintenance mode
*/
async checkMaintenanceStatus(): Promise<{ enabled: boolean; pending: boolean; message: string | null }> {
try {
const response = await this.client.get<ApiResponse<{ maintenance_mode: boolean; maintenance_pending: boolean; message: string | null }>>(
'/status/maintenance'
);
return {
enabled: response.data.data.maintenance_mode,
pending: response.data.data.maintenance_pending,
message: response.data.data.message,
};
} catch (error) {
// If endpoint doesn't exist or fails, assume not in maintenance
return { enabled: false, pending: false, message: null };
}
}
}
export const apiClient = new ApiClient();