From c9a970dbd54a852c7951e5fb8432f9e9fddcb265 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 22:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E5=92=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BF=98=E5=88=A0=E7=9A=84debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyword.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/keyword.py b/keyword.py index 5882087..2c930ed 100644 --- a/keyword.py +++ b/keyword.py @@ -82,7 +82,7 @@ def get_capture(search_data, group_name): except: return None -async def del_msg(context, t_lim: int): +async def del_msg(context, t_lim): await asyncio.sleep(t_lim) await context.delete() @@ -269,7 +269,7 @@ async def reply_set(context): return elif params[0] == "list": if params[1] == "show" and len(params) == 2: - user_list = settings_dict["list"] if "list" in settings_dict else None + user_list = settings_dict.get("list", None) if user_list: msg = "List: \n" for p in user_list.split(","): @@ -282,7 +282,7 @@ async def reply_set(context): return elif params[1] == "add" and len(params) == 3: if is_num(params[2]): - tmp = settings_dict["list"] if "list" in settings_dict else None + tmp = settings_dict.get("list", None) if not tmp: settings_dict["list"] = params[2] else: settings_dict["list"] += f",{params[2]}" redis.set(redis_data, save_rules(settings_dict, None)) @@ -295,7 +295,7 @@ async def reply_set(context): return elif params[1] == "del" and len(params) == 3: if is_num(params[2]): - tmp = settings_dict["list"] if "list" in settings_dict else None + tmp = settings_dict.get("list", None) if tmp: user_list = settings_dict["list"].split(",") if params[2] in user_list: @@ -348,11 +348,11 @@ async def auto_reply(context): 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["mode"] if "mode" in g_settings else None - n_mode = n_settings["mode"] if "mode" in n_settings else None + g_mode = g_settings.get("mode", None) + n_mode = n_settings.get("mode", None) mode = "0" - g_list = g_settings["list"] if "list" in g_settings else None - n_list = n_settings["list"] if "list" in n_settings else None + g_list = g_settings.get("list", None) + n_list = g_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 @@ -372,12 +372,8 @@ async def auto_reply(context): catch_pattern = r"\$\{regex_(?P((?!\}).)+)\}" while re.search(catch_pattern, v): search_data = re.search(k, send_text) - print(search_data) group_name = re.search(catch_pattern, v).group("str") - print(group_name) capture_data = get_capture(search_data, group_name) - print(capture_data) if not capture_data: capture_data = "" v = v.replace("${regex_%s}" % group_name, capture_data) - print(v) await send_reply(chat_id, parse_multi(v), context)