diff --git a/lib/check.js b/lib/check.js index fd7fce5..cc227ed 100644 --- a/lib/check.js +++ b/lib/check.js @@ -1,4 +1,4 @@ -const { log, delay, infiniteNumber } = require('./utils') +const { log, delay, infiniteNumber, judge } = require('./utils') const { sendNotify } = require('./helper/notify') const config = require('./data/config') const global_var = require('./data/global_var') @@ -37,7 +37,7 @@ async function isMe() { if (unread_count) { bili_client.updateSessionStatus(talker_id, type, msg_seqno); await delay(1000); - if (config.notice_key_words.some(it => new RegExp(it).test(content))) { + if (judge(content, config.notice_key_words)) { desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()} \n\n` desp += `用户: ${sender_uid} \n\n` desp += `私信你(${global_var.get("myUID")})说: ${content} \n\n` diff --git a/lib/utils.js b/lib/utils.js index 7a4ede6..40b9e87 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -130,6 +130,20 @@ const utils = { } return array; }, + /** + * 关键词判断 + * @param {string} text + * @param {string[]} key_words startwith '~' 表示黑名单 + * @return {boolean} + */ + judge(text, key_words) { + return key_words.reduce((acc, word) => { + word.startsWith('~') + ? RegExp(word.slice(1)).test(text) && (acc = false) + : RegExp(word).test(text) && (acc = true) + return acc + }, false) + }, /** * 是否有指定环境变量 * @param {string} env_name diff --git a/main.js b/main.js index 7e886e3..73b51e6 100644 --- a/main.js +++ b/main.js @@ -10,7 +10,7 @@ const metainfo = [ ` __/ | | | `, ` |___/ |_| `, ` `, - ` Verison: v2.0.3`, + ` Verison: v2.0.4`, ` Written by shanmite`, ] /**多账号存储 */ diff --git a/my_config.example.js b/my_config.example.js index be4a380..3d629d0 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -178,11 +178,13 @@ module.exports = { is_exception: false, /** - * 中奖通知关键词(满足一个就推送) - * 符合js正则表达式的字符串 + * - 中奖通知关键词(满足一个就推送) + * - 符合js正则表达式的字符串 + * - 若以 ~ 开头则表示为黑名单规则 */ notice_key_words: [ - "中奖", "获得", "填写", "写上", "提供", "收货地址", "支付宝账号", "码", "大会员" + "中奖|获得|填写|写上|提供|收货地址|支付宝账号|码|大会员", + "~预约抽奖通知" ], /**