🔖 Update to v1.2.14

This commit is contained in:
xtaodada 2022-11-14 22:11:27 +08:00
parent e311b57b8e
commit c1b0ee22d4
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
8 changed files with 42 additions and 20 deletions

View File

@ -1,5 +1,4 @@
import contextlib
import sys
from typing import Callable, Awaitable, Set, Dict
@ -13,7 +12,7 @@ from pagermaid.scheduler import scheduler
import pyromod.listen
from pyrogram import Client
pgm_version = "1.2.13"
pgm_version = "1.2.14"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
@ -21,7 +20,9 @@ working_dir = getcwd()
read_context = {}
help_messages = {}
hook_functions: Dict[str, Set[Callable[[], Awaitable[None]]]] = {
"startup": set(), "shutdown": set(), "command_pre": set(), "command_post": set(), "process_error": set(), }
"startup": set(), "shutdown": set(), "command_pre": set(), "command_post": set(), "process_error": set(),
"load_plugins_finished": set(),
}
all_permissions = []
logs = getLogger(__name__)
@ -40,7 +41,6 @@ root_logger.addHandler(file_handler)
basicConfig(level=DEBUG if Config.DEBUG else INFO)
logs.setLevel(DEBUG if Config.DEBUG else INFO)
# easy check
if not Config.API_ID or not Config.API_HASH:
logs.warning("Api-ID or Api-HASH Not Found!")
Config.API_ID = Config.DEFAULT_API_ID

View File

@ -38,6 +38,7 @@ async def main():
await process_exit(start=True, _client=bot)
logs.info(lang('start'))
await Hook.load_success_exec()
await Hook.startup()
await idle()

View File

@ -51,7 +51,7 @@ class Config:
LOG_ID = int(os.environ.get("PGM_LOG_ID", config["log_chatid"]))
IPV6 = strtobool(os.environ.get("PGM_IPV6", config["ipv6"]))
ALLOW_ANALYTIC = strtobool(os.environ.get("PGM_ALLOW_ANALYTIC", config["allow_analytic"]), True)
SENTRY_API = "https://262b310907314998ba2931fa8b3b3624@o1342815.ingest.sentry.io/6617119"
SENTRY_API = "https://fbff8c554f6a44b989b490864679546e@o1342815.ingest.sentry.io/6617119"
MIXPANEL_API = "c79162511383b0fa1e9c062a2a86c855"
TIME_FORM = os.environ.get("PGM_TIME_FORM", config["time_form"])
DATE_FORM = os.environ.get("PGM_DATE_FORM", config["date_form"])
@ -85,7 +85,6 @@ class Config:
with open(f"data{os.sep}alias.json", encoding="utf-8") as f:
alias_dict = load_json(f)
except Exception as e:
print(f"[Degrade] Reading alias file failed{e}")
alias_dict = {}
except ValueError as e:
print(e)

View File

@ -65,6 +65,18 @@ class Hook:
return decorator
@staticmethod
def load_success():
"""
注册一个插件加载完成钩子
"""
def decorator(function):
hook_functions["load_plugins_finished"].add(function)
return function
return decorator
@staticmethod
async def startup():
if cors := [startup(**inject(None, startup)) for startup in hook_functions["startup"]]: # noqa
@ -143,3 +155,11 @@ class Hook:
raise StopPropagation from e
except Exception as exception:
logs.info(f"[process_error]: {type(exception)}: {exception}")
@staticmethod
async def load_success_exec():
if cors := [load(**inject(None, load)) for load in hook_functions["load_plugins_finished"]]: # noqa
try:
await asyncio.gather(*cors)
except Exception as exception:
logs.info(f"[load_success_exec]: {type(exception)}: {exception}")

View File

