(leaderboards): Update to support sessions.
Use `member_totals` to generate leaderboards instead of `members`. Fix typo in data coin conversion.
This commit is contained in:
@@ -46,19 +46,15 @@ async def cmd_topcoin(ctx):
|
||||
exclude.update(ctx.client.objects['blacklisted_users'])
|
||||
exclude.update(ctx.client.objects['ignored_members'][ctx.guild.id])
|
||||
|
||||
args = {
|
||||
'guildid': ctx.guild.id,
|
||||
'select_columns': ('userid', 'total_coins::INTEGER'),
|
||||
'_extra': "AND total_coins > 0 ORDER BY total_coins DESC " + ("LIMIT 100" if top100 else "")
|
||||
}
|
||||
if exclude:
|
||||
user_data = tables.lions.select_where(
|
||||
guildid=ctx.guild.id,
|
||||
userid=data.NOT(list(exclude)),
|
||||
select_columns=('userid', 'coins'),
|
||||
_extra="AND coins > 0 ORDER BY coins DESC " + ("LIMIT 100" if top100 else "")
|
||||
)
|
||||
else:
|
||||
user_data = tables.lions.select_where(
|
||||
guildid=ctx.guild.id,
|
||||
select_columns=('userid', 'coins'),
|
||||
_extra="AND coins > 0 ORDER BY coins DESC " + ("LIMIT 100" if top100 else "")
|
||||
)
|
||||
args['userid'] = data.NOT(list(exclude))
|
||||
|
||||
user_data = tables.members_totals.select_where(**args)
|
||||
|
||||
# Quit early if the leaderboard is empty
|
||||
if not user_data:
|
||||
|
||||
@@ -38,27 +38,20 @@ async def cmd_top(ctx):
|
||||
)
|
||||
top100 = (ctx.args == "100" or ctx.alias == "top100")
|
||||
|
||||
# Flush any pending coin transactions
|
||||
Lion.sync()
|
||||
|
||||
# Fetch the leaderboard
|
||||
exclude = set(m.id for m in ctx.guild_settings.unranked_roles.members)
|
||||
exclude.update(ctx.client.objects['blacklisted_users'])
|
||||
exclude.update(ctx.client.objects['ignored_members'][ctx.guild.id])
|
||||
|
||||
args = {
|
||||
'guildid': ctx.guild.id,
|
||||
'select_columns': ('userid', 'total_tracked_time::INTEGER'),
|
||||
'_extra': "AND total_tracked_time > 0 ORDER BY total_tracked_time DESC " + ("LIMIT 100" if top100 else "")
|
||||
}
|
||||
if exclude:
|
||||
user_data = tables.lions.select_where(
|
||||
guildid=ctx.guild.id,
|
||||
userid=data.NOT(list(exclude)),
|
||||
select_columns=('userid', 'tracked_time'),
|
||||
_extra="AND tracked_time > 0 ORDER BY tracked_time DESC " + ("LIMIT 100" if top100 else "")
|
||||
)
|
||||
else:
|
||||
user_data = tables.lions.select_where(
|
||||
guildid=ctx.guild.id,
|
||||
select_columns=('userid', 'tracked_time'),
|
||||
_extra="AND tracked_time > 0 ORDER BY tracked_time DESC " + ("LIMIT 100" if top100 else "")
|
||||
)
|
||||
args['userid'] = data.NOT(list(exclude))
|
||||
|
||||
user_data = tables.members_totals.select_where(**args)
|
||||
|
||||
# Quit early if the leaderboard is empty
|
||||
if not user_data:
|
||||
@@ -68,6 +61,7 @@ async def cmd_top(ctx):
|
||||
author_index = None
|
||||
entries = []
|
||||
for i, (userid, time) in enumerate(user_data):
|
||||
time = int(time)
|
||||
member = ctx.guild.get_member(userid)
|
||||
name = member.display_name if member else str(userid)
|
||||
name = name.replace('*', ' ').replace('_', ' ')
|
||||
|
||||
@@ -57,3 +57,6 @@ def study_time_since(guildid, userid, timestamp):
|
||||
cursor.callproc('study_time_since', (guildid, userid, timestamp))
|
||||
rows = cursor.fetchall()
|
||||
return (rows[0][0] if rows else None) or 0
|
||||
|
||||
|
||||
members_totals = Table('members_totals')
|
||||
|
||||
Reference in New Issue
Block a user