keyword 日常更新 (#109)

非功能性更新,仅更换了解决重复回复问题的方法
This commit is contained in:
c3b2a 2021-02-03 22:27:12 +08:00 committed by GitHub
parent 7f6124e11b
commit 40d06a0c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -5,8 +5,7 @@ from base64 import b64encode, b64decode
from pagermaid import bot, redis, log, redis_status
from pagermaid.listener import listener
msg_rate = 0.01
last_time = time.time()
read_context = {}
def is_num(x: str):
try:
@ -395,23 +394,25 @@ async def auto_reply(context):
elif g_list or n_list: user_list = g_list if g_list else n_list
send_text = context.text
for k, v in plain_dict.items():
if k in send_text and time.time() - last_time > msg_rate:
if k in send_text and context.id not in read_context:
tmp = get_redis(f"keyword.{chat_id}.single.plain.{encode(k)}")
could_reply = validate(str(sender_id), int(mode), user_list)
if tmp:
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
if could_reply:
last_time = time.time()
read_context[context.id] = None
await send_reply(chat_id, parse_multi(v), context)
elif context.id in read_context:
del read_context[context.id]
for k, v in regex_dict.items():
pattern = re.compile(k)
if pattern.search(send_text) and time.time() - last_time > msg_rate:
if pattern.search(send_text) and context.id not in read_context:
tmp = get_redis(f"keyword.{chat_id}.single.regex.{encode(k)}")
could_reply = validate(str(sender_id), int(mode), user_list)
if tmp:
could_reply = validate(str(sender_id), int(tmp.get("mode", "0")), tmp.get("list", []))
if could_reply:
last_time = time.time()
read_context[context.id] = None
catch_pattern = r"\$\{regex_(?P<str>((?!\}).)+)\}"
count = 0
while re.search(catch_pattern, v) and count < 20:
@ -423,3 +424,5 @@ async def auto_reply(context):
v = v.replace("${regex_%s}" % group_name, capture_data)
count += 1
await send_reply(chat_id, parse_multi(v), context)
elif context.id in read_context:
del read_context[context.id]

View File

@ -362,10 +362,10 @@
},
{
"name": "keyword",
"version": "2.01",
"version": "2.02",
"section": "chat",
"maintainer": "c3b2a",
"size": "17.3 kb",
"size": "17.4 kb",
"supported": true,
"des-short": "群组关键词自动回复插件",
"des": "命令: keyword, replyset。"