Skip to content

feat: add configurable user requirements for community creation#840

Closed
Matobi98 wants to merge 3 commits into
lnp2pBot:mainfrom
Matobi98:feat/community-creation-requirements
Closed

feat: add configurable user requirements for community creation#840
Matobi98 wants to merge 3 commits into
lnp2pBot:mainfrom
Matobi98:feat/community-creation-requirements

Conversation

@Matobi98

@Matobi98 Matobi98 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add environment-based minimum requirements to the /community command so only users who meet configurable thresholds can create a community
  • If any requirement is not met, the bot replies with a short error message and exits — no scene is entered
  • If an env var is not set, that restriction is simply not applied

Changes

  • bot/modules/community/index.ts — validation logic before entering COMMUNITY_WIZARD_SCENE_ID
  • .env-sample — four new commented-out variables with suggested default values
  • locales/*.yaml — added community_creation_requirements_not_met key in all 10 supported languages

New env vars

Variable Description
COMMUNITY_CREATION_MIN_ORDERS Minimum completed orders
COMMUNITY_CREATION_MIN_VOLUME Minimum sats traded
COMMUNITY_CREATION_MIN_DAYS_USING_BOT Minimum days since first use
COMMUNITY_CREATION_MIN_REPUTATION Minimum reputation score

All four are optional. Unset = no restriction for that field.

Suggested production values

COMMUNITY_CREATION_MIN_ORDERS=100
COMMUNITY_CREATION_MIN_VOLUME=10000000
COMMUNITY_CREATION_MIN_DAYS_USING_BOT=365
COMMUNITY_CREATION_MIN_REPUTATION=4.8


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
* Community creation now enforces configurable minimum requirements based on orders, traded volume, account age, and reputation.
* When users don’t meet the criteria, community creation is blocked with a clear explanation.

* **Configuration**
* Added documented (commented) environment keys for minimum requirements, designed to be left unset to disable each restriction.

* **Localization**
* Added a new “requirements not met” message to multiple languages.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a6b55ea2-286e-45c4-8332-e806faec4057

📥 Commits

Reviewing files that changed from the base of the PR and between c6177e9 and d3d604e.

📒 Files selected for processing (1)
  • bot/modules/community/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • bot/modules/community/index.ts

Walkthrough

Adds 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 community_creation_requirements_not_met message, which is localized across all 10 supported languages.

Changes

Community Creation Requirements Gate

Layer / File(s) Summary
Env configuration for creation thresholds
.env-sample
Adds four commented env keys (COMMUNITY_CREATION_MIN_ORDERS, COMMUNITY_CREATION_MIN_VOLUME, COMMUNITY_CREATION_MIN_DAYS_USING_BOT, COMMUNITY_CREATION_MIN_REPUTATION) that define optional minimum thresholds for community creation; leaving them unset disables the restriction.
Community command handler enforcement logic
bot/modules/community/index.ts
Imports logger and inserts a requirements gate: parses the four env thresholds, computes daysUsing from user.created_at, and early-returns with the new error message if any criterion is not met, logging the user's stats on failure.
Localization strings across all languages
locales/en.yaml, locales/es.yaml, locales/de.yaml, locales/fr.yaml, locales/it.yaml, locales/pt.yaml, locales/ru.yaml, locales/uk.yaml, locales/ko.yaml, locales/fa.yaml
Adds the community_creation_requirements_not_met key to all 10 supported locale files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • lnp2pBot/bot#811: Both PRs modify the same community creation feature gate via COMMUNITY_CREATION_ENABLED in .env-sample and bot/modules/community/index.ts.

Suggested reviewers

  • Luquitasjeffrey
  • ermeme
  • grunch
  • mostronatorcoder

Poem

🐇 Hop, hop, before you build a town,
The rabbit checks your orders renown.
Min volume, min days, reputation too —
Only worthy traders make it through!
No shortcut past the warren's gate,
Meet the threshold, then create! 🏡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding configurable user requirements for community creation. It is concise, specific, and clearly reflects the primary objective of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82d66d0 and f751f8c.

📒 Files selected for processing (12)
  • .env-sample
  • bot/modules/community/index.ts
  • locales/de.yaml
  • locales/en.yaml
  • locales/es.yaml
  • locales/fa.yaml
  • locales/fr.yaml
  • locales/it.yaml
  • locales/ko.yaml
  • locales/pt.yaml
  • locales/ru.yaml
  • locales/uk.yaml

Comment thread bot/modules/community/index.ts Outdated

@ermeme ermeme Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Request Changes

Blocking

  • bot/modules/community/index.ts accepts negative values for the new threshold env vars. For minimum requirements, a typo like -1 makes the guard trivially pass and silently weakens the protection. Please reject negative values (and ideally enforce integer values for orders/days).

Comment thread bot/modules/community/index.ts Outdated
const parseOptionalNumber = (raw: string | undefined): number | null => {
if (raw == null || raw.trim() === '') return null;
const n = Number(raw);
return Number.isFinite(n) ? n : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ermeme ermeme Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Request Changes

Blocking

  • bot/modules/community/index.ts still accepts negative values for the new community-creation thresholds. For minimum requirements, a config typo like -1 silently 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Luquitasjeffrey

Copy link
Copy Markdown
Collaborator

Continued on #841

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.

2 participants