From ecfc83d5adc88d408fe425b5c13720a3ea0a289f Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Fri, 29 Aug 2025 16:03:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=91=D0=94=20=D0=BB=D0=B5=D0=B2?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9,=20=D0=BA=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B=D0=B5=20VK=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BD=D1=83=D1=82=D1=8C=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BA=D0=B5=20profiles.=20=D0=9F=D1=80=D0=B8?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D1=81=D1=8B=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20daily=5Fmaintenance=5Ftask=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=BB=D0=B6=D0=B0=D0=B5=D1=82=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks.py | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tasks.py b/tasks.py index a5f09ae..74cc6b3 100644 --- a/tasks.py +++ b/tasks.py @@ -1,4 +1,5 @@ import datetime +import traceback from asyncio import sleep from vkbottle import API @@ -26,24 +27,29 @@ async def check_birthdays(api: API): members = await api.messages.get_conversation_members(peer_id=chat_id, extended=False, fields=['bdate']) today = datetime.datetime.today() - for member in members.profiles: - if member.id < 0 or member.bdate is None: + for item in members.items: + user_id = item.member_id + if user_id < 0: continue + user = database.create_user_if_not_exists(chat_id, user_id) - user = database.create_user_if_not_exists(chat_id, member.id) - if user['happy_birthday'] == 0: - continue + for profile in members.profiles: + if profile.id == user_id: + if profile.bdate is None or user['happy_birthday'] == 0: + break - parts = member.bdate.split('.') - if len(parts) < 2: - continue - day = int(parts[0]) - month = int(parts[1]) + parts = profile.bdate.split('.') + if len(parts) < 2: + break + day = int(parts[0]) + month = int(parts[1]) - if day == today.day and month == today.month: - message = chat['birthday_message'] or MESSAGE_DEFAULT_BIRTHDAY - message = message.format(name=f'@id{member.id} ({member.first_name} {member.last_name})') - await api.messages.send(random_id=0, peer_id=chat_id, message=message) + if day == today.day and month == today.month: + message = chat['birthday_message'] or MESSAGE_DEFAULT_BIRTHDAY + message = message.format(name=f'@id{user_id} ({profile.first_name} {profile.last_name})') + await api.messages.send(random_id=0, peer_id=chat_id, message=message) + + break async def wait_until(target_time: datetime.datetime): @@ -69,8 +75,11 @@ async def daily_maintenance_task(api: API): while True: await wait_until(target_datetime) - reset_counters(target_datetime.day == 1) - await check_birthdays(api) + try: + reset_counters(target_datetime.day == 1) + await check_birthdays(api) + except Exception: + print(traceback.format_exc()) target_datetime = target_datetime + datetime.timedelta(days=1)