cbcec96306
Memind CI / Test, build, and release guards (push) Has been cancelled
Bare “页面”, daily page titles, link requests, and short edits after a side question were leaving the original page task. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
/** Explicit WeChat channel prefixes so users can separate chat, page, and scheduled tasks. */
|
||
|
||
export const WECHAT_CHANNEL_PREFIX = Object.freeze({
|
||
CHAT: 'chat',
|
||
PAGE: 'page',
|
||
SCHEDULED_TASK: 'scheduled_task',
|
||
});
|
||
|
||
const PREFIX_ENTRIES = Object.freeze([
|
||
{
|
||
channel: WECHAT_CHANNEL_PREFIX.CHAT,
|
||
pattern: /^【?\s*聊天\s*】?[::\s]*/iu,
|
||
},
|
||
{
|
||
channel: WECHAT_CHANNEL_PREFIX.PAGE,
|
||
pattern: /^(?:【\s*(?:改页|做页|页面)\s*】\s*|(?:改页|做页|页面)\s*[::])\s*/iu,
|
||
},
|
||
{
|
||
channel: WECHAT_CHANNEL_PREFIX.SCHEDULED_TASK,
|
||
pattern: /^【?\s*定时任务\s*】?[::\s]*/iu,
|
||
},
|
||
]);
|
||
|
||
/**
|
||
* @returns {{ channel: string|null, body: string, hadPrefix: boolean }}
|
||
*/
|
||
export function parseWechatChannelPrefix(text) {
|
||
const normalized = String(text ?? '').trim();
|
||
if (!normalized) {
|
||
return { channel: null, body: '', hadPrefix: false };
|
||
}
|
||
for (const entry of PREFIX_ENTRIES) {
|
||
if (!entry.pattern.test(normalized)) continue;
|
||
return {
|
||
channel: entry.channel,
|
||
body: normalized.replace(entry.pattern, '').trim(),
|
||
hadPrefix: true,
|
||
};
|
||
}
|
||
return { channel: null, body: normalized, hadPrefix: false };
|
||
}
|
||
|
||
export function stripWechatChannelPrefix(text) {
|
||
return parseWechatChannelPrefix(text).body;
|
||
}
|
||
|
||
export function hasWechatPageChannelPrefix(text) {
|
||
return parseWechatChannelPrefix(text).channel === WECHAT_CHANNEL_PREFIX.PAGE;
|
||
}
|