From 654c5f50cb4cc324d7dabe77ef02215601d3cd89 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 7 Jun 2022 20:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Update=20to=20v1.0.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagermaid/__init__.py | 2 +- pagermaid/__main__.py | 4 ++- pagermaid/listener.py | 84 ++++++++++++++++++++++--------------------- pagermaid/utils.py | 17 ++++++++- requirements.txt | 2 +- 5 files changed, 64 insertions(+), 45 deletions(-) diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index 0d59613..b71e77b 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -9,7 +9,7 @@ import pyromod.listen from pyrogram import Client import sys -pgm_version = "1.0.5" +pgm_version = "1.0.6" CMD_LIST = {} module_dir = __path__[0] working_dir = getcwd() diff --git a/pagermaid/__main__.py b/pagermaid/__main__.py index 7e0627b..5796fd4 100644 --- a/pagermaid/__main__.py +++ b/pagermaid/__main__.py @@ -6,7 +6,7 @@ from pyrogram import idle from pagermaid import bot, logs, working_dir from pagermaid.modules import module_list, plugin_list -from pagermaid.utils import lang +from pagermaid.utils import lang, process_exit path.insert(1, f"{working_dir}{sep}plugins") @@ -28,6 +28,8 @@ async def main(): logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}") plugin_list.remove(plugin_name) + await process_exit(start=True, _client=bot) + logs.info(lang('start')) await idle() await bot.stop() diff --git a/pagermaid/listener.py b/pagermaid/listener.py index d3a5da0..42d2b72 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -16,7 +16,7 @@ from pyrogram.handlers import MessageHandler, EditedMessageHandler from pagermaid import help_messages, logs, Config, bot, read_context, all_permissions from pagermaid.group_manager import Permission -from pagermaid.utils import lang, attach_report, sudo_filter, alias_command, get_permission_name +from pagermaid.utils import lang, attach_report, sudo_filter, alias_command, get_permission_name, process_exit secret_generator = secrets.SystemRandom() @@ -27,17 +27,17 @@ def noop(*args, **kw): def listener(**args): """ Register an event listener. """ - command = args.get('command') - disallow_alias = args.get('disallow_alias', False) - need_admin = args.get('need_admin', False) - description = args.get('description') - parameters = args.get('parameters') - pattern = sudo_pattern = args.get('pattern') - diagnostics = args.get('diagnostics', True) - ignore_edited = args.get('ignore_edited', False) - is_plugin = args.get('is_plugin', True) - incoming = args.get('incoming', False) - outgoing = args.get('outgoing', True) + command = args.get("command") + disallow_alias = args.get("disallow_alias", False) + need_admin = args.get("need_admin", False) + description = args.get("description") + parameters = args.get("parameters") + pattern = sudo_pattern = args.get("pattern") + diagnostics = args.get("diagnostics", True) + ignore_edited = args.get("ignore_edited", False) + is_plugin = args.get("is_plugin", True) + incoming = args.get("incoming", False) + outgoing = args.get("outgoing", True) groups_only = args.get("groups_only", False) privates_only = args.get("privates_only", False) @@ -46,11 +46,11 @@ def listener(**args): raise ValueError(f"{lang('error_prefix')} {lang('command')} \"{command}\" {lang('has_reg')}") pattern = fr"^,{alias_command(command, disallow_alias)}(?: |$)([\s\S]*)" sudo_pattern = fr"^/{alias_command(command, disallow_alias)}(?: |$)([\s\S]*)" - if pattern is not None and not pattern.startswith('(?i)'): - args['pattern'] = f"(?i){pattern}" + if pattern is not None and not pattern.startswith("(?i)"): + args["pattern"] = f"(?i){pattern}" else: - args['pattern'] = pattern - if sudo_pattern is not None and not sudo_pattern.startswith('(?i)'): + args["pattern"] = pattern + if sudo_pattern is not None and not sudo_pattern.startswith("(?i)"): sudo_pattern = f"(?i){sudo_pattern}" if outgoing and not incoming: base_filters = filters.me & ~filters.via_bot & ~filters.forwarded @@ -64,8 +64,8 @@ def listener(**args): & ~filters.via_bot & ~filters.forwarded ) - if args['pattern']: - base_filters &= filters.regex(args['pattern']) + if args["pattern"]: + base_filters &= filters.regex(args["pattern"]) sudo_filters &= filters.regex(sudo_pattern) if groups_only: base_filters &= filters.group @@ -73,26 +73,26 @@ def listener(**args): if privates_only: base_filters &= filters.private sudo_filters &= filters.private - if 'ignore_edited' in args: - del args['ignore_edited'] - if 'command' in args: - del args['command'] - if 'diagnostics' in args: - del args['diagnostics'] - if 'description' in args: - del args['description'] - if 'parameters' in args: - del args['parameters'] - if 'is_plugin' in args: - del args['is_plugin'] - if 'owners_only' in args: - del args['owners_only'] - if 'admins_only' in args: - del args['admins_only'] - if 'groups_only' in args: - del args['groups_only'] - if 'need_admin' in args: - del args['need_admin'] + if "ignore_edited" in args: + del args["ignore_edited"] + if "command" in args: + del args["command"] + if "diagnostics" in args: + del args["diagnostics"] + if "description" in args: + del args["description"] + if "parameters" in args: + del args["parameters"] + if "is_plugin" in args: + del args["is_plugin"] + if "owners_only" in args: + del args["owners_only"] + if "admins_only" in args: + del args["admins_only"] + if "groups_only" in args: + del args["groups_only"] + if "need_admin" in args: + del args["need_admin"] def decorator(function): @@ -101,8 +101,8 @@ def listener(**args): try: try: - parameter = message.matches[0].group(1).split(' ') - if parameter == ['']: + parameter = message.matches[0].group(1).split(" ") + if parameter == [""]: parameter = [] message.parameter = parameter message.arguments = message.matches[0].group(1) @@ -132,12 +132,13 @@ def listener(**args): except ContinuePropagation: raise ContinuePropagation except SystemExit: + await process_exit(start=False, _client=client, message=message) sys.exit(0) except BaseException: exc_info = sys.exc_info()[1] exc_format = format_exc() try: - await message.edit(lang('run_error'), no_reply=True) # noqa + await message.edit(lang("run_error"), no_reply=True) # noqa except BaseException: pass if not diagnostics: @@ -191,6 +192,7 @@ def raw_listener(filter_s): except ContinuePropagation: raise ContinuePropagation except SystemExit: + await process_exit(start=False, _client=client, message=message) sys.exit(0) except UserNotParticipant: pass diff --git a/pagermaid/utils.py b/pagermaid/utils.py index 14867fc..7719ab0 100644 --- a/pagermaid/utils.py +++ b/pagermaid/utils.py @@ -13,7 +13,7 @@ from pyrogram import filters, enums from pagermaid.config import Config from pagermaid import bot from pagermaid.group_manager import enforce_permission -from pagermaid.single_utils import _status_sudo, get_sudo_list, Message +from pagermaid.single_utils import _status_sudo, get_sudo_list, Message, sqlite def lang(text: str) -> str: @@ -190,6 +190,21 @@ def check_manage_subs(message: Message) -> bool: return from_self(message) or enforce_permission(from_msg_get_sudo_uid(message), "modules.manage_subs") +async def process_exit(start: int, _client, message=None): + data = sqlite.get("exit_msg", {}) + cid, mid = data.get("cid", 0), data.get("mid", 0) + if start and data and cid and mid: + msg = await _client.get_messages(cid, mid) + if msg: + try: + await msg.edit(lang("restart_complete")) + except Exception as e: # noqa + pass + del sqlite["exit_msg"] + if message: + sqlite["exit_msg"] = {"cid": message.chat.id, "mid": message.id} + + """ Init httpx client """ # 使用自定义 UA headers = { diff --git a/requirements.txt b/requirements.txt index 2940909..8d7d219 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyrogram==2.0.26 +pyrogram==2.0.27 TgCrypto>=1.2.3 Pillow>=8.4.0 pytz>=2021.3