feat: add configurable user requirements for community creation#840
feat: add configurable user requirements for community creation#840Matobi98 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds env-configurable minimum requirements (orders, volume, days using bot, reputation) for community creation. The community command handler now parses these thresholds and blocks users who do not meet them, logging the failure and replying with a new ChangesCommunity Creation Requirements Gate
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bot/modules/community/index.ts`:
- Around line 21-42: The parsing of environment variables using parseInt and
parseFloat for minOrders, minVolume, minDays, and minReputation returns NaN when
given invalid values, and the meetsRequirements logic treats NaN as "no
requirement," silently disabling that enforcement criterion instead of failing
loudly. Fix this by validating each parsed value immediately after parsing: if
the environment variable was provided (non-empty string) but parsing resulted in
NaN, throw an error to fail fast. This prevents invalid configurations from
silently weakening production policy.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0ef74189-c799-44ee-bc64-882e5e991056
📒 Files selected for processing (12)
.env-samplebot/modules/community/index.tslocales/de.yamllocales/en.yamllocales/es.yamllocales/fa.yamllocales/fr.yamllocales/it.yamllocales/ko.yamllocales/pt.yamllocales/ru.yamllocales/uk.yaml
There was a problem hiding this comment.
Code Review Summary
Verdict: Request Changes
Blocking
bot/modules/community/index.tsaccepts negative values for the new threshold env vars. For minimum requirements, a typo like-1makes the guard trivially pass and silently weakens the protection. Please reject negative values (and ideally enforce integer values for orders/days).
| const parseOptionalNumber = (raw: string | undefined): number | null => { | ||
| if (raw == null || raw.trim() === '') return null; | ||
| const n = Number(raw); | ||
| return Number.isFinite(n) ? n : null; |
There was a problem hiding this comment.
Reject negative threshold values here. Number.isFinite() still accepts -1, which turns a minimum requirement into a fail-open config typo for orders, volume, days, and reputation.
There was a problem hiding this comment.
Code Review Summary
Verdict: Request Changes
Blocking
bot/modules/community/index.tsstill accepts negative values for the new community-creation thresholds. For minimum requirements, a config typo like-1silently turns the protection into a no-op. Please reject negative values before evaluating the guard.
| const parseOptionalNumber = (raw: string | undefined): number | null => { | ||
| if (raw == null || raw.trim() === '') return null; | ||
| const n = Number(raw); | ||
| return Number.isFinite(n) && n >= 0 ? n : null; |
There was a problem hiding this comment.
Please reject negative threshold values here. Number.isFinite() is fine for float/int parsing, but it still allows -1, which makes a minimum requirement trivially satisfiable.
|
Continued on #841 |
Summary
/communitycommand so only users who meet configurable thresholds can create a communityChanges
bot/modules/community/index.ts— validation logic before enteringCOMMUNITY_WIZARD_SCENE_ID.env-sample— four new commented-out variables with suggested default valueslocales/*.yaml— addedcommunity_creation_requirements_not_metkey in all 10 supported languagesNew env vars
COMMUNITY_CREATION_MIN_ORDERSCOMMUNITY_CREATION_MIN_VOLUMECOMMUNITY_CREATION_MIN_DAYS_USING_BOTCOMMUNITY_CREATION_MIN_REPUTATIONAll four are optional. Unset = no restriction for that field.
Suggested production values