Исправлено получение списка молчунов.
This commit is contained in:
parent
3ca84006f9
commit
482bb086bb
2 changed files with 15 additions and 12 deletions
25
database.py
25
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("""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue