Files
memind/wechat/daily-surprise-library.mjs
john 830f8a4011
Memind CI / Test, build, and release guards (push) Successful in 5m36s
feat(wechat): add service-account push subscriptions and news morning cover delivery
Ship the 10-item numeric subscription loop on WeChat MP, wire schedule delivery
for news/weather/quote/health/finance/tech/knowledge/night/surprise pushes, and
extend news morning draft cover generation plus a one-shot draft push script.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 16:15:15 +08:00

100 lines
3.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { pickDailyLibraryEntry } from './push-content/daily-library-pick.mjs';
import {
extractCardsFromSectionIds,
loadTodayNewsMorningHtml,
} from './push-content/news-section-extract.mjs';
import { pickSurpriseVariantIndex } from './night-summary-library.mjs';
export const SURPRISE_COLD_FACTS = Object.freeze([
'蜂鸟是唯一能够倒着飞的鸟类。',
'章鱼有三颗心脏,血液是蓝色的。',
'香蕉在植物学上属于浆果,草莓反而不是。',
'人类鼻子能识别超过万亿种不同气味组合。',
'月球正在以每年约 3.8 厘米的速度远离地球。',
]);
export const SURPRISE_FUN_FACTS = Object.freeze([
'「OK」可能源自 19 世纪美国「oll korrect」的幽默拼写。',
'世界上最长的地名之一在新西兰,长达 85 个字母。',
'咖啡最早被当作食物而不是饮料来食用。',
'企鹅求偶时会送一颗小石子给心仪对象。',
'古代罗马人曾用海绵绑在长棍上当作「厕纸」。',
]);
export const SURPRISE_TRIVIA = Object.freeze([
'今天试试用左手刷牙,给大脑一点新鲜刺激。',
'随机给一位朋友发一句感谢,关系会悄悄升温。',
'把你桌面最乱的一个角落整理 5 分钟,心情会轻一点。',
'找一首没听过的歌,当作今天的背景音。',
'写下今天一件「虽小但不错」的事,留给未来的自己看。',
]);
export function pickDailySurpriseText({
userId = '',
timezone = 'Asia/Shanghai',
now = Date.now(),
variant = null,
} = {}) {
const resolvedVariant = variant ?? pickSurpriseVariantIndex({ userId, timezone, now });
const libraries = [SURPRISE_COLD_FACTS, SURPRISE_FUN_FACTS, SURPRISE_TRIVIA];
const labels = ['冷知识', '趣闻', '今日小挑战'];
const library = libraries[resolvedVariant] ?? SURPRISE_COLD_FACTS;
const label = labels[resolvedVariant] ?? '惊喜';
const text = pickDailyLibraryEntry({
userId,
timezone,
now,
library,
salt: `surprise:${label}`,
});
return { label, text };
}
export function formatDailySurpriseDeliveryText({
userId,
timezone = 'Asia/Shanghai',
now = Date.now(),
payload = null,
} = {}) {
const resolved = payload ?? pickDailySurpriseText({ userId, timezone, now });
return [
'🎁 每日惊喜',
'',
`【${resolved.label}】${resolved.text}`,
'',
'回复「取消10」关闭推送',
].join('\n');
}
export async function formatSurprisePushDelivery(options = {}) {
const { html, dateLabel } = await loadTodayNewsMorningHtml(options);
if (html) {
const historyCards = extractCardsFromSectionIds(html, ['history']);
const card = historyCards[0];
if (card) {
const summary = card.context ? `${card.title}:${card.context}` : card.title;
return {
text: formatDailySurpriseDeliveryText({
userId: options.userId,
timezone: options.timezone,
now: options.now,
payload: {
label: dateLabel ? `历史上的今天 · ${dateLabel}` : '历史上的今天',
text: summary,
},
}),
verifiedHtmlUrls: [],
};
}
}
return {
text: formatDailySurpriseDeliveryText({
userId: options.userId,
timezone: options.timezone,
now: options.now,
}),
verifiedHtmlUrls: [],
};
}