Исправлено получение списка молчунов.
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 typing import List, Union
|
||||||
|
|
||||||
|
from pyodbc import connect, SQL_CHAR, SQL_WCHAR, Row
|
||||||
|
|
||||||
|
|
||||||
class BasicDatabase:
|
class BasicDatabase:
|
||||||
def __init__(self, connection_string: str):
|
def __init__(self, connection_string: str):
|
||||||
|
|
@ -76,18 +78,19 @@ class BasicDatabase:
|
||||||
return self._to_dict(self.cursor.fetchall())
|
return self._to_dict(self.cursor.fetchall())
|
||||||
|
|
||||||
def get_top_silent(self, chat_id: int, threshold_days: int):
|
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("""
|
self.cursor.execute("""
|
||||||
SELECT user_id,
|
SELECT user_id, (? - last_message) DIV 86400 as value
|
||||||
CASE
|
|
||||||
WHEN last_message = 0 THEN 'никогда'
|
|
||||||
ELSE (unixepoch() - last_message) / 86400
|
|
||||||
END AS value
|
|
||||||
FROM users
|
FROM users
|
||||||
WHERE chat_id = ? AND value >= ?
|
WHERE chat_id = ? AND last_message <= ?
|
||||||
ORDER BY value DESC
|
ORDER BY last_message ASC
|
||||||
""", chat_id, threshold_days)
|
""", current_time, chat_id, threshold)
|
||||||
return self._to_dict(self.cursor.fetchall())
|
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):
|
def get_top_warnings(self, chat_id: int):
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ async def silent_handler(message: Message, bot: Bot):
|
||||||
await message.answer(MESSAGE_CHAT_NOT_ACTIVE)
|
await message.answer(MESSAGE_CHAT_NOT_ACTIVE)
|
||||||
return
|
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:
|
if len(top_users) == 0:
|
||||||
await message.answer('Молчунов нет. Все молодцы!')
|
await message.answer('Молчунов нет. Все молодцы!')
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue