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:
@@ -6,6 +6,7 @@ import {
|
||||
GroupSettings,
|
||||
REMINDER_PRESETS,
|
||||
ANNOUNCEMENT_DELAY_OPTIONS,
|
||||
NEW_JACKPOT_DELAY_OPTIONS,
|
||||
DEFAULT_GROUP_REMINDER_SLOTS,
|
||||
ReminderTime,
|
||||
formatReminderTime,
|
||||
@@ -268,6 +269,20 @@ export async function handleGroupSettingsCallback(
|
||||
}
|
||||
}
|
||||
|
||||
// Handle new jackpot delay selection
|
||||
if (action.startsWith('newjackpot_delay_')) {
|
||||
const minutes = parseInt(action.replace('newjackpot_delay_', ''), 10);
|
||||
if (!isNaN(minutes)) {
|
||||
updatedSettings = await groupStateManager.updateNewJackpotDelay(chatId, minutes);
|
||||
if (updatedSettings) {
|
||||
logUserAction(userId, 'Updated new jackpot delay', { groupId: chatId, minutes });
|
||||
await bot.answerCallbackQuery(query.id, {
|
||||
text: minutes === 0 ? 'Announce immediately' : `Announce ${minutes} min after new jackpot`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle reminder time adjustments (reminder1_add_1_hours, reminder2_sub_1_days, etc.)
|
||||
const reminderTimeMatch = action.match(/^reminder(\d)_(add|sub)_(\d+)_(minutes|hours|days)$/);
|
||||
if (reminderTimeMatch) {
|
||||
@@ -334,7 +349,7 @@ export async function handleGroupSettingsCallback(
|
||||
|
||||
|
||||
/**
|
||||
* Format delay option for display
|
||||
* Format delay option for display (seconds)
|
||||
*/
|
||||
function formatDelayOption(seconds: number): string {
|
||||
if (seconds === 0) return 'Instant';
|
||||
@@ -345,6 +360,14 @@ function formatDelayOption(seconds: number): string {
|
||||
return `${seconds}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format new jackpot delay option for display (minutes)
|
||||
*/
|
||||
function formatNewJackpotDelay(minutes: number): string {
|
||||
if (minutes === 0) return 'Instant';
|
||||
return minutes === 1 ? '1 min' : `${minutes} min`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time adjustment buttons for a reminder slot
|
||||
*/
|
||||
@@ -385,12 +408,23 @@ function getGroupSettingsKeyboard(settings: GroupSettings): TelegramBot.InlineKe
|
||||
text: `${onOff(settings.newJackpotAnnouncement)} New Jackpot Announcement`,
|
||||
callback_data: 'group_toggle_newjackpot',
|
||||
}],
|
||||
[{
|
||||
text: `${onOff(settings.drawAnnouncements)} Draw Result Announcements`,
|
||||
callback_data: 'group_toggle_announcements',
|
||||
}],
|
||||
];
|
||||
|
||||
// Add new jackpot delay options if enabled
|
||||
if (settings.newJackpotAnnouncement !== false) {
|
||||
keyboard.push(
|
||||
NEW_JACKPOT_DELAY_OPTIONS.map(minutes => ({
|
||||
text: `${selected(settings.newJackpotDelayMinutes ?? 5, minutes)} ${formatNewJackpotDelay(minutes)}`,
|
||||
callback_data: `group_newjackpot_delay_${minutes}`,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
keyboard.push([{
|
||||
text: `${onOff(settings.drawAnnouncements)} Draw Result Announcements`,
|
||||
callback_data: 'group_toggle_announcements',
|
||||
}]);
|
||||
|
||||
// Add announcement delay options if announcements are enabled
|
||||
if (settings.drawAnnouncements) {
|
||||
keyboard.push(
|
||||
|
||||
Reference in New Issue
Block a user