feat: command handlers
Add all 11 Telegraf command handler files (tasks 12–16): log, skip, status, history, streak, snooze, settings-cmd, progress, next, reschedule, chat, and setup (including multi-step onboarding flow). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user