generated from tailored/router-db-template
temp
This commit is contained in:
@@ -9,6 +9,34 @@ const clearAtInfo = (text: string = '') => {
|
||||
const newText = text.replace(/@[\u4e00-\u9fa5\w]+/g, '').replace(/#.*?#/g, '');
|
||||
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',
|
||||
@@ -17,6 +45,21 @@ 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 || '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
const resFix = await agent.call({
|
||||
path: 'fix',
|
||||
key: 'xhs',
|
||||
|
||||
Reference in New Issue
Block a user