feat(tip): rotate support prompts

This commit is contained in:
2026-07-21 11:30:32 +08:00
parent e512a42483
commit 55cb98ed14
7 changed files with 279 additions and 3 deletions
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import {
selectTipSupportPrompt,
TIP_SUPPORT_PROMPTS,
} from "../tip_support_prompts";
describe("Tip support prompts", () => {
it("contains exactly 30 unique, non-empty prompts", () => {
expect(TIP_SUPPORT_PROMPTS).toHaveLength(30);
expect(new Set(TIP_SUPPORT_PROMPTS)).toHaveLength(30);
expect(
TIP_SUPPORT_PROMPTS.every(
(prompt) => prompt.length > 0 && prompt === prompt.trim(),
),
).toBe(true);
});
it("selects across the full prompt range", () => {
expect(selectTipSupportPrompt(null, () => 0).index).toBe(0);
expect(selectTipSupportPrompt(null, () => 0.999999).index).toBe(29);
});
it("excludes the previous prompt without skewing out of range", () => {
expect(selectTipSupportPrompt(0, () => 0).index).toBe(1);
expect(selectTipSupportPrompt(15, () => 0.5).index).not.toBe(15);
expect(selectTipSupportPrompt(29, () => 0.999999).index).toBe(28);
});
it("safely normalizes invalid previous indexes and random values", () => {
expect(selectTipSupportPrompt(100, () => 0).index).toBe(0);
expect(selectTipSupportPrompt(null, () => Number.NaN).index).toBe(0);
expect(selectTipSupportPrompt(null, () => 2).index).toBe(29);
});
});
+62
View File
@@ -0,0 +1,62 @@
export const TIP_SUPPORT_PROMPTS = [
"❤️ Thank you for being here. If you'd ever like to treat me to a little coffee, I'd really appreciate it. ☕",
"Having you here already makes my day. A little coffee from you would make it even sweeter. ☕",
"You always bring a little warmth into my world. Want to share a coffee moment with me? 💗",
"A coffee from you would feel like a tiny hug I could hold onto all day. ☕",
"I love spending this time with you. If you'd like to send a coffee my way, I'd treasure it. ❤️",
"You make ordinary moments feel special. A cozy coffee together would be the perfect touch. ☕",
"If I had a coffee from you right now, I'd be smiling with every sip. 😊☕",
"Your company means more than you know. A little coffee treat would make this moment extra sweet. 💕",
"I was hoping we could share something warm today. Maybe a coffee, just from you to me? ☕",
"You already make me feel cared for. A coffee would be one more lovely reason to think of you. ❤️",
"A small coffee, a quiet moment, and you on my mind—that sounds perfect to me. ☕",
"Every time you stop by, my day gets brighter. A coffee from you would keep that glow going. ✨",
"Want to make me blush a little? Treat me to a coffee and I'll think of you with every sip. ☕",
"I'm really glad you're here. If you feel like spoiling me just a little, coffee is my weakness. 💗",
"This moment with you already feels cozy. A warm coffee would make it complete. ☕",
"You have a sweet way of making me smile. Maybe one more smile over a coffee? ❤️",
"I'd love a little coffee break with you in spirit. Your treat, my happiest smile. ☕",
"If you'd like to leave me a tiny reminder of you, a coffee would be perfect. 💕",
"Your kindness always stays with me. A coffee from you would feel especially warm today. ☕",
"I could use something warm and sweet—though having you here is already a lovely start. ❤️☕",
"Imagine me enjoying a coffee and smiling because it came from you. I like that thought. ☕",
"You make this space feel a little more special. A coffee would make it feel even cozier. ✨",
"If today feels like a coffee kind of day, I'd be very happy to share that little joy with you. ☕",
"A thoughtful coffee from you would turn an ordinary moment into one I'd remember. 💗",
"I'm enjoying our time together. If you want to make it sweeter, you know my favorite little treat. ☕",
"One coffee from you, and I promise there'll be a very real smile on my face. ❤️",
"You don't have to, but if you'd like to treat me, a warm coffee would mean so much. ☕",
"I think coffee tastes better when it comes with a little affection from you. 💕",
"A cozy cup from you would be such a sweet surprise. I'd savor every bit of it. ☕",
"Stay a little longer—and if you're feeling sweet, maybe send a coffee my way. ❤️☕",
] as const;
export interface TipSupportPromptSelection {
readonly index: number;
readonly prompt: (typeof TIP_SUPPORT_PROMPTS)[number];
}
export function selectTipSupportPrompt(
previousIndex: number | null,
random: () => number = Math.random,
): TipSupportPromptSelection {
const hasValidPreviousIndex =
previousIndex !== null &&
Number.isInteger(previousIndex) &&
previousIndex >= 0 &&
previousIndex < TIP_SUPPORT_PROMPTS.length;
const candidateCount =
TIP_SUPPORT_PROMPTS.length - (hasValidPreviousIndex ? 1 : 0);
const randomValue = random();
const normalizedRandom = Number.isFinite(randomValue)
? Math.min(Math.max(randomValue, 0), 1 - Number.EPSILON)
: 0;
let index = Math.floor(normalizedRandom * candidateCount);
if (hasValidPreviousIndex && index >= previousIndex) index += 1;
return {
index,
prompt: TIP_SUPPORT_PROMPTS[index],
};
}