This commit is contained in:
djimbo
2022-08-13 09:18:51 +03:00
commit 562d7f1acf
34 changed files with 1236 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# - *- coding: utf- 8 - *-
from aiogram import Dispatcher, F
from tgbot.routers import main_errors, main_missed, main_start
from tgbot.routers.admin import admin_menu
from tgbot.routers.user import user_menu
from tgbot.utils.misc.bot_filters import IsAdmin
# Регистрация роутеров
def register_all_routers(dp: Dispatcher):
# Подключение фильтров
main_errors.router.message.filter(F.chat.type == "private")
main_start.router.message.filter(F.chat.type == "private")
main_missed.router.message.filter(F.chat.type == "private")
user_menu.router.message.filter(F.chat.type == "private")
admin_menu.router.message.filter(F.chat.type == "private", IsAdmin())
# Инициализация обязательных роутеров
dp.include_router(main_errors.router)
dp.include_router(main_start.router)
# Подключение хендлеров (юзеров и админов)
dp.include_router(user_menu.router) # Юзер хендлер
dp.include_router(admin_menu.router) # Админ хендлер
# Инициализация обязательных роутеров
dp.include_router(main_missed.router)
View File
+46
View File
@@ -0,0 +1,46 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.types import FSInputFile, Message
from tgbot.config import PATH_DATABASE, PATH_LOGS
from tgbot.data.config import PATH_DATABASE, PATH_LOGS
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
router = Router()
# Кнопка - Admin Inline
@router.message(text="Admin Inline")
async def admin_button_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("Click Button - Admin Inline", reply_markup=admin_inl)
# Кнопка - Admin Reply
@router.message(text="Admin Reply")
async def admin_button_reply(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("Click Button - Admin Reply", reply_markup=admin_rep)
# Получение Базы Данных
@router.message(commands=['db', 'database'])
async def admin_database(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer_document(FSInputFile(PATH_DATABASE),
caption=f"<b>📦 BACKUP</b>\n"
f"<code>🕰 {get_date()}</code>")
# Получение логов
@router.message(commands=['log', 'logs'])
async def admin_log(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer_document(FSInputFile(PATH_LOGS), caption=f"<code>🕰 {get_date()}</code>")
+23
View File
@@ -0,0 +1,23 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.exceptions import TelegramAPIError
from aiogram.types import Update
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>")
bot_logger.exception(
f"Exception: {exception}\n"
f"Update: {update.dict()}"
)
+40
View File
@@ -0,0 +1,40 @@
# - *- coding: utf- 8 - *-
from aiogram import types, Router
from aiogram.types import CallbackQuery
from tgbot.keyboards.reply_main import menu_frep
from tgbot.utils.misc.bot_models import FSM
router = Router()
# Колбэк с удалением сообщения
@router.callback_query(text="close_this")
async def processing_callback_remove(call: CallbackQuery, state: FSM):
await call.message.delete()
# Колбэк с обработкой кнопки
@router.callback_query(text="...")
async def processing_callback_answer(call: CallbackQuery, state: FSM):
await call.answer(cache_time=20)
# Колбэк с обработкой удаления сообщений потерявших стейт
@router.callback_query()
async def processing_callback_missed(call: CallbackQuery, state: FSM):
try:
await call.message.delete()
except:
pass
await call.message.answer("<b>❌ Данные не были найдены из-за перезапуска скрипта.\n"
"♻ Выполните действие заново.</b>",
reply_markup=menu_frep(call.from_user.id))
# Обработка всех неизвестных команд
@router.message()
async def processing_message_missed(message: types.Message, state: FSM):
await message.answer("♦ Неизвестная команда.\n"
"▶ Введите /start")
+19
View File
@@ -0,0 +1,19 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.types import Message
from tgbot.keyboards.reply_main import menu_frep
from tgbot.utils.misc.bot_models import FSM, RS
router = Router()
# Открытие главного меню
@router.message(text_startswith=["⬅ Главное меню", "/start"])
async def main_start(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("🔸 Бот готов к использованию.\n"
"🔸 Если не появились вспомогательные кнопки\n"
"▶ Введите /start",
reply_markup=menu_frep(message.from_user.id))
View File
+34
View File
@@ -0,0 +1,34 @@
# - *- coding: utf- 8 - *-
from aiogram import Router, Bot
from aiogram.types import Message
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
router = Router()
# Кнопка - User Inline
@router.message(text="User Inline")
async def user_button_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("Click Button - User Inline", reply_markup=user_inl)
# Кнопка - User Reply
@router.message(text="User Reply")
async def user_button_reply(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("Click Button - User Reply", reply_markup=user_rep)
# Команда - /inline
@router.message(commands="inline")
async def user_command_inline(message: Message, bot: Bot, state: FSM, rSession: RS, my_user):
await state.clear()
await message.answer("Click command - /inline", reply_markup=menu_finl(message.from_user.id))