feat: 简化游戏控制逻辑,移除私聊和艾特机器人的判断
This commit is contained in:
parent
a415832851
commit
0fef9d1cb7
@ -2,7 +2,6 @@ import { SoupGameMessage } from "../../constant/message"
|
|||||||
import db from "../../db"
|
import db from "../../db"
|
||||||
import { SoupGame } from "../../db/soupGame"
|
import { SoupGame } from "../../db/soupGame"
|
||||||
import { Context } from "../../types"
|
import { Context } from "../../types"
|
||||||
import { isP2POrAtBot } from "../../utils/message"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开启或者停止游戏
|
* 开启或者停止游戏
|
||||||
@ -33,16 +32,14 @@ const startOrStopGame = async (
|
|||||||
}
|
}
|
||||||
// 停止游戏
|
// 停止游戏
|
||||||
if (!value) {
|
if (!value) {
|
||||||
// 没有进行中的游戏,是私聊或者at机器人,回复停止游戏
|
// 没有进行中的游戏
|
||||||
if (!activeGame && isP2POrAtBot(ctx)) {
|
if (!activeGame) {
|
||||||
await larkService.message.replyCard(
|
await larkService.message.replyCard(
|
||||||
messageId,
|
messageId,
|
||||||
cardGender.genSuccessCard(SoupGameMessage.hasStopped)
|
cardGender.genSuccessCard(SoupGameMessage.hasStopped)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 没有进行中的游戏,且是正常对话,不响应
|
|
||||||
if (!activeGame) return
|
|
||||||
// 有进行中的游戏,关闭游戏
|
// 有进行中的游戏,关闭游戏
|
||||||
logger.info(`chatId: ${chatId} is closing the game`)
|
logger.info(`chatId: ${chatId} is closing the game`)
|
||||||
const res = await db.soupGame.close(activeGame.id)
|
const res = await db.soupGame.close(activeGame.id)
|
||||||
@ -191,7 +188,7 @@ const soupAgent = async (ctx: Context) => {
|
|||||||
larkBody: { msgText, chatId },
|
larkBody: { msgText, chatId },
|
||||||
} = ctx
|
} = ctx
|
||||||
if (!chatId) return
|
if (!chatId) return
|
||||||
if (msgText === "开始游戏" && isP2POrAtBot(ctx)) {
|
if (msgText === "开始游戏") {
|
||||||
startOrStopGame(ctx, true)
|
startOrStopGame(ctx, true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import groupAgent from "../../controller/groupAgent"
|
|||||||
import createKVTemp from "../../controller/sheet/createKVTemp"
|
import createKVTemp from "../../controller/sheet/createKVTemp"
|
||||||
import soupAgent from "../../controller/soupAgent"
|
import soupAgent from "../../controller/soupAgent"
|
||||||
import { Context } from "../../types"
|
import { Context } from "../../types"
|
||||||
import { isNotP2POrAtBot, isP2POrAtBot } from "../../utils/message"
|
import { isNotP2POrAtBot } from "../../utils/message"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤出非法消息,如果发表情包就直接发回去
|
* 过滤出非法消息,如果发表情包就直接发回去
|
||||||
@ -37,8 +37,8 @@ const filterIllegalMsg = async (ctx: Context): Promise<boolean> => {
|
|||||||
larkService.message.send("chat_id", chatId, "sticker", content)
|
larkService.message.send("chat_id", chatId, "sticker", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 非表情包只在私聊或者群聊中艾特机器人时才回复
|
// 非表情包其他的信息都不处理
|
||||||
else if (isP2POrAtBot(ctx)) {
|
else {
|
||||||
logger.info(`got a illegal message, chatId: ${chatId}`)
|
logger.info(`got a illegal message, chatId: ${chatId}`)
|
||||||
larkService.message.sendText2Chat(
|
larkService.message.sendText2Chat(
|
||||||
chatId,
|
chatId,
|
||||||
@ -233,12 +233,12 @@ const manageCMDMsg = async (ctx: Context) => {
|
|||||||
* @param {Context} ctx - 上下文数据
|
* @param {Context} ctx - 上下文数据
|
||||||
*/
|
*/
|
||||||
export const manageEventMsg = async (ctx: Context) => {
|
export const manageEventMsg = async (ctx: Context) => {
|
||||||
|
// 非群聊和非艾特机器人的消息不处理
|
||||||
|
if (isNotP2POrAtBot(ctx)) return
|
||||||
// 过滤非法消息
|
// 过滤非法消息
|
||||||
if (await filterIllegalMsg(ctx)) return
|
if (await filterIllegalMsg(ctx)) return
|
||||||
// 海龟汤
|
// 海龟汤
|
||||||
if (await soupAgent(ctx)) return
|
if (await soupAgent(ctx)) return
|
||||||
// 非群聊和非艾特机器人的消息不处理
|
|
||||||
if (isNotP2POrAtBot(ctx)) return
|
|
||||||
// 处理命令消息
|
// 处理命令消息
|
||||||
await manageCMDMsg(ctx)
|
await manageCMDMsg(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user