mirror of
https://github.com/zhayujie/bot-on-anything.git
synced 2026-01-30 12:19:47 +08:00
Update wechat_mp_channel.py
This commit is contained in:
@@ -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)
|
||||
@@ -12,12 +13,16 @@ cache = {}
|
||||
|
||||
@robot.text
|
||||
def hello_world(msg):
|
||||
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)
|
||||
with open('sensitive_words.txt', 'r', encoding='utf-8') as f: #加入检测违规词
|
||||
if msg.content in f.read():
|
||||
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):
|
||||
@@ -59,4 +64,4 @@ class WechatSubsribeAccount(Channel):
|
||||
reply_text = super().build_reply_content(query, context)
|
||||
logger.info('[WX_Public] reply content: {}'.format(reply_text))
|
||||
|
||||
cache[key] = {"status": "success", "data": reply_text}
|
||||
cache[key] = {"status": "success", "data": reply_text}
|
||||
|
||||
Reference in New Issue
Block a user