feat: 支持屏蔽艾特全员消息
All checks were successful
Egg CI/CD / build-image (push) Successful in 6m41s
Egg CI/CD / deploy (push) Successful in 20s

This commit is contained in:
zhaoyingbo 2024-03-15 08:25:56 +00:00
parent 6d0f5cd822
commit 6fd24a6365

View File

@ -9,7 +9,9 @@ import { sendMsg } from "../../utils/sendMsg";
export const getMsgText = (body: LarkMessageEvent) => {
// TODO: 如果之后想支持单独提醒,这里需要做模板解析
try {
const { text } = JSON.parse(body?.event?.message?.content);
const { text }: { text: string } = JSON.parse(
body?.event?.message?.content
);
// 去掉@_user_1相关的内容例如 '@_user_1 测试' -> '测试'
const textWithoutAt = text.replace(/@_user_\d+/g, "");
// 去除空格和换行
@ -28,12 +30,15 @@ export const getMsgText = (body: LarkMessageEvent) => {
const filterIllegalMsg = (body: LarkMessageEvent) => {
const chatId = getChatId(body);
if (!chatId) return true;
// 获取msgType
const msgType = getMsgType(body);
// 发表情包就直接发回去
if (msgType === "sticker") {
const content = body?.event?.message?.content;
sendMsg("chat_id", chatId, "sticker", content);
return true;
}
// 剩下的非文字消息暂时不处理
if (msgType !== "text") {
const textList = [
"仅支持普通文本内容[黑脸]",
@ -48,6 +53,10 @@ const filterIllegalMsg = (body: LarkMessageEvent) => {
sendMsg("chat_id", chatId, "text", content);
return true;
}
// 还得过滤下艾特全体成员的消息
if (getMsgText(body).includes("@_all")) {
return true;
}
return false;
};