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>")
+5 -6
View File
@@ -1,7 +1,6 @@
# - *- coding: utf- 8 - *-
from aiogram import Router
from aiogram.exceptions import TelegramForbiddenError
from aiogram.filters import ExceptionTypeFilter, ExceptionMessageFilter
from aiogram.filters import ExceptionMessageFilter
from aiogram.handlers import ErrorHandler
from tgbot.utils.misc.bot_logging import bot_logger
@@ -10,10 +9,10 @@ router = Router(name=__name__)
# Ошибка с блокировкой бота пользователем
@router.errors(ExceptionTypeFilter(TelegramForbiddenError))
class MyHandler(ErrorHandler):
async def handle(self):
pass
# @router.errors(ExceptionTypeFilter(TelegramForbiddenError))
# class MyHandler(ErrorHandler):
# async def handle(self):
# pass
# Ошибка с редактированием одинакового сообщения
+6 -5
View File
@@ -2,33 +2,34 @@
from aiogram import Router, Bot, F
from aiogram.types import CallbackQuery, Message
from tgbot.database.db_users import UserModel
from tgbot.utils.const_functions import del_message
from tgbot.utils.misc.bot_models import FSM, RS
from tgbot.utils.misc.bot_models import FSM, ARS
router = Router(name=__name__)
# Колбэк с удалением сообщения
@router.callback_query(F.data == 'close_this')
async def main_callback_close(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def main_callback_close(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await del_message(call.message)
# Колбэк с обработкой кнопки
@router.callback_query(F.data == '...')
async def main_callback_answer(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def main_callback_answer(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await call.answer(cache_time=30)
# Колбэк с обработкой удаления сообщений потерявших стейт
@router.callback_query()
async def main_callback_missed(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def main_callback_missed(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await call.answer(f"❗️ Miss callback: {call.data}", True)
# Обработка всех неизвестных команд
@router.message()
async def main_message_missed(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def main_message_missed(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await message.answer(
"♦️ Unknown command.\n"
"♦️ Enter /start",
+4 -3
View File
@@ -3,9 +3,10 @@ from aiogram import Router, Bot, F
from aiogram.filters import Command
from aiogram.types import Message
from tgbot.database.db_users import UserModel
from tgbot.keyboards.reply_main import menu_frep
from tgbot.utils.const_functions import ded
from tgbot.utils.misc.bot_models import FSM, RS
from tgbot.utils.misc.bot_models import FSM, ARS
router = Router(name=__name__)
@@ -13,12 +14,12 @@ router = Router(name=__name__)
# Открытие главного меню
@router.message(F.text.in_(('🔙 Main menu', '🔙 Return')))
@router.message(Command(commands=['start']))
async def main_start(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def main_start(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer(
ded(f"""
🔸 Hello, {my_user['user_name']}
🔸 Hello, {User.user_name}
🔸 Enter /start or /inline
"""),
reply_markup=menu_frep(message.from_user.id),
+7 -6
View File
@@ -3,17 +3,18 @@ from aiogram import Router, Bot, F
from aiogram.filters import Command
from aiogram.types import Message, CallbackQuery
from tgbot.database.db_users import UserModel
from tgbot.keyboards.inline_main import menu_finl
from tgbot.keyboards.inline_misc import user_inl
from tgbot.keyboards.reply_misc import user_rep
from tgbot.utils.misc.bot_models import FSM, RS
from tgbot.utils.misc.bot_models import FSM, ARS
router = Router(name=__name__)
# Кнопка - User Inline
@router.message(F.text == 'User Inline')
async def user_button_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def user_button_inline(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer(
@@ -24,7 +25,7 @@ async def user_button_inline(message: Message, bot: Bot, state: FSM, rSession: R
# Кнопка - User Reply
@router.message(F.text == 'User Reply')
async def user_button_reply(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def user_button_reply(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer(
@@ -35,7 +36,7 @@ async def user_button_reply(message: Message, bot: Bot, state: FSM, rSession: RS
# Команда - /inline
@router.message(Command(commands="inline"))
async def user_command_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
async def user_command_inline(message: Message, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await state.clear()
await message.answer(
@@ -46,13 +47,13 @@ async def user_command_inline(message: Message, bot: Bot, state: FSM, rSession:
# Колбэк - User X
@router.callback_query(F.data == 'user_inline_x')
async def user_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def user_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
await call.answer(f"Click User X")
# Колбэк - User
@router.callback_query(F.data.startswith('user_inline:'))
async def user_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, rSession: RS, my_user):
async def user_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, arSession: ARS, User: UserModel):
get_data = call.data.split(":")[1]
await call.answer(f"Click User - {get_data}", True)