feat(bot): add wizard state for reminder creation
This commit is contained in:
parent
01eb5752ee
commit
afd5fcb73b
@ -41,3 +41,53 @@ export function consumePendingSendToGroup(userId: number): string | null {
|
|||||||
if (Date.now() >= pending.expiresAt) return null;
|
if (Date.now() >= pending.expiresAt) return null;
|
||||||
return pending.groupId;
|
return pending.groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reminder creation wizard state.
|
||||||
|
export type WizardStep =
|
||||||
|
| "pick_account"
|
||||||
|
| "pick_group"
|
||||||
|
| "compose"
|
||||||
|
| "set_time"
|
||||||
|
| "confirm";
|
||||||
|
|
||||||
|
export type WizardState = {
|
||||||
|
step: WizardStep;
|
||||||
|
accountId?: string;
|
||||||
|
groupId?: string;
|
||||||
|
text?: string | null;
|
||||||
|
mediaId?: string | null;
|
||||||
|
caption?: string | null;
|
||||||
|
scheduledAt?: Date;
|
||||||
|
expiresAt: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const wizardState = new Map<number, WizardState>();
|
||||||
|
const WIZARD_TTL_MS = 30 * 60 * 1000;
|
||||||
|
|
||||||
|
export function getWizard(userId: number): WizardState | null {
|
||||||
|
const w = wizardState.get(userId);
|
||||||
|
if (!w) return null;
|
||||||
|
if (Date.now() >= w.expiresAt) {
|
||||||
|
wizardState.delete(userId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startWizard(userId: number): WizardState {
|
||||||
|
const w: WizardState = { step: "pick_account", expiresAt: Date.now() + WIZARD_TTL_MS };
|
||||||
|
wizardState.set(userId, w);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateWizard(userId: number, patch: Partial<WizardState>): WizardState | null {
|
||||||
|
const w = getWizard(userId);
|
||||||
|
if (!w) return null;
|
||||||
|
const next = { ...w, ...patch, expiresAt: Date.now() + WIZARD_TTL_MS };
|
||||||
|
wizardState.set(userId, next);
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearWizard(userId: number): void {
|
||||||
|
wizardState.delete(userId);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user