From 487df94f8aab76093b17deca44c6ac80aefac66d Mon Sep 17 00:00:00 2001 From: snowtafir Date: Thu, 26 Dec 2024 19:54:15 +0800 Subject: [PATCH] optimize: task's banWords --- src/models/bilibili/bilibili.main.task.ts | 5 +++-- src/models/weibo/weibo.task.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/models/bilibili/bilibili.main.task.ts b/src/models/bilibili/bilibili.main.task.ts index bb953f6..f03a566 100644 --- a/src/models/bilibili/bilibili.main.task.ts +++ b/src/models/bilibili/bilibili.main.task.ts @@ -261,8 +261,9 @@ export class BiliTask { return 'return'; // 如果动态消息构建失败,则直接返回 } - if (biliConfigData.banWords.length > 0) { - const banWords = new RegExp(biliConfigData.banWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式 + const getBanWords: string[] | null = biliConfigData?.banWords; + if (getBanWords && Array.isArray(getBanWords) && getBanWords.length > 0) { + const banWords = new RegExp(getBanWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式 if (banWords.test(dynamicMsg.msg.join(''))) { return 'return'; // 如果动态消息包含屏蔽关键字,则直接返回 } diff --git a/src/models/weibo/weibo.task.ts b/src/models/weibo/weibo.task.ts index 0c91697..50fe34e 100644 --- a/src/models/weibo/weibo.task.ts +++ b/src/models/weibo/weibo.task.ts @@ -228,8 +228,9 @@ export class WeiboTask { return 'return'; // 如果动态消息构建失败或内部资源获取失败,则直接返回 } - if (weiboConfigData.banWords.length > 0) { - const banWords = new RegExp(weiboConfigData.banWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式 + const getBanWords: string[] | null = weiboConfigData?.banWords; + if (getBanWords && Array.isArray(getBanWords) && getBanWords.length > 0) { + const banWords = new RegExp(getBanWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式 if (banWords.test(dynamicMsg.msg.join(''))) { return 'return'; // 如果动态消息包含屏蔽关键字,则直接返回 }