feat: 自己的笔记也需要at才能评论了,优化一下

This commit is contained in:
2025-06-22 09:30:03 +08:00
parent 71359fba88
commit 530a4f21f5
7 changed files with 78 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import { agent } from '@/agent/index.ts';
import { taskApp, queue, xhsApp } from '../task.ts';
import { taskApp, queue, xhsApp, xhsServices } from '../task.ts';
import { random, omit } from 'lodash-es';
import util from 'node:util';
@@ -111,14 +111,29 @@ taskApp
.define(async (ctx) => {
const data = ctx.query.data; // 为提及的相关信息
const note_id = data.note_id;
const note_userid = data.note_userid;
const note_username = data.note_username;
// 检测是这个用户的username的笔记如果是的话需要有at的用户信息才继续。
const isOwner = xhsServices.isOwner({ username: note_username, userid: note_userid });
const xsec_token = data.xsec_token;
const comment_id = data.comment.comment_id;
const content = data.comment?.content || 'test';
let content: string = data.comment?.content || 'test';
const postData = {
note_id,
content,
comment_id,
};
if (isOwner) {
// 如果是自己的笔记,且笔记不包含 @信息 则不需要AI回复,
const hasAt = content.includes('@' + note_username) || content.includes('@' + note_userid);
if (!hasAt) {
// console.log('不需要AI回复自己的笔记', note_username, note_id, content);
return;
}
}
content = content.replace('@' + note_username, '');
const resAgent = await agent.call({
path: 'xhs',
payload: {

View File

@@ -3,16 +3,23 @@
import { QueryRouterServer } from '@kevisual/router';
import { redis } from '@/modules/redis.ts';
import { Queue } from 'bullmq';
import { app as xhsApp, xhsServices, xhsRootClient, XhsClient } from '@kevisual/xhs/index';
import { app as xhsApp, xhsServices as xhs, xhsRootClient, XhsServices } from '@kevisual/xhs/index.ts';
import { nanoid } from 'nanoid';
export const XHS_GET_UNREAD = 'unread_count';
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
import { config } from '../modules/config.ts';
const xhsClient: XhsClient = xhsRootClient;
xhsClient.setCookie(config.XHS_ROOT_COOKIE || '');
console.log('XHS_ROOT_COOKIE', xhsClient.cookie);
const server: XhsServices = xhs;
server.setCookie(config.XHS_ROOT_COOKIE || '');
server.setUserInfo({
userid: config.XHS_USER_ID || '',
username: config.XHS_USER_NAME || '',
});
console.log('XHS_USER_INFO', config.XHS_USER_ID, config.XHS_USER_NAME, 'XHS_ROOT_COOKIE', config.XHS_ROOT_COOKIE);
export const taskApp = new QueryRouterServer();
export { xhsApp, xhsServices, xhsRootClient };
export { xhsApp };
export const xhsServices = server;
export const queue = new Queue(XHS_QUEUE_NAME, {
connection: redis,
});