|
@@ -1,7 +1,6 @@
|
|
|
from sys import executable
|
|
|
from asyncio import create_subprocess_shell
|
|
|
from asyncio.subprocess import PIPE
|
|
|
-from datetime import datetime, timedelta
|
|
|
|
|
|
from ujson import dumps
|
|
|
from tortoise.exceptions import IntegrityError
|
|
@@ -21,7 +20,7 @@ from actions import (
|
|
|
add_or_update_birthday,
|
|
|
get_birthdays
|
|
|
)
|
|
|
-from utils import WORDS_TABLE, make_temporary_filename, parse_kind, get_user_name, get_word_kind
|
|
|
+from utils import WORDS_TABLE, make_temporary_filename, parse_kind, get_user_name, get_word_for, calculate_age
|
|
|
|
|
|
class Handler:
|
|
|
def __init__(self, handler, is_restricted=False):
|
|
@@ -231,28 +230,19 @@ async def bday_handler(bot, event, command):
|
|
|
|
|
|
birthdays = await get_birthdays(get_peer_id(event.peer_id))
|
|
|
if not birthdays:
|
|
|
- await event.reply('Пока пусто…')
|
|
|
+ await event.reply('Пока пусто...')
|
|
|
|
|
|
return
|
|
|
|
|
|
- birthdays = sorted(birthdays, key=lambda birthday: birthday.date)
|
|
|
+ birthdays = map(lambda birthday: (birthday.user_id, calculate_age(birthday.date)), birthdays)
|
|
|
+ birthdays = sorted(birthdays, key=lambda birthday: birthday[1].days_until)
|
|
|
|
|
|
birthdays_list = ''
|
|
|
- for birthday in birthdays:
|
|
|
- now = datetime.now().date()
|
|
|
- birthday_date = birthday.date.replace(year=now.year)
|
|
|
-
|
|
|
- if now > birthday_date:
|
|
|
- birthday_date = birthday.date.replace(year=now.year + 1)
|
|
|
-
|
|
|
- delta = birthday_date - now
|
|
|
- age = (birthday_date - birthday.date).days // 365
|
|
|
- age_now = age - 1
|
|
|
-
|
|
|
- birthdays_list += get_user_name(await bot.get_entity(birthday.user_id))
|
|
|
+ for user_id, age in birthdays:
|
|
|
+ birthdays_list += get_user_name(await bot.get_entity(user_id))
|
|
|
birthdays_list += ' — '
|
|
|
- birthdays_list += birthday.date.strftime('%d.%m.%Y')
|
|
|
- birthdays_list += f' (через {delta.days} {WORDS_TABLE["день"][get_word_kind(delta.days)]} исполнится {age} {WORDS_TABLE["год"][get_word_kind(age)]}; сейчас {age_now} {WORDS_TABLE["год"][get_word_kind(age_now)]})\n'
|
|
|
+ birthdays_list += age.date_string
|
|
|
+ birthdays_list += f' (через {get_word_for("день", age.days_until)} исполнится {get_word_for("год", age.age)}; сейчас {get_word_for("год", age.age_now)})\n'
|
|
|
|
|
|
await event.reply(f'Дни рождения:\n\n{birthdays_list}')
|
|
|
|