Skip to content

Community creation env var#809

Closed
Matobi98 wants to merge 11 commits into
lnp2pBot:mainfrom
Matobi98:community-creation-env-var
Closed

Community creation env var#809
Matobi98 wants to merge 11 commits into
lnp2pBot:mainfrom
Matobi98:community-creation-env-var

Conversation

@Matobi98
Copy link
Copy Markdown
Contributor

@Matobi98 Matobi98 commented May 21, 2026

Summary

  • Introduces a COMMUNITY_CREATION_ENABLED environment variable (default: false) that controls whether the
    /community command is registered at bot startup
  • Replaces the commented-out /community command block in bot/modules/community/index.ts with a conditional
    registration guarded by the env var
  • Adds COMMUNITY_CREATION_ENABLED=false to .env-sample with an explanatory comment

Behavior

  • COMMUNITY_CREATION_ENABLED=false (default) — /community is not registered; community creation is disabled
  • COMMUNITY_CREATION_ENABLED=true/community is registered and users can create communities through the existing
    wizard flow

The wizard scene itself (COMMUNITY_WIZARD_SCENE_ID) is unchanged — it was already fully implemented.

Test plan

  • With COMMUNITY_CREATION_ENABLED unset or false, confirm /community returns no response / unknown command
  • With COMMUNITY_CREATION_ENABLED=true, confirm /community enters the community creation wizard correctly
    EOF

Summary by CodeRabbit

  • New Features

    • Added community enable/disable functionality for super administrators.
    • Community creation is now disabled by default (configurable via environment settings).
  • Documentation

    • Added localization strings for community enable/disable workflows across all supported languages (German, English, Spanish, French, Italian, Korean, Portuguese, Russian, and Ukrainian).
  • Chores

    • Extended community model to track enabled/disabled state.
    • Updated community lookups to exclude disabled communities from user-facing workflows.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@Matobi98 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 51 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f23c4cc9-b7e4-4013-ac9b-4e852e3ef751

📥 Commits

Reviewing files that changed from the base of the PR and between 00eced1 and 7d5327e.

📒 Files selected for processing (2)
  • bot/modules/community/commands.ts
  • util/communityHelper.ts

Walkthrough

This PR introduces community enable/disable state management. A new enabled boolean field is added to the Community model, and /disablecommunity and /enablecommunity admin commands are implemented with state guards, creator notifications, and comprehensive filtering. The /community creation command is gated behind a new environment flag. All Community lookups across the system are updated to exclude disabled communities.

Changes

Community Enable/Disable Feature

Layer / File(s) Summary
Community model and environment configuration
models/community.ts, .env-sample
ICommunity adds enabled: boolean field (default true). .env-sample introduces COMMUNITY_CREATION_ENABLED flag (default false) to control whether the /community command is registered.
Admin enable/disable command implementation
bot/modules/community/commands.ts
New disableCommunity and enableCommunity handlers use internal helpers to resolve communities by @groupUsername (case-insensitive regex) or object id, enforce state guards (prevent redundant transitions), toggle community.enabled, notify the creator via Telegram, and reply with localized community info text including solvers and creator username.
Command registration and community creation gating
bot/modules/community/index.ts
Imports superAdminMiddleware. Conditionally registers /community command only when COMMUNITY_CREATION_ENABLED === 'true'. Registers new /disablecommunity and /enablecommunity commands protected by superAdminMiddleware, delegating to commands.disableCommunity and commands.enableCommunity.
System-wide disabled community filtering
bot/modules/community/actions.ts, bot/modules/community/messages.ts, bot/modules/community/commands.ts, bot/modules/orders/scenes.ts, bot/modules/user/scenes/settings.ts, util/communityHelper.ts
All Community lookups updated to filter disabled communities using enabled: { $ne: false } in onCommunityInfo, withdrawEarnings, setComm, communityAdmin, myComms, updateCommunity, deleteCommunity, changeVisibility, updateCommunityMessage, earningsMessage, default community resolution, user settings, and helper utility. Disabled communities are now treated as not found throughout the system.
Localization strings for community state messages
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
New i18n keys added across all language files: community_disabled_info, community_enabled_info, community_disabled_by_admin, community_enabled_by_admin, community_already_disabled, community_already_enabled. Templates include placeholders for community name, group, solvers count, and creator username.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The change introduces a single, well-defined feature (community enable/disable) applied consistently across the codebase. Logic density is moderate: state guard logic in enable/disable commands, filtering pattern repeated across queries (homogeneous), and straightforward localization additions. No complex interdependencies or ambiguous behavior transitions. Reviewers should verify filtering consistency across all query sites and validate Telegram notification error handling.

Possibly related issues

  • Community creation via environment variable #808: Both changes implement the same COMMUNITY_CREATION_ENABLED environment variable and conditional registration of the /community command in bot/modules/community/index.ts for opt-in community creation feature.

Suggested reviewers

  • grunch
  • mostronatorcoder

Poem

🐰 A rabbit's ode to community gates...

Communities now can be disabled with care,
Admin commands keep the ecosystem fair,
Enabled flags filter through queries galore,
Locales speak eight languages—and more!
The /community command sleeps 'til set free,
A tidy state machine, as it should be. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Community creation env var' directly references the main objective of this PR: introducing a COMMUNITY_CREATION_ENABLED environment variable that controls community creation functionality.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

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

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.

@Matobi98 Matobi98 marked this pull request as draft May 21, 2026 00:39
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/commands.ts`:
- Around line 269-270: The validateObjectId check must short-circuit so we don't
later send duplicate "community_not_found" replies: ensure the helper that does
"if (!(await validateObjectId(ctx, input))) return null;" (the call that
precedes "return Community.findOne({ _id: input });") returns null on invalid
IDs and update the caller code paths that handle its result to bail out
immediately when they receive null instead of falling through to the existing
community_not_found reply; remove or gate the redundant replies that send
"community_not_found" (the blocks referenced around the current duplicate
checks) so only one response is sent for an invalid/community-missing ID.
🪄 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: a0b39147-8f44-4c52-9444-e09eebc65295

📥 Commits

Reviewing files that changed from the base of the PR and between d2c5b57 and 00eced1.

📒 Files selected for processing (19)
  • .env-sample
  • bot/modules/community/actions.ts
  • bot/modules/community/commands.ts
  • bot/modules/community/index.ts
  • bot/modules/community/messages.ts
  • bot/modules/orders/scenes.ts
  • bot/modules/user/scenes/settings.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
  • models/community.ts
  • util/communityHelper.ts

Comment thread bot/modules/community/commands.ts Outdated
@Matobi98 Matobi98 marked this pull request as ready for review May 21, 2026 00:54
@Luquitasjeffrey
Copy link
Copy Markdown
Collaborator

This pr looks like a continuation of #807
Please make it branch from main

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