830f8a4011
Memind CI / Test, build, and release guards (push) Successful in 5m36s
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>
27 lines
798 B
JavaScript
27 lines
798 B
JavaScript
import { localDateKey, normalizeTimezone } from '../../schedule-time.mjs';
|
|
|
|
export 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);
|
|
}
|
|
|
|
/** 按用户 + 本地日期 + salt 从话术库稳定选取一条。 */
|
|
export function pickDailyLibraryEntry({
|
|
userId = '',
|
|
timezone = 'Asia/Shanghai',
|
|
now = Date.now(),
|
|
library = [],
|
|
salt = 'daily',
|
|
} = {}) {
|
|
const pool = Array.isArray(library) && library.length ? library : [];
|
|
if (!pool.length) return '';
|
|
const tz = normalizeTimezone(timezone);
|
|
const dateKey = localDateKey(now, tz);
|
|
const seed = hashString(`${String(userId)}:${dateKey}:${salt}`);
|
|
return pool[seed % pool.length];
|
|
}
|