🔖 Update to v1.2.1

fix some bugs
This commit is contained in:
xtaodada 2022-07-08 22:26:36 +08:00
parent 6f11e68171
commit a3ee603cd2
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
5 changed files with 36 additions and 6 deletions

View File

@ -14,7 +14,7 @@ import pyromod.listen
from pyrogram import Client
import sys
pgm_version = "1.2.0"
pgm_version = "1.2.1"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
@ -22,7 +22,7 @@ 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()}
"startup": set(), "shutdown": set(), "command_pre": set(), "command_post": set(), "process_error": set(), }
all_permissions = []
logs = getLogger(__name__)

View File

@ -51,6 +51,18 @@ class Hook:
return decorator
@staticmethod
def process_error():
"""
注册一个错误处理钩子
"""
def decorator(function):
hook_functions["process_error"].add(function)
return function
return decorator
@staticmethod
async def startup():
if cors := [startup() for startup in hook_functions["startup"]]:
@ -86,3 +98,13 @@ class Hook:
raise StopPropagation from e
except Exception as 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}")

View File

@ -190,6 +190,7 @@ def listener(**args):
await message.edit(lang("run_error"), no_reply=True) # noqa
if not diagnostics:
return
await Hook.process_error_exec(message, exc_info, exc_format)
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"""

View File

@ -34,9 +34,9 @@ async def userid(message: Message):
return await message.edit(lang("leave_not_group"))
text += f"protected: `{str(msg_from.has_protected_content)}" + "`\n"
if reply:
text += "\n" + lang('id_hint') + "\nMessage ID: `" + str(reply.id) + \
"`\n\n**User**\nid: `" + str(reply.from_user.id) + "`"
text += "\n" + lang('id_hint') + "\nMessage ID: `" + str(reply.id) + "`"
try:
text += "\n\n**User**\nid: `" + str(reply.from_user.id) + "`"
if reply.from_user.is_bot:
text += f"\nis_bot: {lang('id_is_bot_yes')}"
try:
@ -51,6 +51,13 @@ async def userid(message: Message):
text += "\ndc: `" + str(reply.from_user.dc_id) + "`"
except AttributeError:
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:
text += "\n\n**Forward From Channel**\n" \
"id: `" + str(message.forward_from_chat.id) + \

View File

@ -34,7 +34,7 @@ async def sh(message: Message):
if result:
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
await message.edit(
@ -90,7 +90,7 @@ async def sh_eval(message: Message):
final_output = f"**>>>** ```{cmd}``` \n```{evaluation}```"
if len(final_output) > 4096:
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:
await message.edit(final_output)