feat: 优化消息处理逻辑,支持私聊场景和简化群组命令

This commit is contained in:
zhaoyingbo 2024-12-02 06:35:37 +00:00
parent bbbeabe3d8
commit c84901a680

View File

@ -47,10 +47,10 @@ const filterIllegalMsg = async ({
// 非表情包只在私聊或者群聊中艾特机器人时才回复
else {
logger.info(`got a illegal message, chatId: ${chatId}`)
const content = JSON.stringify({
text: "哇!这是什么东东?我只懂普通文本啦![可爱]",
})
larkService.message.send("chat_id", chatId, "text", content)
larkService.message.sendText2Chat(
chatId,
"哇!这是什么东东?我只懂普通文本啦![可爱]"
)
}
// 非纯文本,全不放行
@ -97,7 +97,7 @@ const manageCMDMsg = (ctx: Context.Data) => {
logger,
larkService,
attachService,
larkBody: { msgText, chatId, isInGroup },
larkBody: { msgText, chatId, isInGroup, isP2P },
} = ctx
logger.info(`bot req text: ${msgText}`)
@ -108,34 +108,6 @@ const manageCMDMsg = (ctx: Context.Data) => {
return
}
// 仅限群组功能
if (isInGroup) {
// 注册群组
if (msgText === "开启日报、周报") {
logger.info(`bot command is register, chatId: ${chatId}`)
groupAgent.report.subscribe(ctx)
return
}
// 注销群组
if (msgText === "关闭日报、周报") {
logger.info(`bot command is unregister, chatId: ${chatId}`)
groupAgent.report.unsubscribe(ctx)
return
}
// // 立即发送日简报
// if (msgText === "总结日报") {
// logger.info(`bot command is summary, chatId: ${chatId}`)
// groupAgent.report.gen4Test(ctx, "daily")
// return
// }
// // 立即发送周简报
// if (msgText === "总结周报") {
// logger.info(`bot command is summary, chatId: ${chatId}`)
// groupAgent.report.gen4Test(ctx, "weekly")
// return
// }
}
// 小煎蛋专属功能
if (app === "egg") {
// CI监控
@ -165,20 +137,39 @@ const manageCMDMsg = (ctx: Context.Data) => {
return
}
// 帮助
if (msgText === "/help") {
// 私聊场景下或者/help命令
if (msgText === "/help" || isP2P) {
logger.info(`bot command is /help, chatId: ${chatId}`)
manageHelpMsg(ctx, "eggGuide")
return
}
}
// 如果是群聊使用groupAgent兜底
if (isInGroup) {
groupAgent.agent(ctx)
// michat私聊场景下先回复提示消息
if (isP2P && app === "michat") {
logger.info(`bot command is /help, chatId: ${chatId}`)
manageHelpMsg(ctx, "miChatGuide")
return
}
// 仅限群组功能
if (isInGroup) {
// 注册群组
if (msgText === "开启日报、周报") {
logger.info(`bot command is register, chatId: ${chatId}`)
groupAgent.report.subscribe(ctx)
return
}
// 注销群组
if (msgText === "关闭日报、周报") {
logger.info(`bot command is unregister, chatId: ${chatId}`)
groupAgent.report.unsubscribe(ctx)
return
}
// 使用GroupAgent兜底
groupAgent.agent(ctx)
return
}
return
}