From 482bb086bb1b2abd8ced99c3bb0bdba37ed70506 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Wed, 21 Jan 2026 01:18:47 +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=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=87=D1=83=D0=BD=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 25 ++++++++++++++----------- tg/handlers/user.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/database.py b/database.py index c85ae2d..3177ba4 100644 --- a/database.py +++ b/database.py @@ -1,6 +1,8 @@ -from pyodbc import connect, SQL_CHAR, SQL_WCHAR, Row +from datetime import datetime from typing import List, Union +from pyodbc import connect, SQL_CHAR, SQL_WCHAR, Row + class BasicDatabase: def __init__(self, connection_string: str): @@ -76,18 +78,19 @@ class BasicDatabase: return self._to_dict(self.cursor.fetchall()) def get_top_silent(self, chat_id: int, threshold_days: int): - # noinspection SpellCheckingInspection + current_time = int(datetime.now().timestamp()) + threshold = current_time - threshold_days * 86400 self.cursor.execute(""" - SELECT user_id, - CASE - WHEN last_message = 0 THEN 'никогда' - ELSE (unixepoch() - last_message) / 86400 - END AS value + SELECT user_id, (? - last_message) DIV 86400 as value FROM users - WHERE chat_id = ? AND value >= ? - ORDER BY value DESC - """, chat_id, threshold_days) - return self._to_dict(self.cursor.fetchall()) + WHERE chat_id = ? AND last_message <= ? + ORDER BY last_message ASC + """, current_time, chat_id, threshold) + result = self._to_dict(self.cursor.fetchall()) + for row in result: + if row['value'] > 3650: + row['value'] = 'никогда' + return result def get_top_warnings(self, chat_id: int): self.cursor.execute(""" diff --git a/tg/handlers/user.py b/tg/handlers/user.py index eaf1ab7..14c12cc 100644 --- a/tg/handlers/user.py +++ b/tg/handlers/user.py @@ -158,7 +158,7 @@ async def silent_handler(message: Message, bot: Bot): await message.answer(MESSAGE_CHAT_NOT_ACTIVE) return - top_users = database.DB.get_top_messages_today(chat_id) + top_users = database.DB.get_top_silent(chat_id, 14) if len(top_users) == 0: await message.answer('Молчунов нет. Все молодцы!') return