-
Notifications
You must be signed in to change notification settings - Fork 1
Automate (former) champion badges #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -490,7 +490,7 @@ async def update_homepage_cache() -> None: | |||||||||||||||
| SELECT COUNT(*) AS cnt | ||||||||||||||||
| FROM users | ||||||||||||||||
| WHERE privileges & 1 | ||||||||||||||||
| """ | ||||||||||||||||
| """, | ||||||||||||||||
| ) | ||||||||||||||||
| await redis.set("akatsuki:registered_users", str(user_count["cnt"])) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -499,7 +499,7 @@ async def update_homepage_cache() -> None: | |||||||||||||||
| SELECT COUNT(*) AS cnt | ||||||||||||||||
| FROM beatmaps | ||||||||||||||||
| WHERE ranked IN (2, 3) | ||||||||||||||||
| """ | ||||||||||||||||
| """, | ||||||||||||||||
| ) | ||||||||||||||||
| await redis.set("akatsuki:ranked_beatmaps", str(beatmap_count["cnt"])) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -509,7 +509,7 @@ async def update_homepage_cache() -> None: | |||||||||||||||
| FROM user_stats | ||||||||||||||||
| INNER JOIN users ON users.id = user_stats.user_id | ||||||||||||||||
| WHERE users.privileges & 1 | ||||||||||||||||
| """ | ||||||||||||||||
| """, | ||||||||||||||||
| ) | ||||||||||||||||
| years = int(playtime["total_playtime"]) // (60 * 60 * 24 * 365) | ||||||||||||||||
| await redis.set("akatsuki:total_playtime_years", str(years)) | ||||||||||||||||
|
|
@@ -531,6 +531,79 @@ async def update_homepage_cache() -> None: | |||||||||||||||
| print(f"Updated homepage cache in {time.time() - start_time:.2f} seconds") | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| CHAMPION_BADGE_ID = 67 | ||||||||||||||||
| FORMER_CHAMPION_BADGE_ID = 66 | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| async def update_champion_badges() -> None: | ||||||||||||||||
| for rx in (0, 1, 2): | ||||||||||||||||
| if rx == 0: | ||||||||||||||||
| redis_board = "leaderboard" | ||||||||||||||||
| modes = ("std", "taiko", "ctb", "mania") | ||||||||||||||||
| elif rx == 1: | ||||||||||||||||
| redis_board = "relaxboard" | ||||||||||||||||
| modes = ("std", "taiko", "ctb") | ||||||||||||||||
| else: # rx == 2: | ||||||||||||||||
| redis_board = "autoboard" | ||||||||||||||||
| modes = ("std",) | ||||||||||||||||
|
|
||||||||||||||||
| for mode in modes: | ||||||||||||||||
| mode_int = mode + (4 * rx) | ||||||||||||||||
| rank_key = f"ripple:{redis_board}:{mode}" | ||||||||||||||||
|
|
||||||||||||||||
| # this is updated in a cron so we need to also check current rank one | ||||||||||||||||
| users_who_peaked_at_rank_one = list( | ||||||||||||||||
|
cmyui marked this conversation as resolved.
|
||||||||||||||||
| await db.fetchall( | ||||||||||||||||
| "SELECT DISTINCT user_id FROM user_profile_history WHERE mode = %s AND `rank` = 1", | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check how many users are going to receive a badge that don't currently have it, from the switch from
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a bit to consider here re. cases where someone cheated their way to #1 then got banned/unbanned -- I think this system would grant them the "former champion" badge in that case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if we're not wiping this table when wiping a user for an unban then that's an issue in it's own way - that would mean their peak rank on their profile would already appear as whatever they peaked while cheating 😳 |
||||||||||||||||
| [mode_int], | ||||||||||||||||
| ), | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| current_rank_one_user_id = await redis.zrevrange(rank_key, 0, 0) | ||||||||||||||||
| users_who_peaked_at_rank_one.append({"user_id": current_rank_one_user_id}) | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this fetched separately to guard against the case where the #1 is not yet inserted into
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the API endpoint that the website uses to fetch peak rank does similar functionality (fetches peak from database and also current, takes whichever is lower)
Comment on lines
+562
to
+563
|
||||||||||||||||
| current_rank_one_user_id = await redis.zrevrange(rank_key, 0, 0) | |
| users_who_peaked_at_rank_one.append({"user_id": current_rank_one_user_id}) | |
| current_rank_one_users = await redis.zrevrange(rank_key, 0, 0) | |
| if current_rank_one_users: | |
| users_who_peaked_at_rank_one.append({"user_id": current_rank_one_users[0]}) |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid SQL syntax using bracket notation instead of VALUES clause, and parameters should be passed as a separate argument to db.execute(). The correct format should be: "INSERT INTO user_badges (user, badge) VALUES (%s, %s)", [user["user_id"], CHAMPION_BADGE_ID] where the SQL query and parameters are separate arguments to db.execute().
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid SQL syntax using bracket notation instead of VALUES clause, and parameters should be passed as a separate argument to db.execute(). The correct format should be: "INSERT INTO user_badges (user, badge) VALUES (%s, %s)", [user["user_id"], FORMER_CHAMPION_BADGE_ID] where the SQL query and parameters are separate arguments to db.execute().
| "INSERT INTO user_badges (user, badge) (%s, %s)"[ | |
| user["user_id"], FORMER_CHAMPION_BADGE_ID, | |
| ], | |
| ) | |
| "INSERT INTO user_badges (user, badge) VALUES (%s, %s)", | |
| [user["user_id"], FORMER_CHAMPION_BADGE_ID], | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type error: attempting to concatenate string and integer. The variable
modeis a string (e.g., "std", "taiko", "ctb", "mania") but the code attempts to add it to an integer. Based on line 100 in the codebase, this should bemode_int = STR_TO_INT_MODE[mode] + (4 * rx)to correctly calculate the mode integer value.