Core user data and leaderboard commands.

Added flexibility to data `update_where`.
Added interactive utils, with improved pager.
Added user data table, with caching and transactional interface.
Added `topcoins` command to `Economy`
Added `top` command to `Study`
This commit is contained in:
2021-08-26 22:34:46 +03:00
parent 05cb9650ee
commit 459a728968
18 changed files with 899 additions and 13 deletions

31
bot/core/tables.py Normal file
View File

@@ -0,0 +1,31 @@
from psycopg2.extras import execute_values
from cachetools import TTLCache
from data import RowTable, Table
users = RowTable(
'lions',
('userid', 'tracked_time', 'coins'),
'userid',
cache=TTLCache(5000, ttl=60*5)
)
@users.save_query
def add_coins(userid_coins):
with users.conn:
cursor = users.conn.cursor()
data = execute_values(
cursor,
"""
UPDATE lions
SET coins = coins + t.diff
FROM (VALUES %s) AS t (userid, diff)
WHERE lions.userid = t.userid
RETURNING *
""",
userid_coins,
fetch=True
)
return users._make_rows(*data)