PaiGram/plugins/system/log.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
1.2 KiB
Python
Raw Normal View History

2022-09-18 08:11:09 +00:00
import os
from telegram import Update
from telegram.ext import CommandHandler, CallbackContext
from core.plugin import Plugin, handler
from utils.decorators.admins import bot_admins_rights_check
2022-09-18 08:16:33 +00:00
from utils.log import logger
2022-09-18 08:11:09 +00:00
current_dir = os.getcwd()
error_log = os.path.join(current_dir, "logs", "error", "error.log")
debug_log = os.path.join(current_dir, "logs", "debug", "debug.log")
class Log(Plugin):
@handler(CommandHandler, command="send_log", block=False)
@bot_admins_rights_check
async def send_log(self, update: Update, _: CallbackContext):
2022-09-18 08:16:33 +00:00
user = update.effective_user
logger.info(f"用户 {user.full_name}[{user.id}] send_log 命令请求")
2022-09-18 08:11:09 +00:00
message = update.effective_message
2022-10-06 16:41:38 +00:00
if os.path.exists(error_log) and os.path.getsize(error_log) > 0:
2022-09-18 08:11:09 +00:00
await message.reply_document(open(error_log, mode="rb+"), caption="Error Log")
else:
await message.reply_text("错误日记未找到")
2022-10-06 16:41:38 +00:00
if os.path.exists(debug_log) and os.path.getsize(debug_log) > 0:
2022-09-18 08:11:09 +00:00
await message.reply_document(open(debug_log, mode="rb+"), caption="Debug Log")
else:
await message.reply_text("调试日记未找到")