From f7c55920dfed200bba78eecc075fbfc22a07e033 Mon Sep 17 00:00:00 2001 From: onewhitethreee <38567612+onewhitethreee@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:32:29 +0100 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=BA=86=E6=95=8F=E6=84=9F?= =?UTF-8?q?=E8=AF=8D=E4=B8=BA=E7=A9=BA=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/wechat/wechat_mp_channel.py | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/channel/wechat/wechat_mp_channel.py b/channel/wechat/wechat_mp_channel.py index e7f8dd8..42e67aa 100644 --- a/channel/wechat/wechat_mp_channel.py +++ b/channel/wechat/wechat_mp_channel.py @@ -5,6 +5,7 @@ from common import const from common.log import logger from channel.channel import Channel from concurrent.futures import ThreadPoolExecutor +sensitive_word = [] robot = werobot.WeRoBot(token=channel_conf(const.WECHAT_MP).get('token')) thread_pool = ThreadPoolExecutor(max_workers=8) @@ -15,22 +16,26 @@ def hello_world(msg): with open('sensitive_words.txt', 'r', encoding='utf-8') as f: #加入检测违规词 sensitive_wordss = [msg.content[i:i+2] for i in range(0, len(msg.content), 2)] found = False - for i in sensitive_wordss: - if i in f.read(): - found = True - break - else: - found = False - if found: - return '你输入的内容包含敏感词汇' - else: - logger.info('[WX_Public] receive public msg: {}, userId: {}'.format(msg.content, msg.source)) - key = msg.content + '|' + msg.source - if cache.get(key): - # request time - cache.get(key)['req_times'] += 1 + #如果文件为空 + if not f.read(): + print('empty file in sensitive_words.txt') #如为空则不限制 return WechatSubsribeAccount().handle(msg) - + else: + for i in sensitive_wordss: + if i in f.read(): + found = True + break + else: + found = False + if found: + return '你输入的内容包含敏感词汇' + else: + logger.info('[WX_Public] receive public msg: {}, userId: {}'.format(msg.content, msg.source)) + key = msg.content + '|' + msg.source + if cache.get(key): + # request time + cache.get(key)['req_times'] += 1 + return WechatSubsribeAccount().handle(msg) class WechatSubsribeAccount(Channel):