feat: 完成海龟汤Server请求

This commit is contained in:
zhaoyingbo 2025-01-13 08:39:29 +00:00
parent be1805566b
commit 6b34c6538a
3 changed files with 60 additions and 6 deletions

View File

@ -0,0 +1,13 @@
import db from "../../db"
import { Context } from "../../types"
/**
*
* @param ctx
* @param value
*/
const startOrStopGame = async (ctx: Context, value: boolean) => {
const chat = await db.chat.getAndCreate(ctx)
if (!chat) {
throw new Error("chat not found")
}
}

View File

@ -4,6 +4,16 @@ import groupAgent from "../../controller/groupAgent"
import createKVTemp from "../../controller/sheet/createKVTemp"
import { Context } from "../../types"
/**
*
* @param {Context} ctx - body, logger和larkService
* @returns {boolean}
*/
const isNotP2POrAtBot = (ctx: Context) => {
const { larkBody, appInfo } = ctx
return !larkBody.isP2P && !larkBody.isAtBot(appInfo.appName)
}
/**
*
* @param {Context} ctx - body, logger和larkService
@ -14,18 +24,12 @@ const filterIllegalMsg = async ({
logger,
larkService,
larkBody,
appInfo,
}: Context): Promise<boolean> => {
const { chatId, msgType, msgText } = larkBody
// 没有chatId的消息不处理
logger.info(`bot req chatId: ${chatId}`)
if (!chatId) return true
// 非私聊和群聊中艾特机器人的消息不处理
if (!larkBody.isP2P && !larkBody.isAtBot(appInfo.appName)) {
return true
}
// 获取msgType
logger.info(`bot req msgType: ${msgType}`)
// 放行纯文本消息
@ -239,6 +243,9 @@ const manageCMDMsg = async (ctx: Context) => {
export const manageEventMsg = async (ctx: Context) => {
// 过滤非法消息
if (await filterIllegalMsg(ctx)) return
// TODO: 海龟汤
// 非群聊和非艾特机器人的消息不处理
if (isNotP2POrAtBot(ctx)) return
// 处理命令消息
await manageCMDMsg(ctx)
}

View File

@ -1,6 +1,23 @@
import type { LarkEvent } from "@egg/lark-msg-tool"
import { NetToolBase } from "@egg/net-tool"
interface Chat2SoupParams {
user_query: string
soup_id: string
history: string
}
interface Chat2SoupResp {
type: "GAME" | "END" | "OTHER"
content: string
}
interface Soup {
title: string
query: string
answer: string
}
class AttachService extends NetToolBase {
protected hostMap: Record<string, string> = {
dev: "https://lark-egg-preview.ai.xiaomi.com",
@ -41,6 +58,23 @@ class AttachService extends NetToolBase {
await this.post(URL, body).catch(() => "")
}
}
/**
*
*/
async startSoup() {
const URL = "http://10.224.124.13:8778/soup"
return this.post<Soup>(URL, {}).catch(() => null)
}
/**
*
* @param {Chat2SoupParams} body -
*/
async chat2Soup(body: Chat2SoupParams) {
const URL = "http://10.224.124.13:8778/host"
return this.post<Chat2SoupResp>(URL, body).catch(() => null)
}
}
export default AttachService