🔖 Update to v1.0.6

This commit is contained in:
xtaodada 2022-06-07 20:44:45 +08:00
parent 4a81320369
commit 654c5f50cb
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
5 changed files with 64 additions and 45 deletions

View File

@ -9,7 +9,7 @@ import pyromod.listen
from pyrogram import Client from pyrogram import Client
import sys import sys
pgm_version = "1.0.5" pgm_version = "1.0.6"
CMD_LIST = {} CMD_LIST = {}
module_dir = __path__[0] module_dir = __path__[0]
working_dir = getcwd() working_dir = getcwd()

View File

@ -6,7 +6,7 @@ from pyrogram import idle
from pagermaid import bot, logs, working_dir from pagermaid import bot, logs, working_dir
from pagermaid.modules import module_list, plugin_list 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") 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}") logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
plugin_list.remove(plugin_name) plugin_list.remove(plugin_name)
await process_exit(start=True, _client=bot)
logs.info(lang('start')) logs.info(lang('start'))
await idle() await idle()
await bot.stop() await bot.stop()

View File

@ -16,7 +16,7 @@ from pyrogram.handlers import MessageHandler, EditedMessageHandler
from pagermaid import help_messages, logs, Config, bot, read_context, all_permissions from pagermaid import help_messages, logs, Config, bot, read_context, all_permissions
from pagermaid.group_manager import Permission 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() secret_generator = secrets.SystemRandom()
@ -27,17 +27,17 @@ def noop(*args, **kw):
def listener(**args): def listener(**args):
""" Register an event listener. """ """ Register an event listener. """
command = args.get('command') command = args.get("command")
disallow_alias = args.get('disallow_alias', False) disallow_alias = args.get("disallow_alias", False)
need_admin = args.get('need_admin', False) need_admin = args.get("need_admin", False)
description = args.get('description') description = args.get("description")
parameters = args.get('parameters') parameters = args.get("parameters")
pattern = sudo_pattern = args.get('pattern') pattern = sudo_pattern = args.get("pattern")
diagnostics = args.get('diagnostics', True) diagnostics = args.get("diagnostics", True)
ignore_edited = args.get('ignore_edited', False) ignore_edited = args.get("ignore_edited", False)
is_plugin = args.get('is_plugin', True) is_plugin = args.get("is_plugin", True)
incoming = args.get('incoming', False) incoming = args.get("incoming", False)
outgoing = args.get('outgoing', True) outgoing = args.get("outgoing", True)
groups_only = args.get("groups_only", False) groups_only = args.get("groups_only", False)
privates_only = args.get("privates_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')}") raise ValueError(f"{lang('error_prefix')} {lang('command')} \"{command}\" {lang('has_reg')}")
pattern = fr"^,{alias_command(command, disallow_alias)}(?: |$)([\s\S]*)" pattern = fr"^,{alias_command(command, disallow_alias)}(?: |$)([\s\S]*)"
sudo_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)'): if pattern is not None and not pattern.startswith("(?i)"):
args['pattern'] = f"(?i){pattern}" args["pattern"] = f"(?i){pattern}"
else: else:
args['pattern'] = pattern args["pattern"] = pattern
if sudo_pattern is not None and not sudo_pattern.startswith('(?i)'): if sudo_pattern is not None and not sudo_pattern.startswith("(?i)"):
sudo_pattern = f"(?i){sudo_pattern}" sudo_pattern = f"(?i){sudo_pattern}"
if outgoing and not incoming: if outgoing and not incoming:
base_filters = filters.me & ~filters.via_bot & ~filters.forwarded base_filters = filters.me & ~filters.via_bot & ~filters.forwarded
@ -64,8 +64,8 @@ def listener(**args):
& ~filters.via_bot & ~filters.via_bot
& ~filters.forwarded & ~filters.forwarded
) )
if args['pattern']: if args["pattern"]:
base_filters &= filters.regex(args['pattern']) base_filters &= filters.regex(args["pattern"])
sudo_filters &= filters.regex(sudo_pattern) sudo_filters &= filters.regex(sudo_pattern)
if groups_only: if groups_only:
base_filters &= filters.group base_filters &= filters.group
@ -73,26 +73,26 @@ def listener(**args):
if privates_only: if privates_only:
base_filters &= filters.private base_filters &= filters.private
sudo_filters &= filters.private sudo_filters &= filters.private
if 'ignore_edited' in args: if "ignore_edited" in args:
del args['ignore_edited'] del args["ignore_edited"]
if 'command' in args: if "command" in args:
del args['command'] del args["command"]
if 'diagnostics' in args: if "diagnostics" in args:
del args['diagnostics'] del args["diagnostics"]
if 'description' in args: if "description" in args:
del args['description'] del args["description"]
if 'parameters' in args: if "parameters" in args:
del args['parameters'] del args["parameters"]
if 'is_plugin' in args: if "is_plugin" in args:
del args['is_plugin'] del args["is_plugin"]
if 'owners_only' in args: if "owners_only" in args:
del args['owners_only'] del args["owners_only"]
if 'admins_only' in args: if "admins_only" in args:
del args['admins_only'] del args["admins_only"]
if 'groups_only' in args: if "groups_only" in args:
del args['groups_only'] del args["groups_only"]
if 'need_admin' in args: if "need_admin" in args:
del args['need_admin'] del args["need_admin"]
def decorator(function): def decorator(function):
@ -101,8 +101,8 @@ def listener(**args):
try: try:
try: try:
parameter = message.matches[0].group(1).split(' ') parameter = message.matches[0].group(1).split(" ")
if parameter == ['']: if parameter == [""]:
parameter = [] parameter = []
message.parameter = parameter message.parameter = parameter
message.arguments = message.matches[0].group(1) message.arguments = message.matches[0].group(1)
@ -132,12 +132,13 @@ def listener(**args):
except ContinuePropagation: except ContinuePropagation:
raise ContinuePropagation raise ContinuePropagation
except SystemExit: except SystemExit:
await process_exit(start=False, _client=client, message=message)
sys.exit(0) sys.exit(0)
except BaseException: except BaseException:
exc_info = sys.exc_info()[1] exc_info = sys.exc_info()[1]
exc_format = format_exc() exc_format = format_exc()
try: try:
await message.edit(lang('run_error'), no_reply=True) # noqa await message.edit(lang("run_error"), no_reply=True) # noqa
except BaseException: except BaseException:
pass pass
if not diagnostics: if not diagnostics:
@ -191,6 +192,7 @@ def raw_listener(filter_s):
except ContinuePropagation: except ContinuePropagation:
raise ContinuePropagation raise ContinuePropagation
except SystemExit: except SystemExit:
await process_exit(start=False, _client=client, message=message)
sys.exit(0) sys.exit(0)
except UserNotParticipant: except UserNotParticipant:
pass pass

View File

@ -13,7 +13,7 @@ from pyrogram import filters, enums
from pagermaid.config import Config from pagermaid.config import Config
from pagermaid import bot from pagermaid import bot
from pagermaid.group_manager import enforce_permission 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: 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") 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 """ """ Init httpx client """
# 使用自定义 UA # 使用自定义 UA
headers = { headers = {

View File

@ -1,4 +1,4 @@
pyrogram==2.0.26 pyrogram==2.0.27
TgCrypto>=1.2.3 TgCrypto>=1.2.3
Pillow>=8.4.0 Pillow>=8.4.0
pytz>=2021.3 pytz>=2021.3