From 23d7754ff3409b8cea98fac277b06e43c709f19c Mon Sep 17 00:00:00 2001 From: sergey Date: Tue, 11 Feb 2025 02:10:03 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BotCode/keyboards/inline_kb/randnum_kb.py | 11 ++++---- .../administration/easteggs_handlers.py | 2 +- .../routers/callback_handlers/actor_kb_cb.py | 2 +- .../callback_handlers/randnum_kb_cb.py | 25 +++++++------------ .../routers/commands/user_cmd/randnum_cmd.py | 3 +-- BotCode/routers/commands/user_cmd/states.py | 0 BotLibrary/library/bots.py | 1 + 7 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 BotCode/routers/commands/user_cmd/states.py diff --git a/BotCode/keyboards/inline_kb/randnum_kb.py b/BotCode/keyboards/inline_kb/randnum_kb.py index 992d633..e17a681 100644 --- a/BotCode/keyboards/inline_kb/randnum_kb.py +++ b/BotCode/keyboards/inline_kb/randnum_kb.py @@ -14,8 +14,9 @@ class ButtonInl: mark_cbd = "mark_cbd" -# Функция создания клавиатуры на команду: /actor -def get_randnum_kb() -> InlineKeyboardMarkup: - ikb.button(text=ButtonInl.text, callback_data=ButtonInl.mark_cbd) - ikb.add_row(1) - return ikb.as_markup() +# Функция создания клавиатуры на команду: /randnum +def get_randnum_kb(text=ButtonInl.text) -> InlineKeyboardMarkup: + ikb.button(text=text, callback_data=ButtonInl.mark_cbd) + ikb.adjust(1) + return ikb.as_markup() # Возвращаем клавиатуру + diff --git a/BotCode/routers/administration/easteggs_handlers.py b/BotCode/routers/administration/easteggs_handlers.py index f2e81f9..50bd6f5 100644 --- a/BotCode/routers/administration/easteggs_handlers.py +++ b/BotCode/routers/administration/easteggs_handlers.py @@ -8,7 +8,7 @@ from BotCode.routers.msg_default import msg_default # Создание роутера и настройка экспорта __all__ = ("router",) -router = Router(name=__name__) +router = Router(name="easteggs") log_type = "EastEggs" diff --git a/BotCode/routers/callback_handlers/actor_kb_cb.py b/BotCode/routers/callback_handlers/actor_kb_cb.py index 5c3e0b3..7899446 100644 --- a/BotCode/routers/callback_handlers/actor_kb_cb.py +++ b/BotCode/routers/callback_handlers/actor_kb_cb.py @@ -8,7 +8,7 @@ from BotCode.keyboards.inline_kb.actor_kb import ButtonInl # Создание роутера и настройка экспорта модулей __all__ = ("router",) -router = Router(name="actor_kb_cb_router") +router = Router(name="actor_kb_cb") # Тестирование реферальных ссылок diff --git a/BotCode/routers/callback_handlers/randnum_kb_cb.py b/BotCode/routers/callback_handlers/randnum_kb_cb.py index a26b19b..9876bb7 100644 --- a/BotCode/routers/callback_handlers/randnum_kb_cb.py +++ b/BotCode/routers/callback_handlers/randnum_kb_cb.py @@ -4,11 +4,13 @@ from random import randint from aiogram import Router, F from aiogram.types import CallbackQuery -from BotCode.keyboards.inline_kb.randnum_kb import ButtonInl, get_randnum_kb + +from BotLibrary import ikb +from BotCode.keyboards.inline_kb.randnum_kb import ButtonInl # Создание роутера и настройка экспорта модулей __all__ = ("router",) -router = Router(name="randnum_kb_cb_router") +router = Router(name="randnum_kb_cb") # Тестирование редактирования сообщения @@ -16,17 +18,8 @@ router = Router(name="randnum_kb_cb_router") async def random_site_cb(callback_query: CallbackQuery): await callback_query.answer() - # Новый текст и клавиатура - new_text = f"Какая оценка у тебя будет сегодня: {randint(1, 5)}" - new_reply_markup = get_randnum_kb("Получить ответ от Таро") - - # Текущий текст и клавиатура - current_text = callback_query.message.text - current_reply_markup = callback_query.message.reply_markup - - # Проверяем, отличаются ли текст и клавиатура - if current_text != new_text or current_reply_markup != new_reply_markup: - await callback_query.message.edit_text( - text=new_text, - reply_markup=new_reply_markup, - ) + # Редактируем сообщение и обновляем клавиатуру + await callback_query.message.edit_text( + text=f"Какая оценка у тебя будет сегодня: {randint(1, 5)}", + reply_markup=ikb.as_markup(), # Обновляем клавиатуру + ) diff --git a/BotCode/routers/commands/user_cmd/randnum_cmd.py b/BotCode/routers/commands/user_cmd/randnum_cmd.py index 3a81643..eb30ec4 100644 --- a/BotCode/routers/commands/user_cmd/randnum_cmd.py +++ b/BotCode/routers/commands/user_cmd/randnum_cmd.py @@ -16,7 +16,6 @@ description = "Описание" # Список ключевых слов для команды keywords = ["кфтвтгь", "randnum",] - # Хэндлер на команду /randnum @router.message(Command(*keywords, prefix=BotVariables.prefixs, ignore_case=True)) @router.message(F.text.lower().in_(keywords)) @@ -24,7 +23,7 @@ async def cmd_randnum(message: types.Message): text = "Работа с рандомом оценок!" await message.reply( text="Вы хотите узнать вашу оценку на сегодня?!", - reply_markup=get_randnum_kb("Хочу: ТЫК"), + reply_markup=get_randnum_kb(), ) # Активация логгера diff --git a/BotCode/routers/commands/user_cmd/states.py b/BotCode/routers/commands/user_cmd/states.py deleted file mode 100644 index e69de29..0000000 diff --git a/BotLibrary/library/bots.py b/BotLibrary/library/bots.py index 4d4fda1..44be19e 100644 --- a/BotLibrary/library/bots.py +++ b/BotLibrary/library/bots.py @@ -4,6 +4,7 @@ from aiogram import Dispatcher, Bot, F from aiogram.enums import ParseMode from aiogram.client.default import DefaultBotProperties +from aiogram.types import InlineKeyboardMarkup, ReplyKeyboardMarkup from aiogram.utils.keyboard import ReplyKeyboardBuilder, InlineKeyboardBuilder from apscheduler.schedulers.asyncio import AsyncIOScheduler