This commit is contained in:
张成
2026-03-17 10:50:49 +08:00
parent f5082c157c
commit f071215ad5
3 changed files with 103 additions and 10 deletions

View File

@@ -205,17 +205,27 @@ class ChatManager {
return false;
}
/** 统一 uid 为可比较的字符串(支持 number 或 { low, high } */
_normalizeUid(uid) {
if (uid == null) return null;
if (typeof uid === 'number' || typeof uid === 'string') return String(uid);
if (typeof uid === 'object' && typeof uid.low === 'number') return String(uid.low);
return null;
}
/** 过滤出 HR 发的、非系统、可回复的消息列表(已排除自己发的) */
_filterHrReplyableMessages(messages, geek_uid) {
if (!geek_uid || !Array.isArray(messages)) return [];
let list = messages.filter(msg => {
if (!msg.from || msg.from.uid === geek_uid) return false;
const geekStr = this._normalizeUid(geek_uid);
if (!geekStr) return [];
const list = messages.filter(msg => {
if (!msg.from) return false;
const fromStr = this._normalizeUid(msg.from.uid);
if (fromStr === geekStr) return false; // 自己发的,排除
if (this._isSystemMessage(msg)) return false;
return true;
});
return list
return list;
}
/** AI 回复后写入 chat_reply_intent_logoptions 含 sn_code/platform/friendId/encryptFriendIdsecurityId 为 HR 消息唯一 id */
@@ -299,12 +309,14 @@ class ChatManager {
const logModel = db.getModel('chat_reply_intent_log');
const existing = await logModel.findOne({ where: { security_id } });
if (existing) {
// 已回复过的 HR 消息:不再重复发,避免每次扫描都发一条
if (existing.replied) {
return { replied: false, reason: '该条HR消息已回复过跳过' };
}
// 之前记录为不回复:直接沿用,不再调 AI
return {
replied: !!existing.replied,
action: existing.action || 'text',
reply_content: existing.reply_content || '',
hr_message_text: existing.hr_message_text || hr_message_text,
reason: existing.reason || null
replied: false,
reason: existing.reason || '已记录为不回复'
};
}
} catch (e) {