Files
Moltbot/src/cli/tagline.ts
2026-01-08 06:02:36 +01:00

47 lines
1.4 KiB
TypeScript

const DEFAULT_TAGLINE = "All your chats, one ClawdBot.";
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 };