mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-11-22 03:59:15 +00:00
🔖 Update to v1.2.1
fix some bugs
This commit is contained in:
parent
6f11e68171
commit
a3ee603cd2
@ -14,7 +14,7 @@ import pyromod.listen
|
|||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
pgm_version = "1.2.0"
|
pgm_version = "1.2.1"
|
||||||
CMD_LIST = {}
|
CMD_LIST = {}
|
||||||
module_dir = __path__[0]
|
module_dir = __path__[0]
|
||||||
working_dir = getcwd()
|
working_dir = getcwd()
|
||||||
@ -22,7 +22,7 @@ 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()}
|
"startup": set(), "shutdown": set(), "command_pre": set(), "command_post": set(), "process_error": set(), }
|
||||||
all_permissions = []
|
all_permissions = []
|
||||||
|
|
||||||
logs = getLogger(__name__)
|
logs = getLogger(__name__)
|
||||||
|
@ -51,6 +51,18 @@ class Hook:
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_error():
|
||||||
|
"""
|
||||||
|
注册一个错误处理钩子
|
||||||
|
"""
|
||||||
|
|
||||||
|
def decorator(function):
|
||||||
|
hook_functions["process_error"].add(function)
|
||||||
|
return function
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def startup():
|
async def startup():
|
||||||
if cors := [startup() for startup in hook_functions["startup"]]:
|
if cors := [startup() for startup in hook_functions["startup"]]:
|
||||||
@ -86,3 +98,13 @@ class Hook:
|
|||||||
raise StopPropagation from e
|
raise StopPropagation from e
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
logs.info(f"[command_post]: {type(exception)}: {exception}")
|
logs.info(f"[command_post]: {type(exception)}: {exception}")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def process_error_exec(message: Message, exc_info: BaseException, exc_format: str):
|
||||||
|
if cors := [error(message, exc_info, exc_format) for error in hook_functions["process_error"]]: # noqa
|
||||||
|
try:
|
||||||
|
await asyncio.gather(*cors)
|
||||||
|
except StopPropagation as e:
|
||||||
|
raise StopPropagation from e
|
||||||
|
except Exception as exception:
|
||||||
|
logs.info(f"[process_error]: {type(exception)}: {exception}")
|
||||||
|
@ -190,6 +190,7 @@ def listener(**args):
|
|||||||
await message.edit(lang("run_error"), no_reply=True) # noqa
|
await message.edit(lang("run_error"), no_reply=True) # noqa
|
||||||
if not diagnostics:
|
if not diagnostics:
|
||||||
return
|
return
|
||||||
|
await Hook.process_error_exec(message, exc_info, exc_format)
|
||||||
if Config.ERROR_REPORT:
|
if Config.ERROR_REPORT:
|
||||||
report = f"""# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n# ChatID: {message.chat.id}. \n# UserID: {message.from_user.id if message.from_user else message.sender_chat.id}. \n# Message: \n-----BEGIN TARGET MESSAGE-----\n{message.text or message.caption}\n-----END TARGET MESSAGE-----\n# Traceback: \n-----BEGIN TRACEBACK-----\n{str(exc_format)}\n-----END TRACEBACK-----\n# Error: "{str(exc_info)}". \n"""
|
report = f"""# Generated: {strftime('%H:%M %d/%m/%Y', gmtime())}. \n# ChatID: {message.chat.id}. \n# UserID: {message.from_user.id if message.from_user else message.sender_chat.id}. \n# Message: \n-----BEGIN TARGET MESSAGE-----\n{message.text or message.caption}\n-----END TARGET MESSAGE-----\n# Traceback: \n-----BEGIN TRACEBACK-----\n{str(exc_format)}\n-----END TRACEBACK-----\n# Error: "{str(exc_info)}". \n"""
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ async def userid(message: Message):
|
|||||||
return await message.edit(lang("leave_not_group"))
|
return await message.edit(lang("leave_not_group"))
|
||||||
text += f"protected: `{str(msg_from.has_protected_content)}" + "`\n"
|
text += f"protected: `{str(msg_from.has_protected_content)}" + "`\n"
|
||||||
if reply:
|
if reply:
|
||||||
text += "\n" + lang('id_hint') + "\nMessage ID: `" + str(reply.id) + \
|
text += "\n" + lang('id_hint') + "\nMessage ID: `" + str(reply.id) + "`"
|
||||||
"`\n\n**User**\nid: `" + str(reply.from_user.id) + "`"
|
|
||||||
try:
|
try:
|
||||||
|
text += "\n\n**User**\nid: `" + str(reply.from_user.id) + "`"
|
||||||
if reply.from_user.is_bot:
|
if reply.from_user.is_bot:
|
||||||
text += f"\nis_bot: {lang('id_is_bot_yes')}"
|
text += f"\nis_bot: {lang('id_is_bot_yes')}"
|
||||||
try:
|
try:
|
||||||
@ -51,6 +51,13 @@ async def userid(message: Message):
|
|||||||
text += "\ndc: `" + str(reply.from_user.dc_id) + "`"
|
text += "\ndc: `" + str(reply.from_user.dc_id) + "`"
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
text += "\n\n**Chat**\nid: `" + str(reply.sender_chat.id) + "`"
|
||||||
|
text += "\ntitle: `" + reply.sender_chat.title + "`"
|
||||||
|
if reply.sender_chat.username:
|
||||||
|
text += "\nusername: @" + reply.sender_chat.username
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
if reply.forward_from_chat:
|
if reply.forward_from_chat:
|
||||||
text += "\n\n**Forward From Channel**\n" \
|
text += "\n\n**Forward From Channel**\n" \
|
||||||
"id: `" + str(message.forward_from_chat.id) + \
|
"id: `" + str(message.forward_from_chat.id) + \
|
||||||
|
@ -34,7 +34,7 @@ async def sh(message: Message):
|
|||||||
|
|
||||||
if result:
|
if result:
|
||||||
if len(result) > 4096:
|
if len(result) > 4096:
|
||||||
await attach_log(bot, result, message.chat.id, "output.log", message.id)
|
await attach_log(result, message.chat.id, "output.log", message.id)
|
||||||
return
|
return
|
||||||
|
|
||||||
await message.edit(
|
await message.edit(
|
||||||
@ -90,7 +90,7 @@ async def sh_eval(message: Message):
|
|||||||
final_output = f"**>>>** ```{cmd}``` \n```{evaluation}```"
|
final_output = f"**>>>** ```{cmd}``` \n```{evaluation}```"
|
||||||
if len(final_output) > 4096:
|
if len(final_output) > 4096:
|
||||||
message = await message.edit(f"**>>>** ```{cmd}```")
|
message = await message.edit(f"**>>>** ```{cmd}```")
|
||||||
await attach_log(bot, evaluation, message.chat.id, "output.log", message.id)
|
await attach_log(evaluation, message.chat.id, "output.log", message.id)
|
||||||
else:
|
else:
|
||||||
await message.edit(final_output)
|
await message.edit(final_output)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user