From 8ee30d394c2ed85e574d3b189ff6acfd6a7b8cfd Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 2 Feb 2022 21:03:59 +0800 Subject: [PATCH] Initial commit --- pagermaid/modules/plugin.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pagermaid/modules/plugin.py b/pagermaid/modules/plugin.py index 96dd018..36b2db0 100644 --- a/pagermaid/modules/plugin.py +++ b/pagermaid/modules/plugin.py @@ -139,22 +139,24 @@ async def plugin(__: Client, context: Message): if len(context.parameter) == 2: if exists(f"{plugin_directory}{context.parameter[1]}.py"): remove(f"{plugin_directory}{context.parameter[1]}.py") - with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f: - version_json = json.load(f) - version_json[context.parameter[1]] = '0.0' - with open(f"{plugin_directory}version.json", 'w') as f: - json.dump(version_json, f) + if exists(f"{plugin_directory}version.json"): + with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f: + version_json = json.load(f) + version_json[context.parameter[1]] = '0.0' + with open(f"{plugin_directory}version.json", 'w') as f: + json.dump(version_json, f) result = await context.edit( f"{lang('apt_remove_success')} {context.parameter[1]}, {lang('apt_reboot')} ") await log(f"{lang('apt_remove')} {context.parameter[1]}.") exit(1) elif exists(f"{plugin_directory}{context.parameter[1]}.py.disabled"): remove(f"{plugin_directory}{context.parameter[1]}.py.disabled") - with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f: - version_json = json.load(f) - version_json[context.parameter[1]] = '0.0' - with open(f"{plugin_directory}version.json", 'w') as f: - json.dump(version_json, f) + if exists(f"{plugin_directory}version.json"): + with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f: + version_json = json.load(f) + version_json[context.parameter[1]] = '0.0' + with open(f"{plugin_directory}version.json", 'w') as f: + json.dump(version_json, f) await context.edit(f"{lang('apt_removed_plugins')} {context.parameter[1]}.") await log(f"{lang('apt_removed_plugins')} {context.parameter[1]}.") elif "/" in context.parameter[1]: