txlyre před 2 roky
rodič
revize
5c976c585c
3 změnil soubory, kde provedl 16 přidání a 7 odebrání
  1. 6 1
      actions.py
  2. 4 5
      commands.py
  3. 6 1
      utils.py

+ 6 - 1
actions.py

@@ -133,10 +133,15 @@ async def get_birthdays(peer_id):
 async def add_or_update_birthday(peer_id, user, date):
   birthday = await BirthDay.filter(peer_id=peer_id, user_id=user.id).first()
 
+  if birthday:
+    await BirthDay.filter(id=birthday.id).update(date=date)
+ 
+    return False
+
   await BirthDay(
     peer_id=peer_id,
     user_id=user.id,
     date=date
   ).save()
 
-  return birthday is not None
+  return True

+ 4 - 5
commands.py

@@ -21,7 +21,7 @@ from actions import (
   add_or_update_birthday,
   get_birthdays
 )
-from utils import WORDS_TABLE,  make_temporary_filename, parse_kind, get_link_to_user, get_word_kind
+from utils import WORDS_TABLE, make_temporary_filename, parse_kind, get_user_name, get_word_kind
 
 class Handler:
   def __init__(self, handler, is_restricted=False):
@@ -244,13 +244,12 @@ async def bday_handler(bot, event, command):
     age = (birthday_date - birthday.date).days // 365
     age_now = age - 1
 
-    birthdays_list += '- '
-    birthdays_list += get_link_to_user(await bot.get_entity(birthday.user_id))
-    birthdays_list += ': '
+    birthdays_list += get_user_name(await bot.get_entity(birthday.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'
 
-  await event.reply(f'Дни рождения:\n{birthdays_list}')
+  await event.reply(f'Дни рождения:\n\n{birthdays_list}')
 
 COMMANDS = {
   'newadmin':  Handler(newadmin_handler,  is_restricted=True),

+ 6 - 1
utils.py

@@ -52,7 +52,7 @@ def parse_command(text):
     args_string=args_string
   )
 
-def get_link_to_user(user):
+def get_user_name(user):
   full_name = get_display_name(user)
   if not full_name:
     full_name = user.username
@@ -60,6 +60,11 @@ def get_link_to_user(user):
   if not full_name:
     full_name = '?'
 
+  return full_name
+
+def get_link_to_user(user):
+  full_name = get_user_name(user)
+
   if user.username:
     return f'[{full_name}](@{user.username})'