Conversation
DEPENDENCY UPDATES: - @napi-rs/canvas => v0.1.41 - mongoose => v7.4.2 BUG FIXES: - xp.rank() error - xp.chart() now has a helpful err message - leaderboard() Position & Cache issues TYPE IMPROVEMENTS: - addLevel() => Make Code Prettier - addXP() => Make Code Prettier - charts() => Make Code Prettier - leaderboard() => Ensured limit was optional for TypeScript users - rank() => Cure Cancer (Remove Unnecessary Statements) UPDATES: - Added eslint (dev) - rank() => Moved Funcs (eslint compliant) - connect() => "auto_purge" option, basically does what it did in Beta 7, but you have a choice (false by default)
⭐ Improvements - Refactor leaderboard and rank position calculation into a new utility for efficiency and code reuse. - Add a compound index to the level model for improved leaderboard query performance. - Improve leaderboard auto-purge logic and cleaned up code style. - Refactor `rank()` image to scale background images properly, fixing stretching issues. 💎 Design Changes - Replace `Baloo-Regular.ttf` to `Baloo2-Regular.woff2` for better performance and smaller size. ⬆️ Dependencies - Bump `@napi-rs/canvas` from `v0.1.43` to `v0.1.88`.
Extracted level up notification and XP shortener functions into separate utility modules for better code reuse and maintainability. Updated addLevel, setLevel, fetch, leaderboard, and rank modules to use these utilities. Also simplified ESLint config file patterns and bumped package version to 1.3.8-fix.0.
Extracted the repeated level payload construction logic from addLevel.js and setLevel.js into a new utility function, buildLevelPayload, in src/utils/levelPayload.js. This improves code reuse and maintainability.
Codacy's Analysis Summary100 new issues (≤ 0 medium issue) Review Pull Request in Codacy →
|
Improved leaderboard logic for robustness and variable clarity. Added JSDoc comments to utility functions for better documentation. Minor cleanup in addLevel and setLevel by removing unused variables. Updated README with new badges and improved formatting.
Improves leaderboard entry handling by cloning objects before destructuring, enhancing data safety. Refactors shortener to handle non-numeric input and index bounds more robustly. Updates README for improved clarity and formatting.
Updated leaderboard position calculation to use entryIndex for accuracy and refactored the loop to use for...of. Improved shortener function by safely handling suffix assignment. Also standardized formatting and type definitions in index.d.ts for consistency.
|
I give up trying to please codacy, there isn't a way to do it rn without creating really silly looking code, even with copilot's assistance |
There was a problem hiding this comment.
Pull request overview
This PR appears to modernize the codebase (“Merge LTS to Latest”) by refactoring shared XP/leveling utilities, adjusting leaderboard/rank computation, and updating project metadata/tooling.
Changes:
- Added shared utility modules (short number formatting, level-up notification, leaderboard position lookup).
- Refactored rank/leaderboard/fetch logic to use shared helpers and added a DB index for guild XP sorting.
- Updated package metadata (deps, eslint config, docs/readme, ignore files) and introduced a module-level
optionsconfig.
Reviewed changes
Copilot reviewed 25 out of 29 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/shortener.js | New shared number-shortening helper. |
| src/utils/levelUpNotifier.js | New helper to emit levelUp with resolved role config. |
| src/utils/levelPayload.js | New helper to standardize levelUp payload shape. |
| src/utils/getUserPosition.js | New cursor-based helper to compute leaderboard position without loading whole list. |
| src/setXP.js | Refactors XP set logic to use findOneAndUpdate. |
| src/setLevel.js | Refactors level set logic and extracts notification/payload creation. |
| src/roleSetup.js | Formatting/string consistency updates. |
| src/reset.js | Formatting update of errors and query call. |
| src/rank.js | Uses shared shortener + position helper; rank card rendering refactor. |
| src/models/lvlrole.js | Formatting/string consistency updates. |
| src/models/level.js | Adds { guild, xp } index; formatting updates. |
| src/lvlRole.js | Formatting/string consistency updates. |
| src/leaderboard.js | Reworks leaderboard construction and adds optional auto-purge behavior. |
| src/fetch.js | Uses shared shortener + position helper. |
| src/create.js | Formatting update of errors and DB insert behavior. |
| src/connect.js | Formatting changes and modifies notify behavior. |
| src/charts.js | Switches to @napi-rs/canvas usage and formatting updates. |
| src/addXP.js | Formatting/string consistency updates. |
| src/addLevel.js | Uses new payload/notifier helper instead of inline emission logic. |
| src/Fonts/Baloo2-Regular.woff2 | Adds new font asset used by rank card. |
| simplyxp.js | Adds exported options object and standardizes require/export formatting. |
| package.json | Updates version/metadata, dependencies, scripts, keywords, and repo links. |
| index.d.ts | Reformats typings and adjusts some option types. |
| eslint.config.cjs | Adds ESLint flat config (replaces .eslintrc.json). |
| README.md | Updates badges, copy, and formatting. |
| .npmignore | Expands ignored files for publishing. |
| .gitignore | Updates ignored files (pnpm lock/workspace). |
| .eslintrc.json | Removes legacy ESLint config. |
Comments suppressed due to low confidence (1)
src/models/level.js:6
- The schema marks
useras globallyunique, but all queries in this package are keyed by{ user, guild }. This uniqueness constraint will prevent the same user from having XP in multiple guilds. Consider removingunique: trueonuserand adding a compound unique index on{ user: 1, guild: 1 }instead.
const Levelz = new mongoose.Schema({
user: { type: String, unique: true },
guild: { type: String },
xp: { type: Number, default: 0 },
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Allow xp = 0 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove unnecessary const Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
Fix levelUp event emission logic in addLevel
Codacy's Analysis Summary100 new issues (≤ 0 medium issue) Review Pull Request in Codacy →
|
Fix setLevel to capture previous level before update
Fix type coercion in setLevel to prevent incorrect event emission
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 29 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async function notifyLevelUp(message, data, roleLevel) { | ||
| const role = await roleSetup.find(message.client, data.guildID, roleLevel); | ||
| message.client.emit("levelUp", message, data, role); | ||
| } |
There was a problem hiding this comment.
Indentation here uses spaces instead of tabs, which will fail the repo’s ESLint indent: ["error", "tab"] rule.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…n, member checks, and logging Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
Fix level emission, negative number handling, and member validation issues
|
@copilot your suggestions have been granted, plz approve review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 29 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
Co-authored-by: Abadima <39747270+Abadima@users.noreply.github.com>
[WIP] Merge LTS to latest code version
Codacy's Analysis Summary100 new issues (≤ 0 medium issue) Review Pull Request in Codacy →
|
No description provided.