mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-11-25 10:44:42 +00:00
🔖 Update to v1.2.14
This commit is contained in:
parent
e311b57b8e
commit
c1b0ee22d4
@ -1,5 +1,4 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import sys
|
|
||||||
|
|
||||||
from typing import Callable, Awaitable, Set, Dict
|
from typing import Callable, Awaitable, Set, Dict
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ from pagermaid.scheduler import scheduler
|
|||||||
import pyromod.listen
|
import pyromod.listen
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
pgm_version = "1.2.13"
|
pgm_version = "1.2.14"
|
||||||
CMD_LIST = {}
|
CMD_LIST = {}
|
||||||
module_dir = __path__[0]
|
module_dir = __path__[0]
|
||||||
working_dir = getcwd()
|
working_dir = getcwd()
|
||||||
@ -21,7 +20,9 @@ working_dir = getcwd()
|
|||||||
read_context = {}
|
read_context = {}
|
||||||
help_messages = {}
|
help_messages = {}
|
||||||
hook_functions: Dict[str, Set[Callable[[], Awaitable[None]]]] = {
|
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 = []
|
all_permissions = []
|
||||||
|
|
||||||
logs = getLogger(__name__)
|
logs = getLogger(__name__)
|
||||||
@ -40,7 +41,6 @@ root_logger.addHandler(file_handler)
|
|||||||
basicConfig(level=DEBUG if Config.DEBUG else INFO)
|
basicConfig(level=DEBUG if Config.DEBUG else INFO)
|
||||||
logs.setLevel(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:
|
if not Config.API_ID or not Config.API_HASH:
|
||||||
logs.warning("Api-ID or Api-HASH Not Found!")
|
logs.warning("Api-ID or Api-HASH Not Found!")
|
||||||
Config.API_ID = Config.DEFAULT_API_ID
|
Config.API_ID = Config.DEFAULT_API_ID
|
||||||
|
@ -38,6 +38,7 @@ async def main():
|
|||||||
|
|
||||||
await process_exit(start=True, _client=bot)
|
await process_exit(start=True, _client=bot)
|
||||||
logs.info(lang('start'))
|
logs.info(lang('start'))
|
||||||
|
await Hook.load_success_exec()
|
||||||
await Hook.startup()
|
await Hook.startup()
|
||||||
|
|
||||||
await idle()
|
await idle()
|
||||||
|
@ -51,7 +51,7 @@ class Config:
|
|||||||
LOG_ID = int(os.environ.get("PGM_LOG_ID", config["log_chatid"]))
|
LOG_ID = int(os.environ.get("PGM_LOG_ID", config["log_chatid"]))
|
||||||
IPV6 = strtobool(os.environ.get("PGM_IPV6", config["ipv6"]))
|
IPV6 = strtobool(os.environ.get("PGM_IPV6", config["ipv6"]))
|
||||||
ALLOW_ANALYTIC = strtobool(os.environ.get("PGM_ALLOW_ANALYTIC", config["allow_analytic"]), True)
|
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"
|
MIXPANEL_API = "c79162511383b0fa1e9c062a2a86c855"
|
||||||
TIME_FORM = os.environ.get("PGM_TIME_FORM", config["time_form"])
|
TIME_FORM = os.environ.get("PGM_TIME_FORM", config["time_form"])
|
||||||
DATE_FORM = os.environ.get("PGM_DATE_FORM", config["date_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:
|
with open(f"data{os.sep}alias.json", encoding="utf-8") as f:
|
||||||
alias_dict = load_json(f)
|
alias_dict = load_json(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[Degrade] Reading alias file failed:{e}")
|
|
||||||
alias_dict = {}
|
alias_dict = {}
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
@ -65,6 +65,18 @@ class Hook:
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load_success():
|
||||||
|
"""
|
||||||
|
注册一个插件加载完成钩子
|
||||||
|
"""
|
||||||
|
|
||||||
|
def decorator(function):
|
||||||
|
hook_functions["load_plugins_finished"].add(function)
|
||||||
|
return function
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def startup():
|
async def startup():
|
||||||
if cors := [startup(**inject(None, startup)) for startup in hook_functions["startup"]]: # noqa
|
if cors := [startup(**inject(None, startup)) for startup in hook_functions["startup"]]: # noqa
|
||||||
@ -143,3 +155,11 @@ class Hook:
|
|||||||
raise StopPropagation from e
|
raise StopPropagation from e
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
logs.info(f"[process_error]: {type(exception)}: {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}")
|
||||||
|
@ -108,7 +108,7 @@ async def lang_change(message: Message):
|
|||||||
with open('config.yml', 'w', encoding="utf-8") as f:
|
with open('config.yml', 'w', encoding="utf-8") as f:
|
||||||
f.write(file)
|
f.write(file)
|
||||||
await message.edit(f"{lang('lang_change_to')} {to_lang}, {lang('lang_reboot')}")
|
await message.edit(f"{lang('lang_change_to')} {to_lang}, {lang('lang_reboot')}")
|
||||||
reload_all()
|
await reload_all()
|
||||||
else:
|
else:
|
||||||
await message.edit(f'{lang("lang_current_lang")} {Config.LANGUAGE}\n\n'
|
await message.edit(f'{lang("lang_current_lang")} {Config.LANGUAGE}\n\n'
|
||||||
f'{lang("lang_all_lang")}{",".join(dir__)}')
|
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:
|
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
|
||||||
json_dump(Config.alias_dict, f)
|
json_dump(Config.alias_dict, f)
|
||||||
await message.edit(lang('alias_success'))
|
await message.edit(lang('alias_success'))
|
||||||
reload_all()
|
await reload_all()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
await message.edit(lang('alias_no_exist'))
|
await message.edit(lang('alias_no_exist'))
|
||||||
return
|
return
|
||||||
@ -160,4 +160,4 @@ async def alias_commands(message: Message):
|
|||||||
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
|
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
|
||||||
json_dump(Config.alias_dict, f)
|
json_dump(Config.alias_dict, f)
|
||||||
await message.edit(lang('alias_success'))
|
await message.edit(lang('alias_success'))
|
||||||
reload_all()
|
await reload_all()
|
||||||
|
@ -80,7 +80,7 @@ async def plugin(message: Message):
|
|||||||
f"{lang('apt_plugin')} "
|
f"{lang('apt_plugin')} "
|
||||||
f"{path.basename(file_path)[:-3]} {lang('apt_installed')}")
|
f"{path.basename(file_path)[:-3]} {lang('apt_installed')}")
|
||||||
await log(f"{lang('apt_install_success')} {path.basename(file_path)[:-3]}.")
|
await log(f"{lang('apt_install_success')} {path.basename(file_path)[:-3]}.")
|
||||||
reload_all()
|
await reload_all()
|
||||||
elif len(message.parameter) >= 2:
|
elif len(message.parameter) >= 2:
|
||||||
process_list = message.parameter
|
process_list = message.parameter
|
||||||
message = await message.edit(lang('apt_processing'))
|
message = await message.edit(lang('apt_processing'))
|
||||||
@ -131,7 +131,7 @@ async def plugin(message: Message):
|
|||||||
restart = len(success_list) > 0
|
restart = len(success_list) > 0
|
||||||
await message.edit(text)
|
await message.edit(text)
|
||||||
if restart:
|
if restart:
|
||||||
reload_all()
|
await reload_all()
|
||||||
else:
|
else:
|
||||||
await message.edit(lang('arg_error'))
|
await message.edit(lang('arg_error'))
|
||||||
elif message.parameter[0] == "remove":
|
elif message.parameter[0] == "remove":
|
||||||
@ -147,7 +147,7 @@ async def plugin(message: Message):
|
|||||||
json.dump(version_json, f)
|
json.dump(version_json, f)
|
||||||
await message.edit(f"{lang('apt_remove_success')} {message.parameter[1]}")
|
await message.edit(f"{lang('apt_remove_success')} {message.parameter[1]}")
|
||||||
await log(f"{lang('apt_remove')} {message.parameter[1]}.")
|
await log(f"{lang('apt_remove')} {message.parameter[1]}.")
|
||||||
reload_all()
|
await reload_all()
|
||||||
elif "/" in message.parameter[1]:
|
elif "/" in message.parameter[1]:
|
||||||
await message.edit(lang('arg_error'))
|
await message.edit(lang('arg_error'))
|
||||||
else:
|
else:
|
||||||
@ -198,7 +198,7 @@ async def plugin(message: Message):
|
|||||||
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
|
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
|
||||||
f"{lang('apt_enable')}")
|
f"{lang('apt_enable')}")
|
||||||
await log(f"{lang('apt_enable')} {message.parameter[1]}.")
|
await log(f"{lang('apt_enable')} {message.parameter[1]}.")
|
||||||
reload_all()
|
await reload_all()
|
||||||
else:
|
else:
|
||||||
await message.edit(lang('apt_not_exist'))
|
await message.edit(lang('apt_not_exist'))
|
||||||
else:
|
else:
|
||||||
@ -211,7 +211,7 @@ async def plugin(message: Message):
|
|||||||
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
|
await message.edit(f"{lang('apt_plugin')} {message.parameter[1]} "
|
||||||
f"{lang('apt_disable')}")
|
f"{lang('apt_disable')}")
|
||||||
await log(f"{lang('apt_disable')} {message.parameter[1]}.")
|
await log(f"{lang('apt_disable')} {message.parameter[1]}.")
|
||||||
reload_all()
|
await reload_all()
|
||||||
else:
|
else:
|
||||||
await message.edit(lang('apt_not_exist'))
|
await message.edit(lang('apt_not_exist'))
|
||||||
else:
|
else:
|
||||||
@ -288,7 +288,7 @@ async def plugin(message: Message):
|
|||||||
with open(f"{plugin_directory}version.json", "w") as f:
|
with open(f"{plugin_directory}version.json", "w") as f:
|
||||||
json.dump(version_json, f)
|
json.dump(version_json, f)
|
||||||
await message.edit(f"<b>{lang('apt_name')}</b>\n\n" + lang("apt_reading_list") + need_update)
|
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":
|
elif message.parameter[0] == "search":
|
||||||
if len(message.parameter) == 1:
|
if len(message.parameter) == 1:
|
||||||
await message.edit(lang("apt_search_no_name"))
|
await message.edit(lang("apt_search_no_name"))
|
||||||
|
@ -4,11 +4,12 @@ import pagermaid.config
|
|||||||
import pagermaid.modules
|
import pagermaid.modules
|
||||||
|
|
||||||
from pagermaid import bot, logs, help_messages, all_permissions, hook_functions
|
from pagermaid import bot, logs, help_messages, all_permissions, hook_functions
|
||||||
|
from pagermaid.hook import Hook
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, Message
|
from pagermaid.utils import lang, Message
|
||||||
|
|
||||||
|
|
||||||
def reload_all():
|
async def reload_all():
|
||||||
bot.dispatcher.remove_all_handlers()
|
bot.dispatcher.remove_all_handlers()
|
||||||
bot.job.remove_all_jobs()
|
bot.job.remove_all_jobs()
|
||||||
with contextlib.suppress(RuntimeError):
|
with contextlib.suppress(RuntimeError):
|
||||||
@ -38,6 +39,7 @@ def reload_all():
|
|||||||
except BaseException as exception:
|
except BaseException as exception:
|
||||||
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
|
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
|
||||||
pagermaid.modules.plugin_list.remove(plugin_name)
|
pagermaid.modules.plugin_list.remove(plugin_name)
|
||||||
|
await Hook.load_success_exec()
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=False, command="reload",
|
@listener(is_plugin=False, command="reload",
|
||||||
@ -45,5 +47,5 @@ def reload_all():
|
|||||||
description=lang('reload_des'))
|
description=lang('reload_des'))
|
||||||
async def reload_plugins(message: Message):
|
async def reload_plugins(message: Message):
|
||||||
""" To reload plugins. """
|
""" To reload plugins. """
|
||||||
reload_all()
|
await reload_all()
|
||||||
await message.edit(lang("reload_ok"))
|
await message.edit(lang("reload_ok"))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
pyrogram==2.0.59
|
pyrogram==2.0.60
|
||||||
TgCrypto>=1.2.4
|
TgCrypto==1.2.5
|
||||||
Pillow>=8.4.0
|
Pillow>=8.4.0
|
||||||
pytz>=2021.3
|
pytz>=2021.3
|
||||||
PyYAML>=6.0
|
PyYAML>=6.0
|
||||||
@ -8,5 +8,5 @@ psutil>=5.8.0
|
|||||||
httpx
|
httpx
|
||||||
apscheduler
|
apscheduler
|
||||||
sqlitedict
|
sqlitedict
|
||||||
casbin>=1.17.2
|
casbin==1.17.4
|
||||||
sentry-sdk>=1.10.1
|
sentry-sdk>=1.10.1
|
||||||
|
Loading…
Reference in New Issue
Block a user