import type { Context } from 'telegraf'; import type { Database } from 'better-sqlite3'; import { todayString } from '../../utils/date'; import { getScheduleByDate, updateScheduleStatus } from '../../db/schedule'; import { getSessionByDate } from '../../db/sessions'; export function handleSkip(db: Database) { return async (ctx: Context) => { const text = (ctx.message as { text?: string })?.text ?? ''; const reason = text.split(/\s+/).slice(1).join(' ') || null; const today = todayString(); const session = getSessionByDate(db, today); if (session) { await ctx.reply(`You already logged a session today (${session.duration_min}m). Nothing to skip.`); return; } const scheduled = getScheduleByDate(db, today); if (!scheduled) { await ctx.reply('No session scheduled for today anyway.'); return; } if (scheduled.status !== 'pending') { await ctx.reply(`Today's session is already marked as ${scheduled.status}.`); return; } updateScheduleStatus(db, today, 'skipped', reason); const msg = reason ? `Skipped today (${reason}). The AI will account for this next time you reschedule.` : 'Skipped today. The AI will account for this next time you reschedule.'; await ctx.reply(msg); }; }