@ -108,7 +108,7 @@ async def lang_change(message: Message):
with open('config.yml', 'w', encoding="utf-8") as f:
f.write(file)
await message.edit(f"{lang('lang_change_to')} {to_lang}, {lang('lang_reboot')}")
reload_all()
await reload_all()
else:
await message.edit(f'{lang("lang_current_lang")} {Config.LANGUAGE}\n\n'
f'{lang("lang_all_lang")}{"".join(dir__)}')
@ -146,7 +146,7 @@ async def alias_commands(message: Message):
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
json_dump(Config.alias_dict, f)
await message.edit(lang('alias_success'))
reload_all()
await reload_all()
except KeyError:
await message.edit(lang('alias_no_exist'))
return
@ -160,4 +160,4 @@ async def alias_commands(message: Message):
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
json_dump(Config.alias_dict, f)
await message.edit(lang('alias_success'))
reload_all()
await reload_all()

View File

@ -80,7 +80,7 @@ async def plugin(message: Message):
f"{lang('apt_plugin')} "
f"{path.basename(file_path)[:-3]} {lang('apt_installed')}")
await log(f"{lang('apt_install_success')} {path.basename(file_path)[:-3]}.")
reload_all()
await reload_all()
elif len(message.parameter) >= 2:
process_list = message.parameter
message = await message.edit(lang('apt_processing'))
@ -131,7 +131,7 @@ async def plugin(message: Message):
restart = len(success_list) > 0
await message.edit(text)
if restart:
reload_all()
await reload_all()
else:
await message.edit(lang('arg_error'))
elif message.parameter[0] == "remove":
@ -147,7 +147,7 @@ async def plugin(message: Message):
json.dump(version_json, f)
await message.edit(f"{lang('apt_remove_success')} {message.parameter[1]}")
await log(f"{lang('apt_remove')} {message.parameter[1]}.")
reload_all()
await reload_all()
elif "/" in message.parameter[1]:
await message.edit(lang('arg_error'))
else:
@ -198,7 +198,7 @@ async def plugin(message: Message):
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
f"{lang('apt_enable')}")
await log(f"{lang('apt_enable')} {message.parameter[1]}.")
reload_all()
await reload_all()
else:
await message.edit(lang('apt_not_exist'))
else:
@ -211,7 +211,7 @@ async def plugin(message: Message):
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
f"{lang('apt_disable')}")
await log(f"{lang('apt_disable')} {message.parameter[1]}.")
reload_all()
await reload_all()
else:
await message.edit(lang('apt_not_exist'))
else:
@ -288,7 +288,7 @@ async def plugin(message: Message):
with open(f"{plugin_directory}version.json", "w") as f:
json.dump(version_json, f)
await message.edit(f"<b>{lang('apt_name')}</b>\n\n" + lang("apt_reading_list") + need_update)
reload_all()
await reload_all()
elif message.parameter[0] == "search":
if len(message.parameter) == 1:
await message.edit(lang("apt_search_no_name"))

View File

@ -4,11 +4,12 @@ import pagermaid.config
import pagermaid.modules
from pagermaid import bot, logs, help_messages, all_permissions, hook_functions
from pagermaid.hook import Hook
from pagermaid.listener import listener
from pagermaid.utils import lang, Message
def reload_all():
async def reload_all():
bot.dispatcher.remove_all_handlers()
bot.job.remove_all_jobs()
with contextlib.suppress(RuntimeError):
@ -38,6 +39,7 @@ def reload_all():
except BaseException as exception:
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
pagermaid.modules.plugin_list.remove(plugin_name)
await Hook.load_success_exec()
@listener(is_plugin=False, command="reload",
@ -45,5 +47,5 @@ def reload_all():
description=lang('reload_des'))
async def reload_plugins(message: Message):
""" To reload plugins. """
reload_all()
await reload_all()
await message.edit(lang("reload_ok"))

View File

@ -1,5 +1,5 @@
pyrogram==2.0.59
TgCrypto>=1.2.4
pyrogram==2.0.60
TgCrypto==1.2.5
Pillow>=8.4.0
pytz>=2021.3
PyYAML>=6.0
@ -8,5 +8,5 @@ psutil>=5.8.0
httpx
apscheduler
sqlitedict
casbin>=1.17.2
casbin==1.17.4
sentry-sdk>=1.10.1