You've already forked Travel-Agent
chore: Code refactoring
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
# type: ignore
|
|
||||||
__all__ = ()
|
__all__ = ()
|
||||||
|
|
||||||
from aiogram import Router
|
from aiogram import Router
|
||||||
@@ -16,6 +15,9 @@ router = Router(name="profile_command")
|
|||||||
|
|
||||||
@router.message(Command("profile"), Registered())
|
@router.message(Command("profile"), Registered())
|
||||||
async def command_profile_handler(message: Message) -> None:
|
async def command_profile_handler(message: Message) -> None:
|
||||||
|
if message.from_user is None:
|
||||||
|
return
|
||||||
|
|
||||||
user = User().get_user_by_telegram_id(message.from_user.id)
|
user = User().get_user_by_telegram_id(message.from_user.id)
|
||||||
|
|
||||||
await message.answer(
|
await message.answer(
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# type: ignore
|
|
||||||
__all__ = ()
|
__all__ = ()
|
||||||
|
|
||||||
from aiogram import F, Router
|
from aiogram import F, Router
|
||||||
@@ -17,11 +16,11 @@ router = Router(name="start_command")
|
|||||||
|
|
||||||
@router.message(CommandStart())
|
@router.message(CommandStart())
|
||||||
async def command_start_handler(message: Message, state: FSMContext) -> None:
|
async def command_start_handler(message: Message, state: FSMContext) -> None:
|
||||||
if (
|
if message.from_user is None:
|
||||||
User.get_user_by_telegram_id(
|
return
|
||||||
telegram_id=message.from_user.id,
|
|
||||||
)
|
if User.user_by_telegram_id_exist(
|
||||||
is not None
|
telegram_id=message.from_user.id,
|
||||||
):
|
):
|
||||||
await message.answer(
|
await message.answer(
|
||||||
messages.WELCOME_AGAIN_MESSAGE.format(
|
messages.WELCOME_AGAIN_MESSAGE.format(
|
||||||
@@ -41,6 +40,9 @@ async def command_start_handler(message: Message, state: FSMContext) -> None:
|
|||||||
|
|
||||||
@router.message(RegistrationForm.username, F.text)
|
@router.message(RegistrationForm.username, F.text)
|
||||||
async def username_handler(message: Message, state: FSMContext) -> None:
|
async def username_handler(message: Message, state: FSMContext) -> None:
|
||||||
|
if message.text is None:
|
||||||
|
return
|
||||||
|
|
||||||
username = message.text.strip()
|
username = message.text.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -66,6 +68,9 @@ async def username_handler(message: Message, state: FSMContext) -> None:
|
|||||||
|
|
||||||
@router.message(RegistrationForm.age, F.text)
|
@router.message(RegistrationForm.age, F.text)
|
||||||
async def age_handler(message: Message, state: FSMContext) -> None:
|
async def age_handler(message: Message, state: FSMContext) -> None:
|
||||||
|
if message.text is None:
|
||||||
|
return
|
||||||
|
|
||||||
age = message.text.strip()
|
age = message.text.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -88,6 +93,9 @@ async def age_handler(message: Message, state: FSMContext) -> None:
|
|||||||
|
|
||||||
@router.message(RegistrationForm.sex, F.text)
|
@router.message(RegistrationForm.sex, F.text)
|
||||||
async def sex_handler(message: Message, state: FSMContext) -> None:
|
async def sex_handler(message: Message, state: FSMContext) -> None:
|
||||||
|
if message.text is None:
|
||||||
|
return
|
||||||
|
|
||||||
sex = message.text.strip().lower()
|
sex = message.text.strip().lower()
|
||||||
|
|
||||||
if sex not in ["male", "female"]:
|
if sex not in ["male", "female"]:
|
||||||
@@ -106,6 +114,9 @@ async def sex_handler(message: Message, state: FSMContext) -> None:
|
|||||||
|
|
||||||
@router.message(RegistrationForm.bio, F.text)
|
@router.message(RegistrationForm.bio, F.text)
|
||||||
async def bio_handler(message: Message, state: FSMContext) -> None:
|
async def bio_handler(message: Message, state: FSMContext) -> None:
|
||||||
|
if message.text is None:
|
||||||
|
return
|
||||||
|
|
||||||
bio = message.text.strip()
|
bio = message.text.strip()
|
||||||
|
|
||||||
if bio == "/skip":
|
if bio == "/skip":
|
||||||
@@ -132,6 +143,9 @@ async def bio_handler(message: Message, state: FSMContext) -> None:
|
|||||||
|
|
||||||
@router.message(RegistrationForm.location, F.text)
|
@router.message(RegistrationForm.location, F.text)
|
||||||
async def location_handler(message: Message, state: FSMContext) -> None:
|
async def location_handler(message: Message, state: FSMContext) -> None:
|
||||||
|
if message.text is None or message.from_user is None:
|
||||||
|
return
|
||||||
|
|
||||||
location = message.text.strip().split(", ")
|
location = message.text.strip().split(", ")
|
||||||
|
|
||||||
if len(location) != 2:
|
if len(location) != 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user