Files
memind/wechat/night-summary-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

82 lines
2.4 KiB
JavaScript

import { getLocalParts, localDateKey, normalizeTimezone } from '../schedule-time.mjs';
import { pickDailyLibraryEntry } from './push-content/daily-library-pick.mjs';
export const NIGHT_SUMMARY_REFLECTIONS = Object.freeze([
'今天认真过就好,不必和完美较劲。',
'你已经比昨天更前进一步,这就值得晚安。',
'把未完成留给明天,把休息留给今晚。',
'今天的小收获,会在未来某天连起来。',
'允许自己慢下来,明天会继续。',
]);
export const NIGHT_TOMORROW_HINTS = Object.freeze([
'明天记得留一点空白给意外之喜。',
'明天优先处理最重要的一件事就好。',
'明天早起一杯水,会是很不错的开始。',
'明天如果有难的事,先拆成一小步再行动。',
'明天也别忘了,给自己留点轻松时间。',
]);
function hashString(input) {
let hash = 2166136261;
for (let i = 0; i < input.length; i += 1) {
hash ^= input.charCodeAt(i);
hash = Math.imul(hash, 16777619);
}
return Math.abs(hash);
}
export function formatNightDateLabel(now = Date.now(), timezone = 'Asia/Shanghai') {
const parts = getLocalParts(now, normalizeTimezone(timezone));
return `${parts.year}年${parts.month}月${parts.day}日`;
}
export function pickNightSummaryParts({
userId = '',
timezone = 'Asia/Shanghai',
now = Date.now(),
} = {}) {
const reflection = pickDailyLibraryEntry({
userId,
timezone,
now,
library: NIGHT_SUMMARY_REFLECTIONS,
salt: 'night-reflection',
});
const tomorrowHint = pickDailyLibraryEntry({
userId,
timezone,
now,
library: NIGHT_TOMORROW_HINTS,
salt: 'night-tomorrow',
});
return { reflection, tomorrowHint };
}
export function formatNightSummaryDeliveryText({
userId,
timezone = 'Asia/Shanghai',
now = Date.now(),
} = {}) {
const dateLabel = formatNightDateLabel(now, timezone);
const { reflection, tomorrowHint } = pickNightSummaryParts({ userId, timezone, now });
return [
`🌙 晚安总结 · ${dateLabel}`,
'',
`今日一句:${reflection}`,
'',
`明日提醒:${tomorrowHint}`,
'',
'晚安,好梦。',
'',
'回复「取消9」关闭推送',
].join('\n');
}
export function pickSurpriseVariantIndex({ userId, timezone, now }) {
const tz = normalizeTimezone(timezone);
const dateKey = localDateKey(now, tz);
const seed = hashString(`${String(userId)}:${dateKey}:surprise-variant`);
return seed % 3;
}