feat: 添加夸一下的内容

This commit is contained in:
2025-06-25 11:35:16 +08:00
parent b807cc9f38
commit bce94f52a0
8 changed files with 124 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
import { nanoid } from 'nanoid';
import { agent } from './agent.ts';
import { ai } from './ai.ts';
import { cmdList } from './analyze/cmd.ts';
/**
* 清除文本中的@信息
* @param text
@@ -10,33 +11,6 @@ const clearAtInfo = (text: string = '') => {
return newText.trim();
};
const cmdList: {
cmd: string;
description?: string;
callPath?: {
path?: string;
key?: string;
};
}[] = [
{
cmd: '指令夸人',
description: `进行夸奖`,
callPath: {
path: 'tools',
key: 'good-job',
},
},
];
const getTextCmd = (text: string, cmdList = []) => {
const text20 = text.length > 20 ? text.slice(0, 20) : text;
const cmd = cmdList.find((item) => text20.includes(item.cmd));
if (cmd) {
return cmd;
}
return {
cmd: undefined,
};
};
agent
.route({
path: 'xhs',
@@ -45,20 +19,29 @@ agent
const { text = '' } = ctx.query || {};
const id = nanoid();
const no_at_text = clearAtInfo(text);
const cmd = getTextCmd(no_at_text, cmdList);
if (cmd.cmd) {
const newText = no_at_text.replace(cmd.cmd, '').trim();
if (cmd.callPath) {
const res = await agent.call({
path: cmd.callPath.path,
key: cmd.callPath.key,
payload: {
text: newText,
},
});
ctx.body = res.body || '';
const some_text = no_at_text.length > 20 ? no_at_text.slice(0, 20) : no_at_text;
const hasCmd = some_text.includes('指令');
if (hasCmd) {
const analyzeRes = await agent.call({
path: 'analyze',
key: 'cmd',
payload: {
text: no_at_text,
},
});
if (analyzeRes.code === 200) {
const cmd = analyzeRes.body?.cmd;
if (cmd) {
const res = await agent.call({
...cmd.action,
payload: {
text: no_at_text,
},
});
ctx.body = res.body || '';
return;
}
}
return;
}
const resFix = await agent.call({
path: 'fix',