From a4ecd0019985f29c2cffff588e4435e03783816d Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Sun, 7 Feb 2021 12:37:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AA=E6=89=BE=E5=88=B0?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=8F=90=E7=A4=BA=20(#119)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加未找到函数提示 --- keyword.py | 39 ++++++++++++++++++++++----------------- list.json | 4 ++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/keyword.py b/keyword.py index 4da5ef2..d8d531f 100644 --- a/keyword.py +++ b/keyword.py @@ -522,7 +522,7 @@ async def funcset(context): for p in os.listdir("plugins/keyword_func"): if path.isfile(f"plugins/keyword_func/{p}"): try: - send_msg += f"{count}: `{p[:len(p) - 3]}`\n" + send_msg += f"{count}: `{p[:-3]}`\n" count += 1 except: pass @@ -542,7 +542,7 @@ async def funcset(context): file_path = f"plugins/keyword_func/{cmd[1]}.py" if path.exists(file_path) and path.isfile(file_path): remove(file_path) - await context.edit("删除成功,正在重启 PagerMaid") + await context.edit("删除成功,PagerMaid-Modify 正在重新启动。") await bot.disconnect() else: await context.edit("函数不存在") @@ -570,26 +570,31 @@ async def funcset(context): await del_msg(context, 5) return elif len(cmd) == 2 and cmd[0] == "install": - fun_name = cmd[1] - fun_online = \ + func_name = cmd[1] + func_online = \ json.loads( - requests.get("https://raw.githubusercontent.com/xtaodada/PagerMaid_Plugins/master/keyword_func/list.json").content)[ - 'list'] - if fun_name in fun_online: - fun_directory = f"{working_dir}/plugins/keyword_func/" - file_path = fun_name + ".py" - fun_content = requests.get( - f"https://raw.githubusercontent.com/xtaodada/PagerMaid_Plugins/master/keyword_func/{fun_name}.py").content + requests.get("https://raw.githubusercontent.com/xtaodada/PagerMaid_Plugins/master" + "/keyword_func/list.json").content)['list'] + if func_name in func_online: + func_directory = f"{working_dir}/plugins/keyword_func/" + file_path = func_name + ".py" + func_content = requests.get( + f"https://raw.githubusercontent.com/xtaodada/PagerMaid_Plugins/master" + f"/keyword_func/{func_name}.py").content with open(file_path, 'wb') as f: - f.write(fun_content) - if path.exists(f"{fun_directory}{file_path}"): - remove(f"{fun_directory}{file_path}") - move(file_path, fun_directory) + f.write(func_content) + if path.exists(f"{func_directory}{file_path}"): + remove(f"{func_directory}{file_path}") + move(file_path, func_directory) else: - move(file_path, fun_directory) + move(file_path, func_directory) await context.edit(f"函数 {path.basename(file_path)[:-3]} 已添加,PagerMaid-Modify 正在重新启动。") await log(f"成功安装函数 {path.basename(file_path)[:-3]}.") - await context.client.disconnect() + await bot.disconnect() + else: + await context.edit(f"{func_name} 函数不存在") + await del_msg(context, 5) + return elif len(cmd) == 1 and cmd[0] == "help": await context.edit(""" `-funcset new ` (要回复带有文件的信息或自己附带文件) diff --git a/list.json b/list.json index 0542408..318f089 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "keyword", - "version": "2.3", + "version": "2.31", "section": "chat", "maintainer": "c3b2a, xtaodada", - "size": "26.5 kb", + "size": "26.7 kb", "supported": true, "des-short": "群组关键词自动回复插件", "des": "命令: keyword, replyset, funcset。"