Compare commits

..

3 Commits

Author SHA1 Message Date
0a48fba5c0 fix builder buttons 2025-03-29 17:11:19 +03:00
6f44c533d4 fix args handlers 2025-03-29 17:10:57 +03:00
a487f452d9 delete attr CExample 2025-03-29 17:10:31 +03:00
3 changed files with 8 additions and 12 deletions

View File

@ -4,4 +4,3 @@ from dataclasses import dataclass
@dataclass @dataclass
class CExample: class CExample:
example: str = "ExampleCallback" example: str = "ExampleCallback"
state: bool = True

View File

@ -11,18 +11,17 @@ from data import callbacks, factory
def example_callback() -> InlineKeyboardMarkup: def example_callback() -> InlineKeyboardMarkup:
"""Выберите нужный тип""" """Выберите нужный тип"""
inline_builder = InlineKeyboardBuilder() inline_builder = InlineKeyboardBuilder()
inline_builder.row( list_build: tuple[InlineKeyboardButton] = (
InlineKeyboardButton( InlineKeyboardButton(
text="📠 Callback", text="📠 Callback",
callback_data=callbacks.CExample.example, callback_data=callbacks.CExample.example,
), ),
InlineKeyboardButton( InlineKeyboardButton(
text="📠 Callback Factory", text="📠 Callback Factory | State",
callback_data=factory.ExampleFactory(example='Example 2').pack(), callback_data=factory.ExampleFactory(example='Example 2').pack(),
), ),
InlineKeyboardButton(
text="📠 State",
callback_data=callbacks.CExample.state,
),
) )
for i in list_build:
inline_builder.row(i)
return inline_builder.as_markup(resize_keyboard=True) return inline_builder.as_markup(resize_keyboard=True)

View File

@ -23,7 +23,6 @@ async def mainstart(
async def example_callback( async def example_callback(
message: aiogram.types.CallbackQuery, message: aiogram.types.CallbackQuery,
state: FSMContext, state: FSMContext,
command: Command,
bot: Bot, bot: Bot,
): ):
await state.clear() await state.clear()
@ -33,12 +32,12 @@ async def example_callback(
async def example_callback_factory( async def example_callback_factory(
message: aiogram.types.CallbackQuery, message: aiogram.types.CallbackQuery,
state: FSMContext, state: FSMContext,
command: Command,
bot: Bot, bot: Bot,
callback_data: factory.ExampleFactory = None, callback_data: factory.ExampleFactory = None,
): ):
await state.clear() await state.clear()
await state.set_state(states.ExampleState.input_user) await state.set_state(states.ExampleState.input_user)
await message.answer()
return await bot.send_message( return await bot.send_message(
chat_id=message.message.chat.id, chat_id=message.message.chat.id,
text=f'CallbackData: {callback_data.example} | Set state, wait input...' text=f'CallbackData: {callback_data.example} | Set state, wait input...'
@ -48,10 +47,9 @@ async def example_callback_factory(
async def example_state( async def example_state(
message: aiogram.types.Message, message: aiogram.types.Message,
state: FSMContext, state: FSMContext,
command: Command,
bot: Bot, bot: Bot,
): ):
await state.clear() await state.clear()
return await message.answer( return await message.answer(
text=f"hello! Your text: \n\n{message.text}" text=f"hello! Your text: \n\n{message.text}\n\nState Off!"
) )