Skip to content

feat(levels): add levels leaderboard#406

Merged
ReenigneArcher merged 7 commits intomasterfrom
feat/levels/add-levels-leaderboard
Feb 15, 2026
Merged

feat(levels): add levels leaderboard#406
ReenigneArcher merged 7 commits intomasterfrom
feat/levels/add-levels-leaderboard

Conversation

@ReenigneArcher
Copy link
Member

@ReenigneArcher ReenigneArcher commented May 19, 2025

Description

This PR changes the following:

  • Adds levels/ranking system for both discord and reddit
  • Migrates existing levels from mee6 for discord
  • For discord xp between 15 and 25 will awarded for each minute that a user is messaging
  • For reddit xp between 150 and 250 will be awarded for every minute that a user creates or comments on a submission
  • Adds a rank slash command
  • Adds a leaderboard slash command

TODO:

  • Discord leaderboard slash command to support reddit users
  • Specify channel to send Discord level up message to
  • Determine if new slash commands should be added to reddit (reddit cogs?)
  • Use new Database.query wherever tinydb.Query is used
  • Possibly, allow paging through leaderboard
  • Record new betamax cassettes/fixtures
  • Unit testing and coverage

Screenshot

image

image

Issues Fixed or Closed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@codecov
Copy link

codecov bot commented May 19, 2025

Codecov Report

❌ Patch coverage is 56.88073% with 282 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.51%. Comparing base (48071cc) to head (5847d69).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/discord_bot/cogs/rank.py 27.35% 154 Missing ⚠️
src/common/rank.py 54.07% 107 Missing ⚠️
src/reddit_bot/bot.py 74.64% 18 Missing ⚠️
src/common/rank_database.py 96.77% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #406      +/-   ##
==========================================
- Coverage   60.30%   59.51%   -0.80%     
==========================================
  Files          21       24       +3     
  Lines        1164     1761     +597     
==========================================
+ Hits          702     1048     +346     
- Misses        462      713     +251     
Files with missing lines Coverage Δ
src/common/database.py 59.11% <100.00%> (+18.52%) ⬆️
src/common/webapp.py 96.85% <100.00%> (-0.03%) ⬇️
src/common/rank_database.py 96.77% <96.77%> (ø)
src/reddit_bot/bot.py 69.46% <74.64%> (-0.03%) ⬇️
src/common/rank.py 54.07% <54.07%> (ø)
src/discord_bot/cogs/rank.py 27.35% <27.35%> (ø)

... and 1 file with indirect coverage changes

@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch 25 times, most recently from 8780c06 to 984396a Compare May 23, 2025 20:33
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from 984396a to 8942723 Compare July 2, 2025 01:31
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from 8942723 to 3bc5088 Compare July 16, 2025 13:59
@LizardByte-bot

This comment was marked as resolved.

@LizardByte-bot LizardByte-bot added the stale This issue is stale. label Oct 15, 2025
@ReenigneArcher ReenigneArcher removed the stale This issue is stale. label Oct 15, 2025
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from 3bc5088 to cafdc7e Compare October 15, 2025 12:39
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from cafdc7e to 9642ccc Compare January 20, 2026 02:03
@LizardByte LizardByte deleted a comment from sonarqubecloud bot Jan 20, 2026
@LizardByte LizardByte deleted a comment from sonarqubecloud bot Jan 20, 2026
@LizardByte LizardByte deleted a comment from sonarqubecloud bot Jan 20, 2026
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from 9642ccc to d8827de Compare February 15, 2026 01:41
Use `with self.db as db` and get table handles via `db.table(...)`; introduce `q = self.db.query()` for queries. Move `comment_data` construction to the correct scope, update comments via `comments_table.update(...)`, and preserve existing `bot_discord` when updating submissions. For submissions, perform update-and-return inside the DB context, and build/insert new `submission_data` (with default `bot_discord`) afterward. Overall tidies DB access and fixes update/insert logic for comments and submissions.
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from d8827de to 34df460 Compare February 15, 2026 01:57
Add support for sending level-up messages to a designated Discord channel and introduce comprehensive unit tests. README and sample.env: document and expose DISCORD_LEVEL_UP_CHANNEL_ID. src/discord_bot/cogs/rank.py: import os and implement sending a Level Up embed to the channel defined by DISCORD_LEVEL_UP_CHANNEL_ID (if present), with error handling. tests/unit/common: add test_rank.py and test_rank_database.py to cover RankSystem and RankDatabase behaviors (XP awarding, cooldowns, level calculations, leaderboards, migrations, multi-community handling) using temporary DBs and mocks.
Enhance Rank tests to reliably clean up DB file handles and correct test expectations. Added gc and time imports and explicit tinydb.close()/gc.collect()/sleep to release file locks (esp. on Windows). Adjusted RankDatabase patching to return a real instance for temp DB usage and reformatted env_patch creation. Updated Reddit-related tests to patch globals.REDDIT_BOT and assert community_id from the mock subreddit. Corrected calculate_level/calculate_xp_for_level expectations to match the level = floor(sqrt(xp/100)) and xp = level^2 * 100 formulas. Also improved table existence checks by accessing tables and verifying they are empty.
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from 3289ad9 to ffb7abe Compare February 15, 2026 03:07
Add comprehensive unit tests for Database.sync covering git-related scenarios. Tests include: git enabled with no changes, git enabled with changes (commit & push), handling multiple JSON files, push failures, general git exceptions, behavior when GIT_ENABLED flag is false, no JSON files to add, changes cleared after git add, correct push URL construction with credentials, and ensuring _configure_repo is invoked. Tests use mocking for the repo, os.listdir, and the GIT_ENABLED flag to avoid performing real git operations.
@ReenigneArcher ReenigneArcher force-pushed the feat/levels/add-levels-leaderboard branch from ffb7abe to 36d296e Compare February 15, 2026 03:11
@ReenigneArcher ReenigneArcher marked this pull request as ready for review February 15, 2026 03:21
Update the migration-status print to explicitly mention Mee6 when skipping already-completed migrations. This provides clearer context in logs for why a guild's migration was skipped.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 New issues
2 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@ReenigneArcher ReenigneArcher merged commit d56d2ad into master Feb 15, 2026
15 of 17 checks passed
@ReenigneArcher ReenigneArcher deleted the feat/levels/add-levels-leaderboard branch February 15, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support-bot: migrate mee6 functionality Migrate mee6 functionality

2 participants