Fix bugs, add README and Makefile
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
import asyncio
|
||||
import uuid
|
||||
|
||||
from aiogram import types, F, Router
|
||||
from aiogram import types
|
||||
from aiogram.enums import MessageOriginType, ParseMode
|
||||
from aiogram.filters import Command
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder
|
||||
from pydantic_core import PydanticCustomError
|
||||
from pydantic_filters import PagePagination
|
||||
from pydantic_extra_types.phone_numbers import PhoneNumber
|
||||
|
||||
from birthday_pool_bot.dto import (
|
||||
BankEnum,
|
||||
PaymentData,
|
||||
Pool,
|
||||
Subscription,
|
||||
SubscriptionFilter,
|
||||
User,
|
||||
)
|
||||
from birthday_pool_bot.repositories.repositories import (
|
||||
@@ -24,18 +16,11 @@ from birthday_pool_bot.repositories.repositories import (
|
||||
UsersRepository,
|
||||
)
|
||||
from . import constants, logic
|
||||
from .callback_data import (
|
||||
AddSubscriptionCallbackData,
|
||||
AddSubscriptionConfirmCallbackData,
|
||||
ConfirmAnswerEnum,
|
||||
MenuCallbackData,
|
||||
SubscriptionCallbackData,
|
||||
SubscriptionsCallbackData,
|
||||
)
|
||||
from .callback_data import PoolCallbackData, SubscriptionCallbackData
|
||||
from .exceptions import FlowInternalError
|
||||
from .states import (
|
||||
AddSubscriptionPoolState,
|
||||
AddSubscriptionState,
|
||||
NewSubscriptionPoolState,
|
||||
NewSubscriptionState,
|
||||
MenuState,
|
||||
SetProfileBirthdayState,
|
||||
SetProfileGiftPaymentDataState,
|
||||
@@ -322,31 +307,31 @@ async def delete_subscription_callback(
|
||||
await state.set_state(MenuState.SUBSCRIPTIONS)
|
||||
|
||||
|
||||
async def add_subscription_message_handler(
|
||||
async def new_subscription_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
|
||||
|
||||
async def add_subscription_callback_handler(
|
||||
async def new_subscription_callback_handler(
|
||||
callback_query: types.CallbackQuery,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_user(callback_query=callback_query)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(callback_query=callback_query)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
|
||||
|
||||
async def ask_add_subscription_user_message_handler(
|
||||
async def ask_new_subscription_user_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
|
||||
|
||||
async def set_add_subscription_user_message_handler(
|
||||
async def set_new_subscription_user_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
@@ -370,15 +355,15 @@ async def set_add_subscription_user_message_handler(
|
||||
await message.reply(
|
||||
text="Пользователь скрыл свои данные, попробуйте отправить номер телефона или его контакт",
|
||||
)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
if message.forward_origin.type != MessageOriginType.USER:
|
||||
await message.reply(
|
||||
text="Это сообщение не от пользователя, попробуйте ещё раз",
|
||||
)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
user_name = get_telegram_user_full_name(message.forward_origin.sender_user)
|
||||
user_telegram_id = message.forward_origin.sender_user.id
|
||||
@@ -390,8 +375,8 @@ async def set_add_subscription_user_message_handler(
|
||||
try:
|
||||
PhoneNumber._validate(user_phone, None)
|
||||
except PydanticCustomError:
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
subscription_user = await users_repository.get_user_by_phone(phone=user_phone)
|
||||
|
||||
@@ -406,8 +391,8 @@ async def set_add_subscription_user_message_handler(
|
||||
|
||||
if subscription_user.id == user.id:
|
||||
await message.reply("Нельзя подписаться на самого себя")
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with subscriptions_repository.transaction():
|
||||
@@ -418,8 +403,8 @@ async def set_add_subscription_user_message_handler(
|
||||
|
||||
if subscription is not None:
|
||||
await message.reply(text="У вас уже есть подписка на этого человека")
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.update_data(
|
||||
@@ -427,65 +412,65 @@ async def set_add_subscription_user_message_handler(
|
||||
)
|
||||
|
||||
if subscription_user.birthday is None:
|
||||
await logic.ask_add_subscription_user_birthday(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_DATE)
|
||||
await logic.ask_new_subscription_user_birthday(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_DATE)
|
||||
return
|
||||
|
||||
await logic.ask_add_subscription_name(
|
||||
await logic.ask_new_subscription_name(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
subscription_user_id=subscription_user.id,
|
||||
)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_NAME)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_NAME)
|
||||
|
||||
|
||||
async def ask_add_subscription_user_birthday_message_handler(
|
||||
async def ask_new_subscription_user_birthday_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_user_birthday(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_DATE)
|
||||
await logic.ask_new_subscription_user_birthday(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_DATE)
|
||||
|
||||
|
||||
async def set_add_subscription_user_birthday_message_handler(
|
||||
async def set_new_subscription_user_birthday_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
users_repository: UsersRepository,
|
||||
):
|
||||
birthday = parse_date(message=message)
|
||||
if birthday is None:
|
||||
await logic.ask_add_subscription_user_birthday(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_DATE)
|
||||
await logic.ask_new_subscription_user_birthday(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_DATE)
|
||||
return
|
||||
|
||||
state_data = await state.get_data()
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
subscription_user = await users_repository.get_user_by_id(user_id=subscription_user_id)
|
||||
if subscription_user is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
subscription_user.birthday = birthday
|
||||
await users_repository.update_user(user=subscription_user)
|
||||
|
||||
await logic.ask_add_subscription_name(
|
||||
await logic.ask_new_subscription_name(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
subscription_user_id=subscription_user.id,
|
||||
)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_NAME)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_NAME)
|
||||
|
||||
|
||||
async def ask_add_subscription_name_message_handler(
|
||||
async def ask_new_subscription_name_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
users_repository: UsersRepository,
|
||||
@@ -494,26 +479,26 @@ async def ask_add_subscription_name_message_handler(
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.ask_add_subscription_name(
|
||||
await logic.ask_new_subscription_name(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_NAME)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_NAME)
|
||||
|
||||
|
||||
async def set_add_subscription_name_message_handler(
|
||||
async def set_new_subscription_name_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
@@ -525,29 +510,29 @@ async def set_add_subscription_name_message_handler(
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
subscription_user = await users_repository.get_user_by_id(user_id=subscription_user_id)
|
||||
if subscription_user is None or subscription_user.birthday is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.update_data(subscription_name=message.text)
|
||||
await logic.ask_add_subscription_pool_decision(
|
||||
await logic.ask_new_subscription_pool_decision(
|
||||
message=message,
|
||||
pools_repository=pools_repository,
|
||||
users_repository=users_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_POOL_DECISION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_POOL_DECISION)
|
||||
|
||||
|
||||
async def ask_add_subscription_pool_decision_message_handler(
|
||||
async def ask_new_subscription_pool_decision_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
pools_repository: PoolsRepository,
|
||||
@@ -557,12 +542,12 @@ async def ask_add_subscription_pool_decision_message_handler(
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.ask_add_subscription_pool_decision(
|
||||
await logic.ask_new_subscription_pool_decision(
|
||||
message=message,
|
||||
pools_repository=pools_repository,
|
||||
users_repository=users_repository,
|
||||
@@ -570,72 +555,235 @@ async def ask_add_subscription_pool_decision_message_handler(
|
||||
)
|
||||
except FlowInternalError:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_POOL_DECISION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_POOL_DECISION)
|
||||
|
||||
|
||||
async def show_add_subscription_pools_message_handler(
|
||||
async def ask_new_subscription_pool_decision_callback_handler(
|
||||
callback_query: types.Message,
|
||||
state: FSMContext,
|
||||
pools_repository: PoolsRepository,
|
||||
users_repository: UsersRepository,
|
||||
):
|
||||
state_data = await state.get_data()
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.ask_new_subscription_pool_decision(
|
||||
message=callback_query.message,
|
||||
pools_repository=pools_repository,
|
||||
users_repository=users_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_POOL_DECISION)
|
||||
|
||||
|
||||
async def show_new_subscription_choosing_pools_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
users_repository: UsersRepository,
|
||||
pools_repository: PoolsRepository,
|
||||
):
|
||||
state_data = await state.get_data()
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.show_add_subscription_pools(
|
||||
await logic.show_new_subscription_choosing_pools(
|
||||
user=user,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
message=message,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await logic.ask_add_subscription_pool_description(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_DESCRIPTION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
|
||||
|
||||
async def ask_add_subscription_pool_description_message_handler(
|
||||
async def show_new_subscription_choosing_pools_callback_handler(
|
||||
callback_query: types.CallbackQuery,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
users_repository: UsersRepository,
|
||||
pools_repository: PoolsRepository,
|
||||
):
|
||||
state_data = await state.get_data()
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
if subscription_user_id is None:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.show_new_subscription_choosing_pools(
|
||||
user=user,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
message=callback_query.message,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
|
||||
|
||||
async def show_new_subscription_choosing_pool_callback_handler(
|
||||
callback_query: types.CallbackQuery,
|
||||
state: FSMContext,
|
||||
pools_repository: PoolsRepository,
|
||||
):
|
||||
callback_data = PoolCallbackData.unpack(callback_query.data)
|
||||
|
||||
try:
|
||||
await logic.show_new_subscription_choosing_pool(
|
||||
pools_repository=pools_repository,
|
||||
pool_id=callback_data.id,
|
||||
callback_query=callback_query,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.show_new_subscription_choosing_pools(
|
||||
user=user,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
return
|
||||
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
|
||||
|
||||
async def choose_new_subscription_pool_callback_handler(
|
||||
callback_query: types.CallbackQuery,
|
||||
state: FSMContext,
|
||||
users_repository: UsersRepository,
|
||||
pools_repository: PoolsRepository,
|
||||
):
|
||||
state_data = await state.get_data()
|
||||
subscription_user_id = state_data.get("subscription_user_id")
|
||||
subscription_name = state_data.get("subscription_name")
|
||||
if not all((subscription_user_id, subscription_name)):
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
subscription_user = await users_repository.get_user_by_id(
|
||||
user_id=subscription_user_id,
|
||||
)
|
||||
if subscription_user is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
callback_data = PoolCallbackData.unpack(callback_query.data)
|
||||
|
||||
async with pools_repository.transaction():
|
||||
subscription_pool = await pools_repository.get_pool_by_id(
|
||||
pool_id=callback_data.id,
|
||||
)
|
||||
if subscription_pool is None:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.show_new_subscription_choosing_pools(
|
||||
user=user,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_user_id=subscription_user_id,
|
||||
callback_query=callback_query,
|
||||
)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
return
|
||||
|
||||
await state.update_data(
|
||||
subscription_pool_id=callback_data.id,
|
||||
)
|
||||
|
||||
try:
|
||||
await logic.ask_new_subscription_confirmation(
|
||||
message=callback_query.message,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_name=subscription_name,
|
||||
subscription_user_id=subscription_user_id,
|
||||
subscription_pool_id=callback_data.id,
|
||||
)
|
||||
except FlowInternalError:
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.show_new_subscription_choosing_pools(
|
||||
message=callback_query.message,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
subscription_name=subscription_name,
|
||||
subscription_user_id=subscription_user_id,
|
||||
subscription_pool_id=callback_data.id,
|
||||
)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CHOOSE_POOL)
|
||||
return
|
||||
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
|
||||
|
||||
async def ask_new_subscription_pool_description_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_pool_description(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_DESCRIPTION)
|
||||
await logic.ask_new_subscription_pool_description(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_DESCRIPTION)
|
||||
|
||||
|
||||
async def set_add_subscription_pool_description_message_handler(
|
||||
async def set_new_subscription_pool_description_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
description = message.text
|
||||
await state.update_data(subscription_pool_description=description)
|
||||
|
||||
await logic.ask_add_subscription_pool_payment_phone(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
await logic.ask_new_subscription_pool_payment_phone(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
|
||||
|
||||
async def ask_add_subscription_pool_payment_phone_message_handler(
|
||||
async def ask_new_subscription_pool_payment_phone_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
):
|
||||
await logic.ask_add_subscription_pool_payment_phone(message=message, user=user)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
await logic.ask_new_subscription_pool_payment_phone(message=message, user=user)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
|
||||
|
||||
async def set_add_subscription_pool_payment_phone_message_handler(
|
||||
async def set_new_subscription_pool_payment_phone_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
@@ -646,8 +794,8 @@ async def set_add_subscription_pool_payment_phone_message_handler(
|
||||
phone_number = message.text
|
||||
else:
|
||||
await message.reply(text="Некорректный номер телефона, попробуйте ещё раз")
|
||||
await logic.ask_add_subscription_pool_payment_phone(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
await logic.ask_new_subscription_pool_payment_phone(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -656,16 +804,16 @@ async def set_add_subscription_pool_payment_phone_message_handler(
|
||||
await message.reply(
|
||||
text="Некорректный номер телефона, попробуйте ещё раз",
|
||||
)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
return
|
||||
|
||||
await state.update_data(subscription_pool_phone=phone_number)
|
||||
|
||||
await logic.ask_add_subscription_pool_payment_bank(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_BANK)
|
||||
await logic.ask_new_subscription_pool_payment_bank(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_BANK)
|
||||
|
||||
|
||||
async def set_add_subscription_pool_payment_data_from_profile_message_handler(
|
||||
async def set_new_subscription_pool_payment_data_from_profile_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
@@ -674,8 +822,8 @@ async def set_add_subscription_pool_payment_data_from_profile_message_handler(
|
||||
):
|
||||
if user.gift_payment_data is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_pool_payment_phone(message=message, user=user)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
await logic.ask_new_subscription_pool_payment_phone(message=message, user=user)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_PHONE)
|
||||
return
|
||||
|
||||
state_data = await state.get_data()
|
||||
@@ -684,15 +832,15 @@ async def set_add_subscription_pool_payment_data_from_profile_message_handler(
|
||||
subscription_pool_description = state_data.get("subscription_pool_description")
|
||||
if not all((subscription_user_id, subscription_name)):
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.update_data(
|
||||
subscription_pool_phone=user.gift_payment_data.phone,
|
||||
subscription_pool_bank=user.gift_payment_data.bank,
|
||||
)
|
||||
await logic.ask_add_subscription_confirmation(
|
||||
await logic.ask_new_subscription_confirmation(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
@@ -702,18 +850,18 @@ async def set_add_subscription_pool_payment_data_from_profile_message_handler(
|
||||
subscription_pool_phone=user.gift_payment_data.phone,
|
||||
subscription_pool_bank=user.gift_payment_data.bank,
|
||||
)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
|
||||
|
||||
async def ask_add_subscription_pool_payment_bank_message_handler(
|
||||
async def ask_new_subscription_pool_payment_bank_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
):
|
||||
await logic.ask_add_subscription_pool_payment_bank(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_PAYMENT_BANK)
|
||||
await logic.ask_new_subscription_pool_payment_bank(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_PAYMENT_BANK)
|
||||
|
||||
|
||||
async def set_add_subscription_pool_payment_bank_message_handler(
|
||||
async def set_new_subscription_pool_payment_bank_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
users_repository: UsersRepository,
|
||||
@@ -726,13 +874,13 @@ async def set_add_subscription_pool_payment_bank_message_handler(
|
||||
subscription_pool_phone = state_data.get("subscription_pool_phone")
|
||||
if not all((subscription_user_id, subscription_name)):
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
if subscription_pool_phone is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_pool_decision(message=message)
|
||||
await state.set_state(AddSubscriptionPoolState.WAITING_FOR_DESCRIPTION)
|
||||
await logic.ask_new_subscription_pool_decision(message=message)
|
||||
await state.set_state(NewSubscriptionPoolState.WAITING_FOR_DESCRIPTION)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
@@ -741,8 +889,8 @@ async def set_add_subscription_pool_payment_bank_message_handler(
|
||||
)
|
||||
if subscription_user is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
bank_name = message.text
|
||||
@@ -754,7 +902,7 @@ async def set_add_subscription_pool_payment_bank_message_handler(
|
||||
bank = constants.BANKS_MAP[bank_name]
|
||||
await state.update_data(subscription_pool_bank=bank)
|
||||
|
||||
await logic.ask_add_subscription_confirmation(
|
||||
await logic.ask_new_subscription_confirmation(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
@@ -764,10 +912,10 @@ async def set_add_subscription_pool_payment_bank_message_handler(
|
||||
subscription_pool_phone=subscription_pool_phone,
|
||||
subscription_pool_bank=bank,
|
||||
)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
|
||||
|
||||
async def ask_add_subscription_confirmation_message_handler(
|
||||
async def ask_new_subscription_confirmation_message_handler(
|
||||
message: types.Message,
|
||||
state: FSMContext,
|
||||
users_repository: UsersRepository,
|
||||
@@ -782,8 +930,8 @@ async def ask_add_subscription_confirmation_message_handler(
|
||||
subscription_pool_bank = state_data.get("subscription_pool_bank")
|
||||
if not all((subscription_user_id, subscription_name)):
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
@@ -792,12 +940,12 @@ async def ask_add_subscription_confirmation_message_handler(
|
||||
)
|
||||
if subscription_user is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
try:
|
||||
await logic.ask_add_subscription_confirmation(
|
||||
await logic.ask_new_subscription_confirmation(
|
||||
message=message,
|
||||
users_repository=users_repository,
|
||||
pools_repository=pools_repository,
|
||||
@@ -810,14 +958,14 @@ async def ask_add_subscription_confirmation_message_handler(
|
||||
)
|
||||
except FlowInternalError:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await logic.ask_new_subscription_user(message=message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_CONFIRMATION)
|
||||
|
||||
|
||||
async def confirm_add_subscription_callback_handler(
|
||||
async def confirm_new_subscription_callback_handler(
|
||||
callback_query: types.CallbackQuery,
|
||||
state: FSMContext,
|
||||
user: User,
|
||||
@@ -833,9 +981,9 @@ async def confirm_add_subscription_callback_handler(
|
||||
subscription_pool_phone = state_data.get("subscription_pool_phone")
|
||||
subscription_pool_bank = state_data.get("subscription_pool_bank")
|
||||
if not all((subscription_user_id, subscription_name)):
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
async with users_repository.transaction():
|
||||
@@ -843,9 +991,9 @@ async def confirm_add_subscription_callback_handler(
|
||||
user_id=subscription_user_id,
|
||||
)
|
||||
if subscription_user is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
subscription_pool = None
|
||||
@@ -855,9 +1003,9 @@ async def confirm_add_subscription_callback_handler(
|
||||
pool_id=subscription_pool_id,
|
||||
)
|
||||
if subscription_pool is None:
|
||||
await message.reply(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_add_subscription_user(message=message)
|
||||
await state.set_state(AddSubscriptionState.WAITING_FOR_PHONE)
|
||||
await callback_query.answer(text=constants.ERROR_MESSAGE)
|
||||
await logic.ask_new_subscription_user(message=callback_query.message)
|
||||
await state.set_state(NewSubscriptionState.WAITING_FOR_PHONE)
|
||||
return
|
||||
|
||||
if subscription_pool is None and all((subscription_pool_phone, subscription_pool_bank)):
|
||||
|
||||
Reference in New Issue
Block a user