feat: 分离小煎蛋和michat的指令
All checks were successful
Egg Server CI/CD / build-image (push) Successful in 50s
Egg Server CI/CD / refresh-image (push) Successful in 14s
Egg Server CI/CD / fast-deploy (push) Successful in 2s

This commit is contained in:
zhaoyingbo 2024-10-23 09:44:56 +00:00
parent ae759108cf
commit 1153183869
3 changed files with 103 additions and 50 deletions

View File

@ -15,7 +15,8 @@ const tempMap = {
successMsg: "ctp_AA0LgXOkEOPK",
errorMsg: "ctp_AA0LgXOkEuqi",
chatId: "ctp_AAi3NnHb6zgK",
guide: "ctp_AAyVx5R39xU9",
eggGuide: "ctp_AAyVx5R39xU9",
miChatGuide: "AAqDiiTs4kSN9",
createKVSuccess: "ctp_AA00oqPWPXtG",
}

View File

@ -1,5 +1,6 @@
import { type LarkBody } from "@egg/lark-msg-tool"
import tempMap from "../../constant/template"
import db from "../../db"
import { Context } from "../../types"
import createKVTemp from "../sheet/createKVTemp"
@ -93,14 +94,13 @@ const manageIdMsg = ({
*
* @param {Context.Data} ctx -
*/
const manageHelpMsg = ({
larkBody: { chatId },
larkCard,
larkService,
}: Context.Data): void => {
const manageHelpMsg = (
{ larkBody: { chatId }, larkCard, larkService }: Context.Data,
tempKey: keyof typeof tempMap
): void => {
larkService.message.sendCard2Chat(
chatId,
larkCard.genTempCard("guide", { chat_id: chatId }) as string
larkCard.genTempCard(tempKey, { chat_id: chatId }) as string
)
}
@ -110,6 +110,7 @@ const manageHelpMsg = ({
*/
const manageCMDMsg = (ctx: Context.Data) => {
const {
app,
body,
logger,
larkService,
@ -123,44 +124,61 @@ const manageCMDMsg = (ctx: Context.Data) => {
manageIdMsg(ctx)
return
}
// 帮助
if (msgText.trim() === "/help") {
logger.info(`bot command is /help, chatId: ${chatId}`)
manageHelpMsg(ctx)
return
}
// CI监控
if (msgText.trim() === "/ci") {
logger.info(`bot command is /ci, chatId: ${chatId}`)
attachService.ciMonitor(chatId)
return
}
// 简报
if (msgText.includes("share") && msgText.includes("简报")) {
logger.info(`bot command is share report, chatId: ${chatId}`)
// 这个用时比较久,先发一条提醒用户收到了请求
// TODO: 迁移到简报服务中
larkService.message.send(
"chat_id",
chatId,
"text",
"正在为您收集简报,请稍等片刻~"
)
attachService.reportCollector(body)
return
}
// 创建Sheet DB
if (msgText.trim() === "/gen db") {
logger.info(`bot command is /gen db, chatId: ${chatId}`)
createKVTemp.createFromEvent(ctx)
return
}
// 选择群组信息
if (msgText.trim().startsWith("/groupchat")) {
if (msgText.trim().startsWith("/g")) {
logger.info(`bot command is /groupchat, chatId: ${chatId}`)
groupAgent(ctx)
return
}
// michat专属功能
if (app === "michat") {
// 帮助
if (msgText.trim() === "/help") {
logger.info(`bot command is /help, chatId: ${chatId}`)
manageHelpMsg(ctx, "miChatGuide")
return
}
}
// 小煎蛋专属功能
if (app === "egg") {
// CI监控
if (msgText.trim() === "/ci") {
logger.info(`bot command is /ci, chatId: ${chatId}`)
attachService.ciMonitor(chatId)
return
}
// 简报
if (msgText.includes("share") && msgText.includes("简报")) {
logger.info(`bot command is share report, chatId: ${chatId}`)
// 这个用时比较久,先发一条提醒用户收到了请求
// TODO: 迁移到简报服务中
larkService.message.send(
"chat_id",
chatId,
"text",
"正在为您收集简报,请稍等片刻~"
)
attachService.reportCollector(body)
return
}
// 创建Sheet DB
if (msgText.trim() === "/gen db") {
logger.info(`bot command is /gen db, chatId: ${chatId}`)
createKVTemp.createFromEvent(ctx)
return
}
// 帮助
if (msgText.trim() === "/help") {
logger.info(`bot command is /help, chatId: ${chatId}`)
manageHelpMsg(ctx, "eggGuide")
return
}
}
return
}

View File

@ -1,14 +1,48 @@
import { LarkService } from "../../services"
// import logger from "@egg/logger"
const service = new LarkService("egg", "")
// import getChatHistory from "../../routes/bot/groupAgent/chatHistory"
// import { LarkService } from "../../services"
const currentTime = Math.floor(new Date().getTime() / 1000)
const yesterdayTime = currentTime - 24 * 60 * 60
// const service = new LarkService("michat", "")
const res = await service.message.getHistory(
"oc_c83f627bde3da39b01bbbfb026a00111",
yesterdayTime.toString(),
currentTime.toString()
)
// const currentTime = Math.floor(new Date().getTime() / 1000)
// const weekAgoTime = currentTime - 7 * 24 * 60 * 60
console.log(JSON.stringify(res, null, 2))
// const res = await service.message.getHistory(
// "oc_bd23da1ae9948654fc04365d7d102d73",
// weekAgoTime.toString(),
// currentTime.toString()
// )
// // const res = await getChatHistory(
// // { larkService: service, logger: logger },
// // {
// // chatId: "oc_bd23da1ae9948654fc04365d7d102d73",
// // timeScope: "",
// // startTime: "2024-10-16 00:00:00",
// // endTime: "2024-10-24 00:00:00",
// // mentions: [],
// // }
// // )
// // {
// // "user": "左建光",
// // "content": "Anthropic经过一番操作已经是和openai并肩的AI双雄了[呲牙]",
// // "time": "2024/10/23 09:25:33"
// // },
// // {
// // "user": "魏柏楠",
// // "content": "@Mi Chat /id",
// // "time": "2024/10/23 10:02:42"
// // }
// console.log(JSON.stringify(res, null, 2))
// // 把res内容输出到csv文件保留user、content、time字段使用逗号分隔
// // 手写代码实现
// const fileContent = res
// .filter(({ user, content, time }) => user && content && time)
// .map(
// ({ user, content, time }) =>
// `${time},${user},${content.replace(/,/g, "").replace(/\n/g, " ")}`
// )
// .join("\n")
// await Bun.write("output.csv", fileContent)