diff --git a/aiogram_calendar/dialog_calendar.py b/aiogram_calendar/dialog_calendar.py index 1cf2317..d92cd4e 100644 --- a/aiogram_calendar/dialog_calendar.py +++ b/aiogram_calendar/dialog_calendar.py @@ -194,4 +194,5 @@ async def process_selection(self, query: CallbackQuery, data: DialogCalendarCall if data.act == DialogCalAct.cancel: await query.message.delete_reply_markup() + return False, 'cancel' return return_data diff --git a/aiogram_calendar/simple_calendar.py b/aiogram_calendar/simple_calendar.py index d2083e8..49ddb85 100644 --- a/aiogram_calendar/simple_calendar.py +++ b/aiogram_calendar/simple_calendar.py @@ -177,5 +177,6 @@ async def process_selection(self, query: CallbackQuery, data: SimpleCalendarCall await query.answer(cache_time=60) if data.act == SimpleCalAct.cancel: await query.message.delete_reply_markup() + return False, 'cancel' # at some point user clicks DAY button, returning date return return_data diff --git a/aiogram_calendar/tests/test_dialog_calendar.py b/aiogram_calendar/tests/test_dialog_calendar.py index e05f62c..5ffbaab 100644 --- a/aiogram_calendar/tests/test_dialog_calendar.py +++ b/aiogram_calendar/tests/test_dialog_calendar.py @@ -72,7 +72,7 @@ async def test_start_calendar_params(year, expected1, expected2): (DialogCalendarCallback(**{'act': 'SET-MONTH', 'year': '2022', 'month': '8', 'day': '1'}), (False, None)), (DialogCalendarCallback(**{'act': 'SET-YEAR', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), (DialogCalendarCallback(**{'act': 'START', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), - (DialogCalendarCallback(**{'act': 'CANCEL', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), + (DialogCalendarCallback(**{'act': 'CANCEL', 'year': '2021', 'month': '8', 'day': '0'}), (False, 'cancel')), ] diff --git a/aiogram_calendar/tests/test_simple_calendar.py b/aiogram_calendar/tests/test_simple_calendar.py index 760e332..9c9685b 100644 --- a/aiogram_calendar/tests/test_simple_calendar.py +++ b/aiogram_calendar/tests/test_simple_calendar.py @@ -83,7 +83,7 @@ async def test_start_calendar_params(year, month, expected, expected_2): (SimpleCalendarCallback(**{'act': 'PREV-MONTH', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), (SimpleCalendarCallback(**{'act': 'NEXT-YEAR', 'year': '2022', 'month': '8', 'day': '1'}), (False, None)), (SimpleCalendarCallback(**{'act': 'NEXT-MONTH', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), - (SimpleCalendarCallback(**{'act': 'CANCEL', 'year': '2021', 'month': '8', 'day': '0'}), (False, None)), + (SimpleCalendarCallback(**{'act': 'CANCEL', 'year': '2021', 'month': '8', 'day': '0'}), (False, 'cancel')), (SimpleCalendarCallback(**{'act': 'TODAY', 'year': '2021', 'month': '8', 'day': '1'}), (False, None)), ] diff --git a/example_bot.py b/example_bot.py index f8a98b7..87103b5 100644 --- a/example_bot.py +++ b/example_bot.py @@ -82,6 +82,9 @@ async def process_simple_calendar(callback_query: CallbackQuery, callback_data: f'You selected {date.strftime("%d/%m/%Y")}', reply_markup=start_kb ) + else: + if date == 'cancel': + await callback_query.message.answer("Cancelled") @dp.message(F.text.lower() == 'dialog calendar') @@ -127,6 +130,9 @@ async def process_dialog_calendar(callback_query: CallbackQuery, callback_data: f'You selected {date.strftime("%d/%m/%Y")}', reply_markup=start_kb ) + else: + if date == 'cancel': + await callback_query.message.answer("Cancelled") async def main() -> None: