fix: 修正非法消息过滤逻辑漏洞
This commit is contained in:
parent
b0406cef99
commit
c298b3780c
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user