添加 try 防止不停报错

This commit is contained in:
c3b2a 2021-02-07 13:41:50 +08:00 committed by GitHub
parent a4ecd00199
commit c58f7f00fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -618,58 +618,61 @@ async def auto_reply(context):
return
chat_id = context.chat_id
sender_id = context.sender_id
if context.id not in read_context:
plain_dict = get_redis(f"keyword.{chat_id}.plain")
regex_dict = get_redis(f"keyword.{chat_id}.regex")
g_settings = get_redis("keyword.settings")
n_settings = get_redis(f"keyword.{chat_id}.settings")
g_mode = g_settings.get("mode", None)
n_mode = n_settings.get("mode", None)
mode = "0"
g_list = g_settings.get("list", None)
n_list = n_settings.get("list", None)
user_list = []
if g_mode and n_mode:
mode = n_mode
elif g_mode or n_mode:
mode = g_mode if g_mode else n_mode
if g_list and n_list:
user_list = n_list
elif g_list or n_list:
user_list = g_list if g_list else n_list
send_text = context.text
if not send_text:
send_text = ""
for k, v in plain_dict.items():
if k in send_text:
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:
read_context[context.id] = None
await send_reply(chat_id, parse_multi(v), context)
for k, v in regex_dict.items():
pattern = re.compile(k)
if pattern.search(send_text):
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:
read_context[context.id] = None
catch_pattern = r"\$\{regex_(?P<str>((?!\}).)+)\}"
count = 0
while re.search(catch_pattern, v) and count < 20:
search_data = re.search(k, send_text)
group_name = re.search(catch_pattern, v).group("str")
capture_data = get_capture(search_data, group_name)
if not capture_data:
capture_data = ""
if re.search(catch_pattern, capture_data):
capture_data = ""
v = v.replace("${regex_%s}" % group_name, capture_data)
count += 1
await send_reply(chat_id, parse_multi(v), context)
else:
del read_context[context.id]
try:
if context.id not in read_context:
plain_dict = get_redis(f"keyword.{chat_id}.plain")
regex_dict = get_redis(f"keyword.{chat_id}.regex")
g_settings = get_redis("keyword.settings")
n_settings = get_redis(f"keyword.{chat_id}.settings")
g_mode = g_settings.get("mode", None)
n_mode = n_settings.get("mode", None)
mode = "0"
g_list = g_settings.get("list", None)
n_list = n_settings.get("list", None)
user_list = []
if g_mode and n_mode:
mode = n_mode
elif g_mode or n_mode:
mode = g_mode if g_mode else n_mode
if g_list and n_list:
user_list = n_list
elif g_list or n_list:
user_list = g_list if g_list else n_list
send_text = context.text
if not send_text:
send_text = ""
for k, v in plain_dict.items():
if k in send_text:
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:
read_context[context.id] = None
await send_reply(chat_id, parse_multi(v), context)
for k, v in regex_dict.items():
pattern = re.compile(k)
if pattern.search(send_text):
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:
read_context[context.id] = None
catch_pattern = r"\$\{regex_(?P<str>((?!\}).)+)\}"
count = 0
while re.search(catch_pattern, v) and count < 20:
search_data = re.search(k, send_text)
group_name = re.search(catch_pattern, v).group("str")
capture_data = get_capture(search_data, group_name)
if not capture_data:
capture_data = ""
if re.search(catch_pattern, capture_data):
capture_data = ""
v = v.replace("${regex_%s}" % group_name, capture_data)
count += 1
await send_reply(chat_id, parse_multi(v), context)
else:
del read_context[context.id]
except:
pass