From 772b58b2b6969fb8e5ebb736f7e2967a29930a9c Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 2 Aug 2022 12:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Update=20to=20v1.2.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ languages/built-in/en.yml | 4 ++++ languages/built-in/ja.yml | 4 ++++ languages/built-in/zh-cn.yml | 4 ++++ languages/built-in/zh-tw.yml | 4 ++++ pagermaid/__init__.py | 8 ++++++-- pagermaid/modules/plugin.py | 17 +++++++++++------ pagermaid/modules/sentry.py | 4 ++-- pagermaid/modules/system.py | 21 +++++++++++++++++++-- 9 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index a0a5887..8efc557 100644 --- a/.gitignore +++ b/.gitignore @@ -128,6 +128,8 @@ keyword.list requirements2.txt languages/custom.yml unknown_errors.txt +pagermaid*.txt +exception*.txt output.log # Spyder project settings diff --git a/languages/built-in/en.yml b/languages/built-in/en.yml index dc6af9b..b514a1c 100644 --- a/languages/built-in/en.yml +++ b/languages/built-in/en.yml @@ -494,6 +494,10 @@ eval_parameters: eval_channel: Something went wrong ~ The current PagerMaid-Pyro configuration prohibits the execution of Python commands in the channel. eval_success: execute Python commands remotely eval_need_dev: '**Please note: This command can directly operate your account** This command is only for developers. If you know what you are doing, please manually configure the `dev` item in the Redis database to any value or create the `dev` file in the `data` folder.' +## send_log +send_log_des: Send the log file to the specified user. +send_log_not_found: The log file does not exist. +send_log_caption: Log file of PagerMaid-Pyro. ## restart restart_des: Restart PagerMaid-Pyro restart_processing: Try to restart PagerMaid-Pyro. diff --git a/languages/built-in/ja.yml b/languages/built-in/ja.yml index be9f5d7..bf11cb0 100644 --- a/languages/built-in/ja.yml +++ b/languages/built-in/ja.yml @@ -494,6 +494,10 @@ eval_parameters: eval_channel: Something went wrong ~ The current Maid-Pyro configuration prohibits the execution of Python commands in the channel. eval_success: execute Python commands remotey eval_need_dev: '**Please note: This command can directly operate your account** This command is only for developers. If you know what you are doing, and please manually configure the `dev` item in the Redis database to any value or create the `dev` file in the `data` folder。' +## send_log +send_log_des: 指定したユーザーにログ ファイルを送信します。 +send_log_not_found: ログファイルが存在しません。 +send_log_caption: PagerMaid-Pyroのログファイル。 ## restart restart_des: Restart PagerMaid-Pyro restart_processing: to restart PagerMaid-Pyro. diff --git a/languages/built-in/zh-cn.yml b/languages/built-in/zh-cn.yml index 325ed3d..c157de0 100644 --- a/languages/built-in/zh-cn.yml +++ b/languages/built-in/zh-cn.yml @@ -494,6 +494,10 @@ eval_parameters: <命令> eval_channel: 出错了呜呜呜 ~ 当前 PagerMaid-Pyro 的配置禁止在频道中执行 Python 命令。 eval_success: 远程执行 Python 命令 eval_need_dev: '**请注意:此命令可以直接操作您的账户** 此命令仅适用于开发者,如果您知道您在做什么的话,请手动在 Redis 数据库配置 dev 项为任意值或者在 data 文件夹下创建 dev 文件。' +## send_log +send_log_des: 将日志文件发送给指定用户 +send_log_not_found: 日志文件不存在。 +send_log_caption: PagerMaid-Pyro 日志文件 ## restart restart_des: 使 PagerMaid-Pyro 重新启动 restart_processing: 尝试重启 PagerMaid-Pyro... diff --git a/languages/built-in/zh-tw.yml b/languages/built-in/zh-tw.yml index 38b4b6e..1900741 100644 --- a/languages/built-in/zh-tw.yml +++ b/languages/built-in/zh-tw.yml @@ -494,6 +494,10 @@ eval_parameters: <指令> eval_channel: Error!不能在頻道執行指令。 eval_success: 執行 Python 指令 eval_need_dev: '**請注意:此命令可以直接操作您的賬戶** 此命令僅適用於開發者,如果您知道您在做什麼的話,請手動在 Redis 數據庫配置 dev 項為任意值或者在 data 文件夾下創建 dev 文件。' +## send_log +send_log_des: 將日誌文件發送到指定的用戶 +send_log_not_found: 日誌文件不存在 +send_log_caption: PagerMaid-Pyro 日誌文件 ## restart restart_des: 重新啟動 restart_processing: 正在嘗試重新啟動 diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index 6236219..47add77 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -1,9 +1,10 @@ import contextlib + from typing import Callable, Awaitable, Set, Dict from coloredlogs import ColoredFormatter from datetime import datetime, timezone -from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG +from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG, Formatter, FileHandler from os import getcwd from pyrogram.errors import PeerIdInvalid @@ -14,7 +15,7 @@ import pyromod.listen from pyrogram import Client import sys -pgm_version = "1.2.4" +pgm_version = "1.2.5" CMD_LIST = {} module_dir = __path__[0] working_dir = getcwd() @@ -35,6 +36,9 @@ root_logger.addHandler(logging_handler) pyro_logger = getLogger("pyrogram") pyro_logger.setLevel(CRITICAL) pyro_logger.addHandler(logging_handler) +file_handler = FileHandler(filename="pagermaid.log.txt", mode="w", encoding="utf-8") +file_handler.setFormatter(Formatter(logging_format)) +root_logger.addHandler(file_handler) basicConfig(level=DEBUG if Config.DEBUG else INFO) logs.setLevel(DEBUG if Config.DEBUG else INFO) diff --git a/pagermaid/modules/plugin.py b/pagermaid/modules/plugin.py index 793ee4a..ac7bb39 100644 --- a/pagermaid/modules/plugin.py +++ b/pagermaid/modules/plugin.py @@ -35,6 +35,7 @@ def move_plugin(file_path): async def download(name): html = await client.get(f'{Config.GIT_SOURCE}{name}/main.py') + assert html.status_code == 200 with open(f'plugins{sep}{name}.py', mode='wb') as f: f.write(html.text.encode('utf-8')) return f'plugins{sep}{name}.py' @@ -107,15 +108,16 @@ async def plugin(message: Message): if x["name"] == i: if (float(x["version"]) - float(plugin_version)) <= 0: no_need_list.append(i) - temp = False - break else: remove_plugin(i) - await download(i) + try: + await download(i) + except AssertionError: + break update_version(i, x["version"]) success_list.append(i) - temp = False - break + temp = False + break if temp: failed_list.append(i) text = f"{lang('apt_name')}\n\n" @@ -274,7 +276,10 @@ async def plugin(message: Message): plugin_directory = f"{working_dir}{sep}plugins{sep}" for i in need_update_list: remove_plugin(i) - await download(i) + try: + await download(i) + except AssertionError: + continue with open(f"{plugin_directory}version.json", "r", encoding="utf-8") as f: version_json = json.load(f) for m in plugin_online: diff --git a/pagermaid/modules/sentry.py b/pagermaid/modules/sentry.py index dc82549..0ff4580 100644 --- a/pagermaid/modules/sentry.py +++ b/pagermaid/modules/sentry.py @@ -3,7 +3,7 @@ import sentry_sdk from subprocess import run, PIPE from time import time -from pyrogram.errors import Unauthorized +from pyrogram.errors import Unauthorized, UsernameInvalid from pagermaid import Config from pagermaid.enums import Client, Message @@ -14,7 +14,7 @@ from pagermaid.single_utils import safe_remove def sentry_before_send(event, hint): global sentry_sdk_report_time exc_info = hint.get("exc_info") - if exc_info and isinstance(exc_info[1], Unauthorized): + if exc_info and isinstance(exc_info[1], (Unauthorized, UsernameInvalid)): # The user has been deleted/deactivated or session revoked safe_remove('pagermaid.session') exit(1) diff --git a/pagermaid/modules/system.py b/pagermaid/modules/system.py index 7229523..0cb3c44 100644 --- a/pagermaid/modules/system.py +++ b/pagermaid/modules/system.py @@ -2,13 +2,15 @@ import io import sys import traceback +from os.path import exists, sep from sys import exit from platform import node from getpass import getuser -from pagermaid import bot from pagermaid.listener import listener -from pagermaid.utils import attach_log, execute, Message, lang +from pagermaid.enums import Message +from pagermaid.services import bot +from pagermaid.utils import attach_log, execute, lang, upload_attachment @listener(is_plugin=False, command="sh", @@ -95,6 +97,21 @@ async def sh_eval(message: Message): await message.edit(final_output) +@listener(is_plugin=False, command="send_log", + need_admin=True, + description=lang("send_log_des")) +async def send_log(message: Message): + """ Send log to a chat. """ + if not exists("pagermaid.log.txt"): + return await message.edit(lang("send_log_not_found")) + await upload_attachment("pagermaid.log.txt", + message.chat.id, + message.reply_to_message_id, + thumb=f"pagermaid{sep}assets{sep}logo.jpg", + caption=lang("send_log_caption")) + await message.safe_delete() + + async def aexec(code, event, client): exec( (