fix: 修正非法消息过滤逻辑漏洞
All checks were successful
Egg CI/CD / build-image (push) Successful in 32s
Egg CI/CD / deploy (push) Successful in 21s

This commit is contained in:
zhaoyingbo 2024-05-30 09:38:49 +00:00
parent b0406cef99
commit c298b3780c

View File

@ -10,41 +10,58 @@ import {
getMsgType,
} from "../../utils/msgTools";
/**
* P2P或者群聊并且艾特了小煎蛋
* @param {LarkMessageEvent} body
* @returns {boolean} P2P或者群聊并且艾特了小煎蛋
*/
const getIsP2pOrGroupAtBot = (body: LarkMessageEvent) => {
const isP2p = getChatType(body) === "p2p";
const isAtBot = getMentions(body)?.some(
(mention) => mention.name === "小煎蛋"
);
return isP2p || isAtBot;
}
/**
*
* @param {LarkMessageEvent} body
* @returns {boolean}
*/
const filterIllegalMsg = (body: LarkMessageEvent) => {
// 没有chatId的消息不处理
const chatId = getChatId(body);
if (!chatId) return true;
// 不响应艾特全体成员的消息
if (getMsgText(body).includes("@_all")) {
return true;
}
// 获取msgType
const msgType = getMsgType(body);
// 放行纯文本消息
if (msgType === "text") {
// 过滤艾特全体成员的消息
if (getMsgText(body).includes("@_all")) {
return true;
}
// 放行
return false;
}
// 发表情包就直接发回去
if (msgType === "sticker") {
const content = body?.event?.message?.content;
lark.sendMsg("chat_id", chatId, "sticker", content);
return true;
}
// 是否是私聊
const isP2p = getChatType(body) === "p2p";
// 是否是群聊且@了小煎蛋
const isAtBot = getMentions(body)?.some(
(mention) => mention.name === "小煎蛋"
);
// 只在私聊或者群聊中艾特小煎蛋时才回复
if (msgType !== "text" && (isP2p || isAtBot)) {
// 非表情包只在私聊或者群聊中艾特小煎蛋时才回复
else if (getIsP2pOrGroupAtBot(body)) {
const content = JSON.stringify({
text: "哇!这是什么东东?我只懂普通文本啦![可爱]",
});
lark.sendMsg("chat_id", chatId, "text", content);
return true;
}
return false;
// 非纯文本,全不放行
return true;
};
/**