feat: 优化游戏消息回复逻辑,统一使用更新或回复消息的方法

This commit is contained in:
zhaoyingbo 2025-01-25 10:54:10 +00:00
parent c5fd3da73c
commit 8dc474df92

View File

@ -15,10 +15,10 @@ const startOrStopGame = async (
) => {
const {
logger,
larkBody: { chatId, messageId },
larkBody: { chatId },
attachService,
larkCard,
larkService,
larkService: { message },
} = ctx
const cardGender = larkCard.child("soupAgent")
if (!chatId) {
@ -34,8 +34,7 @@ const startOrStopGame = async (
if (!value) {
// 没有进行中的游戏
if (!activeGame) {
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genSuccessCard(SoupGameMessage.hasStopped)
)
return
@ -45,15 +44,13 @@ const startOrStopGame = async (
const res = await db.soupGame.close(activeGame.id)
if (!res) {
logger.error(`chatId: ${chatId} failed to close the game`)
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genErrorCard(SoupGameMessage.startFailed)
)
}
// 手动结束
if (which === "manual") {
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genCard("markdownSuccessCard", {
content: `
@ -65,8 +62,7 @@ const startOrStopGame = async (
)
} else {
// 自动结束
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genCard("markdownSuccessCard", {
llmRes: `
@ -83,8 +79,7 @@ const startOrStopGame = async (
// 开始游戏,有进行中的游戏
if (activeGame) {
logger.info(`chatId: ${chatId} has an active game`)
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genSuccessCard(SoupGameMessage.hasStarted)
)
return
@ -94,8 +89,7 @@ const startOrStopGame = async (
const game = await attachService.startSoup()
if (!game) {
logger.error(`chatId: ${chatId} failed to start a new game`)
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genErrorCard(SoupGameMessage.startFailed)
)
return
@ -110,16 +104,14 @@ const startOrStopGame = async (
const res = await db.soupGame.create(newSoupGame)
if (!res) {
logger.error(`chatId: ${chatId} failed to create a new game`)
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genErrorCard(SoupGameMessage.startFailed)
)
return
}
logger.info(`chatId: ${chatId} created a new game`)
// 回复用户模型的消息
await larkService.message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genCard("markdownSuccessCard", {
content: `
@ -158,8 +150,7 @@ const chat2Soup = async (ctx: Context) => {
})
if (!res) {
logger.error(`chatId: ${chatId} failed to get soup result`)
await message.replyCard(
messageId,
await message.updateOrReply(
cardGender.genErrorCard(SoupGameMessage.chatFailed)
)
return