This commit is contained in:
dj
2023-12-01 18:17:58 +03:00
parent e0fe8e392f
commit 2208bbf566
18 changed files with 353 additions and 190 deletions
+39 -17
View File
@@ -1,20 +1,25 @@
# - *- coding: utf- 8 - *-
import os
import aiofiles
from aiogram import Router, Bot, F
from aiogram.filters import Command
from aiogram.types import FSInputFile, Message, CallbackQuery
from aiogram.utils.media_group import MediaGroupBuilder
from tgbot.data.config import PATH_DATABASE, PATH_LOGS
from tgbot.database.db_users import UserModel
from tgbot.keyboards.inline_misc import admin_inl
from tgbot.keyboards.reply_misc import admin_rep
from tgbot.utils.const_functions import get_date
from tgbot.utils.misc.bot_models import FSM, RS
from tgbot.utils.misc.bot_models import FSM, ARS
router = Router(name=__name__)
# Кнопка - Admin Inline
@router.message(F.text == 'Admin Inline')
async def admin_button_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_button_inline(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer("Click Button - Admin Inline", reply_markup=admin_inl)
@@ -22,7 +27,7 @@ async def admin_button_inline(message: Message, bot: Bot, state: FSM, rSession:
# Кнопка - Admin Reply
@router.message(F.text == 'Admin Reply')
async def admin_button_reply(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_button_reply(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer("Click Button - Admin Reply", reply_markup=admin_rep)
@@ -30,13 +35,13 @@ async def admin_button_reply(message: Message, bot: Bot, state: FSM, rSession: R
# Колбэк - Admin X
@router.callback_query(F.data == 'admin_inline_x')
async def admin_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await call.answer(f"Click Admin X")
# Колбэк - Admin
@router.callback_query(F.data.startswith('admin_inline:'))
async def admin_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
get_data = call.data.split(":")[1]
await call.answer(f"Click Admin - {get_data}", True)
@@ -44,34 +49,51 @@ async def admin_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, rSess
# Получение Базы Данных
@router.message(Command(commands=['db', 'database']))
async def admin_database(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_database(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer_document(
FSInputFile(PATH_DATABASE),
caption=f"<b>📦 BACKUP</b>\n"
f"🕰 <code>{get_date()}</code>",
caption=f"<b>📦 #BACKUP | <code>{get_date(full=False)}</code></b>",
)
# Получение логов
@router.message(Command(commands=['log', 'logs']))
async def admin_log(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_log(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer_document(
FSInputFile(PATH_LOGS),
caption=f"<b>🖨 LOGS</b>\n"
f"🕰 <code>{get_date()}</code>",
media_group = MediaGroupBuilder(
caption=f"<b>🖨 #LOGS | <code>{get_date(full=False)}</code></b>",
)
if os.path.isfile(PATH_LOGS):
media_group.add_document(media=FSInputFile(PATH_LOGS))
if os.path.isfile("tgbot/data/sv_log_err.log"):
media_group.add_document(media=FSInputFile("tgbot/data/sv_log_err.log"))
if os.path.isfile("tgbot/data/sv_log_out.log"):
media_group.add_document(media=FSInputFile("tgbot/data/sv_log_out.log"))
await message.answer_media_group(media=media_group.build())
# Очистить логи
@router.message(Command(commands=['clear_log', 'clear_logs', 'log_clear', 'logs_clear']))
async def admin_logs_clear(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def admin_logs_clear(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
with open(PATH_LOGS, "w") as file:
file.write(f"{get_date()} | LOGS WAS CLEAR")
if os.path.isfile(PATH_LOGS):
async with aiofiles.open(PATH_LOGS, "w") as file:
await file.write(f"{get_date()} | LOGS WAS CLEAR")
await message.answer("<b>🖨 Логи были успешно очищены</b>")
if os.path.isfile("tgbot/data/sv_log_err.log"):
async with aiofiles.open("tgbot/data/sv_log_err.log", "w") as file:
await file.write(f"{get_date()} | LOGS WAS CLEAR")
if os.path.isfile("tgbot/data/sv_log_out.log"):
async with aiofiles.open("tgbot/data/sv_log_out.log", "w") as file:
await file.write(f"{get_date()} | LOGS WAS CLEAR")
await message.answer("<b>🖨 The logs have been cleared</b>")