Init project
This commit is contained in:
25
birthday_pool_bot/telegram_bot/ui/utils.py
Normal file
25
birthday_pool_bot/telegram_bot/ui/utils.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from aiogram import types
|
||||
from aiogram.types import User as TelegramUser
|
||||
|
||||
|
||||
BIRTHDATE_REGEXP = re.compile("^(?P<day>\d{2})\.(?P<month>\d{2})\.(?P<year>\d{4})$")
|
||||
|
||||
|
||||
def parse_date(message: types.Message) -> datetime.date:
|
||||
if (re_match := BIRTHDATE_REGEXP.match(message.text)) is None:
|
||||
return
|
||||
|
||||
return datetime.date(
|
||||
year=int(re_match.group("year")),
|
||||
month=int(re_match.group("month")),
|
||||
day=int(re_match.group("day")),
|
||||
)
|
||||
|
||||
|
||||
def get_telegram_user_full_name(user: TelegramUser) -> str:
|
||||
name_parts = (user.first_name, user.last_name)
|
||||
return " ".join(filter(None, name_parts))
|
||||
|
||||
Reference in New Issue
Block a user