This commit is contained in:
djimbo
2022-11-18 14:29:52 +03:00
parent 9ba4ee7215
commit 7d4aaf99d0
14 changed files with 185 additions and 109 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ def register_all_routers(dp: Dispatcher):
dp.include_router(main_errors.router)
dp.include_router(main_start.router)
# Подключение хендлеров (юзеров и админов)
# Подключение пользовательских роутеров (юзеров и админов)
dp.include_router(user_menu.router) # Юзер хендлер
dp.include_router(admin_menu.router) # Админ хендлер
+26 -10
View File
@@ -1,6 +1,7 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.types import FSInputFile, Message
from aiogram.filters import Text, Command
from aiogram.types import FSInputFile, Message, CallbackQuery
from tgbot.data.config import PATH_DATABASE, PATH_LOGS
from tgbot.keyboards.inline_misc import admin_inl
@@ -12,7 +13,7 @@ router = Router()
# Кнопка - Admin Inline
@router.message(text="Admin Inline")
@router.message(Text(text="Admin Inline"))
async def admin_button_inline(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
@@ -20,35 +21,50 @@ async def admin_button_inline(message: Message, bot: Bot, state: FSM, aSession:
# Кнопка - Admin Reply
@router.message(text="Admin Reply")
@router.message(Text(text="Admin Reply"))
async def admin_button_reply(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
await message.answer("Click Button - Admin Reply", reply_markup=admin_rep)
# Колбэк - Admin X
@router.callback_query(Text(text="admin_inline_x"))
async def admin_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
await call.answer(f"Click Admin X")
# Колбэк - Admin
@router.callback_query(Text(startswith="admin_inline:"))
async def admin_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
get_data = call.data.split(":")[1]
await call.answer(f"Click Admin - {get_data}", True)
# Получение Базы Данных
@router.message(commands=['db', 'database'])
@router.message(Command(commands=['db', 'database']))
async def admin_database(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
await message.answer_document(FSInputFile(PATH_DATABASE),
caption=f"<b>📦 BACKUP</b>\n"
f"<code>🕰 {get_date()}</code>")
f"🕰 <code>{get_date()}</code>")
# Получение логов
@router.message(commands=['log', 'logs'])
@router.message(Command(commands=['log', 'logs']))
async def admin_log(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
await message.answer_document(FSInputFile(PATH_LOGS), caption=f"<code>🕰 {get_date()}</code>")
await message.answer_document(FSInputFile(PATH_LOGS),
caption=f"<b>🖨 LOGS</b>\n"
f"🕰 <code>{get_date()}</code>")
# Очистить логи
@router.message(text_contains=['log', '_', 'clean'])
@router.message(text_contains=['log', '_', 'clear'])
async def admin_log_clear(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
@router.message(Command(commands=['clear_log', 'clear_logs', 'log_clear', 'logs_clear']))
async def admin_logs_clear(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
with open(PATH_LOGS, "w") as file:
+21 -18
View File
@@ -1,26 +1,29 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.exceptions import TelegramAPIError
from aiogram.types import Update
from aiogram import Router
from aiogram.exceptions import TelegramForbiddenError
from aiogram.filters import ExceptionTypeFilter, ExceptionMessageFilter
from aiogram.handlers import ErrorHandler
from tgbot.utils.misc.bot_logging import bot_logger
from tgbot.utils.misc_functions import send_admins
router = Router()
# Обработка ошибок
@router.errors()
async def processing_errors(update: Update, exception: TelegramAPIError, bot: Bot):
print(f"-Exception | {exception}")
await send_admins(
bot,
f"<b>❌ Ошибка\n\n"
f"<b>Exception: <code>{exception}</code>\n\n"
f"Update: <code>{update.dict()}</code></b>"
)
# Ошибка с блокировкой бота пользователем
@router.errors(ExceptionTypeFilter(TelegramForbiddenError))
class MyHandler(ErrorHandler):
async def handle(self):
pass
bot_logger.exception(
f"Exception: {exception}\n"
f"Update: {update.dict()}"
)
# Ошибка с редактированием одинакового сообщения
@router.errors(ExceptionMessageFilter(
"Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message"))
class MyHandler(ErrorHandler):
async def handle(self):
bot_logger.exception(
f"====================\n"
f"Exception name: {self.exception_name}\n"
f"Exception message: {self.exception_message}\n"
f"===================="
)
+10 -9
View File
@@ -1,28 +1,29 @@
# - *- coding: utf- 8 - *-
from aiogram import types, Router
from aiogram.types import CallbackQuery
from aiogram import Router, Bot
from aiogram.filters import Text
from aiogram.types import CallbackQuery, Message
from tgbot.keyboards.reply_main import menu_frep
from tgbot.utils.misc.bot_models import FSM
from tgbot.utils.misc.bot_models import FSM, AS
router = Router()
# Колбэк с удалением сообщения
@router.callback_query(text="close_this")
async def processing_callback_close(call: CallbackQuery, state: FSM):
@router.callback_query(Text(text="close_this"))
async def main_callback_close(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
await call.message.delete()
# Колбэк с обработкой кнопки
@router.callback_query(text="...")
async def processing_callback_answer(call: CallbackQuery, state: FSM):
@router.callback_query(Text(text="..."))
async def main_callback_answer(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
await call.answer(cache_time=20)
# Колбэк с обработкой удаления сообщений потерявших стейт
@router.callback_query()
async def processing_callback_missed(call: CallbackQuery, state: FSM):
async def main_callback_missed(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
try:
await call.message.delete()
except:
@@ -35,6 +36,6 @@ async def processing_callback_missed(call: CallbackQuery, state: FSM):
# Обработка всех неизвестных команд
@router.message()
async def processing_message_missed(message: types.Message, state: FSM):
async def main_message_missed(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await message.answer("♦ Неизвестная команда.\n"
"▶ Введите /start")
+3 -1
View File
@@ -1,5 +1,6 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.filters import Text, Command
from aiogram.types import Message
from tgbot.keyboards.reply_main import menu_frep
@@ -9,7 +10,8 @@ router = Router()
# Открытие главного меню
@router.message(text_startswith=[" Главное меню", "/start"])
@router.message(Text(text=['🔙 Главное меню']))
@router.message(Command(commands=['start']))
async def main_start(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
+19 -4
View File
@@ -1,6 +1,7 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.types import Message
from aiogram.filters import Command, Text
from aiogram.types import Message, CallbackQuery
from tgbot.keyboards.inline_main import menu_finl
from tgbot.keyboards.inline_misc import user_inl
@@ -11,7 +12,7 @@ router = Router()
# Кнопка - User Inline
@router.message(text="User Inline")
@router.message(Text(text="User Inline"))
async def user_button_inline(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
@@ -19,7 +20,7 @@ async def user_button_inline(message: Message, bot: Bot, state: FSM, aSession: A
# Кнопка - User Reply
@router.message(text="User Reply")
@router.message(Text(text="User Reply"))
async def user_button_reply(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
@@ -27,8 +28,22 @@ async def user_button_reply(message: Message, bot: Bot, state: FSM, aSession: AS
# Команда - /inline
@router.message(commands="inline")
@router.message(Command(commands="inline"))
async def user_command_inline(message: Message, bot: Bot, state: FSM, aSession: AS, my_user):
await state.clear()
await message.answer("Click command - /inline", reply_markup=menu_finl(message.from_user.id))
# Колбэк - User X
@router.callback_query(Text(text="user_inline_x"))
async def user_callback_inline_x(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
await call.answer(f"Click User X")
# Колбэк - User
@router.callback_query(Text(startswith="user_inline:"))
async def user_callback_inline(call: CallbackQuery, bot: Bot, state: FSM, aSession: AS, my_user):
get_data = call.data.split(":")[1]
await call.answer(f"Click User - {get_data}", True)