feat: improve cli setup flow

This commit is contained in:
Peter Steinberger
2026-01-08 05:32:49 +01:00
parent 6a684fdf6c
commit 9c9d191d6f
7 changed files with 206 additions and 85 deletions

45
src/cli/tagline.ts Normal file
View File

@@ -0,0 +1,45 @@
const DEFAULT_TAGLINE =
"Send, receive, and auto-reply on WhatsApp (web) and Telegram (bot).";
const TAGLINES: string[] = [];
type HolidayRule = (date: Date) => boolean;
const HOLIDAY_RULES = new Map<string, HolidayRule>();
function isTaglineActive(tagline: string, date: Date): boolean {
const rule = HOLIDAY_RULES.get(tagline);
if (!rule) return true;
return rule(date);
}
export interface TaglineOptions {
env?: NodeJS.ProcessEnv;
random?: () => number;
now?: () => Date;
}
export function activeTaglines(options: TaglineOptions = {}): string[] {
if (TAGLINES.length === 0) return [DEFAULT_TAGLINE];
const today = options.now ? options.now() : new Date();
const filtered = TAGLINES.filter((tagline) => isTaglineActive(tagline, today));
return filtered.length > 0 ? filtered : TAGLINES;
}
export function pickTagline(options: TaglineOptions = {}): string {
const env = options.env ?? process.env;
const override = env?.CLAWDBOT_TAGLINE_INDEX;
if (override !== undefined) {
const parsed = Number.parseInt(override, 10);
if (!Number.isNaN(parsed) && parsed >= 0) {
const pool = TAGLINES.length > 0 ? TAGLINES : [DEFAULT_TAGLINE];
return pool[parsed % pool.length];
}
}
const pool = activeTaglines(options);
const rand = options.random ?? Math.random;
const index = Math.floor(rand() * pool.length) % pool.length;
return pool[index];
}
export { TAGLINES, HOLIDAY_RULES, DEFAULT_TAGLINE };