feat: 完成海龟汤Server请求
This commit is contained in:
parent
be1805566b
commit
6b34c6538a
13
controller/soupAgent/index.ts
Normal file
13
controller/soupAgent/index.ts
Normal 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")
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user