This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rewrite' of https://github.com/RealistikDash/GDPyS into…
… rewrite
- Loading branch information
Showing
9 changed files
with
56 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
from conn.mysql import myconn | ||
from helpers.userhelper import user_helper | ||
|
||
# Lists of user objects in order of stars | ||
top_stars = [] | ||
top_cp = [] | ||
|
||
|
||
async def get_list(order: str = "stars") -> list: | ||
async def get_list(conn, order: str = "stars") -> list: | ||
"""Gets list of users ordered desc by arg.""" | ||
async with myconn.conn.cursor() as mycursor: | ||
async with conn.cursor() as mycursor: | ||
await mycursor.execute( | ||
f"SELECT extID FROM users WHERE isBanned = 0 ORDER BY {order} DESC LIMIT 100" | ||
) # TODO: isBanned alternative | ||
list_id = await mycursor.fetchall() | ||
return [i[0] for i in list_id] | ||
|
||
|
||
async def cron_top_stars(): | ||
async def cron_top_stars(conn): | ||
"""Caches top 100 leaderboards.""" | ||
top_stars.clear() | ||
# We have to cache all the user objects. | ||
for account_id in await get_list("stars"): | ||
for account_id in await get_list(conn, "stars"): | ||
top_stars.append( | ||
await user_helper.get_object(account_id) | ||
) # Honestly I have no clue how to not store the objects separately twice plus this helps when adding features like lb freezing. | ||
|
||
|
||
async def cron_top_cp(): | ||
async def cron_top_cp(conn): | ||
"""Caches top cp leaderboards.""" | ||
top_cp.clear() | ||
# We have to cache all the user objects. | ||
for account_id in await get_list("creatorPoints"): | ||
for account_id in await get_list(conn, "creatorPoints"): | ||
top_cp.append( | ||
await user_helper.get_object(account_id) | ||
) # Honestly I have no clue how to not store the objects separately twice plus this helps when adding features like lb freezing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
from conn.mysql import myconn | ||
from constants import Permissions | ||
|
||
ranks = {} # For now I will store it here. | ||
|
||
|
||
async def cron_calc_ranks() -> None: | ||
async def cron_calc_ranks(conn) -> None: | ||
"""Calculates all ranks for users and stores them in cache.""" # I may move this to a cron category however that does not currently exist. | ||
async with myconn.conn.cursor() as mycursor: | ||
async with conn.cursor() as mycursor: | ||
await mycursor.execute( | ||
"SELECT extID FROM users WHERE extID IN (SELECT accountID FROM accounts WHERE privileges & %s AND isBot = 0) ORDER BY stars DESC", | ||
(Permissions.AUTH,), | ||
) | ||
users = await mycursor.fetchall() | ||
|
||
curr_rank = ( | ||
0 # There is most likely a better way to do this but I don't know it yet | ||
) | ||
for user in users: | ||
curr_rank += 1 | ||
ranks[int(user[0])] = curr_rank | ||
for rank, user in enumerate(users): | ||
# Add 1 to rank as lists are 0 indexed. | ||
ranks[int(user[0])] = rank + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters