Community creation env var#810
Conversation
WalkthroughThis PR adds environment-controlled community management commands. It introduces a ChangesCommunity Management Feature Gate and Control Commands
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
bot/modules/community/commands.ts (1)
278-380: ⚡ Quick winConsolidate enable/disable logic into one toggle helper.
disableCommunityandenableCommunityduplicate the same control flow, DB operations, notification path, and reply composition. Extracting a shared internal function will reduce drift risk and make future fixes safer.♻️ Refactor sketch
+type CommunityToggleConfig = { + targetEnabled: boolean; + alreadyStateKey: string; + notifyKey: string; + infoKey: string; +}; + +async function toggleCommunity(ctx: MainContext, cfg: CommunityToggleConfig) { + const [input] = (await validateParams( + ctx, + 2, + '\\<_community id \\| `@groupUsername_`\\>', + ))!; + if (!input) return; + + const community = await findCommunityByInput(ctx, input); + if (community === undefined) return; + if (community === null) return ctx.reply(ctx.i18n.t('community_not_found')); + + if (community.enabled === cfg.targetEnabled) { + return ctx.reply(ctx.i18n.t(cfg.alreadyStateKey)); + } + + community.enabled = cfg.targetEnabled; + await community.save(); + + const creator = await User.findById(community.creator_id); + const creatorUsername = creator?.username || 'unknown'; + + if (creator) { + try { + await ctx.telegram.sendMessage( + creator.tg_id, + ctx.i18n.t(cfg.notifyKey, { communityName: community.name }), + ); + } catch (notifyError) { + logger.error(notifyError); + } + } + + return ctx.reply( + buildCommunityInfoText(ctx, community, creatorUsername, cfg.infoKey), + ); +} + export const disableCommunity = async (ctx: MainContext) => { try { - // existing duplicated body + return await toggleCommunity(ctx, { + targetEnabled: false, + alreadyStateKey: 'community_already_disabled', + notifyKey: 'community_disabled_by_admin', + infoKey: 'community_disabled_info', + }); } catch (error) { logger.error(error); await ctx.reply(ctx.i18n.t('generic_error')); } }; export const enableCommunity = async (ctx: MainContext) => { try { - // existing duplicated body + return await toggleCommunity(ctx, { + targetEnabled: true, + alreadyStateKey: 'community_already_enabled', + notifyKey: 'community_enabled_by_admin', + infoKey: 'community_enabled_info', + }); } catch (error) { logger.error(error); await ctx.reply(ctx.i18n.t('generic_error')); } };🤖 Prompt for 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. In `@bot/modules/community/commands.ts` around lines 278 - 380, Extract the shared logic from disableCommunity and enableCommunity into a single helper function (e.g., toggleCommunity(ctx: MainContext, input: string, enable: boolean)) that: validates params or accepts already-validated input, calls findCommunityByInput, checks for null/undefined, compares/sets community.enabled based on the enable flag, saves via community.save(), resolves creator via User.findById, sends the appropriate notification text keys ('community_disabled_by_admin' / 'community_enabled_by_admin') and returns the same buildCommunityInfoText reply with the correct info key ('community_disabled_info' / 'community_enabled_info'); then rewrite disableCommunity and enableCommunity to call toggleCommunity(ctx, input, false) and toggleCommunity(ctx, input, true) respectively, preserving existing error handling and logging (logger.error) and keeping validateParams usage in the top-level functions if you prefer.
🤖 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.
Nitpick comments:
In `@bot/modules/community/commands.ts`:
- Around line 278-380: Extract the shared logic from disableCommunity and
enableCommunity into a single helper function (e.g., toggleCommunity(ctx:
MainContext, input: string, enable: boolean)) that: validates params or accepts
already-validated input, calls findCommunityByInput, checks for null/undefined,
compares/sets community.enabled based on the enable flag, saves via
community.save(), resolves creator via User.findById, sends the appropriate
notification text keys ('community_disabled_by_admin' /
'community_enabled_by_admin') and returns the same buildCommunityInfoText reply
with the correct info key ('community_disabled_info' /
'community_enabled_info'); then rewrite disableCommunity and enableCommunity to
call toggleCommunity(ctx, input, false) and toggleCommunity(ctx, input, true)
respectively, preserving existing error handling and logging (logger.error) and
keeping validateParams usage in the top-level functions if you prefer.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fa40f34b-a6e6-4037-9874-ba4a6ed3075d
📒 Files selected for processing (3)
.env-samplebot/modules/community/commands.tsbot/modules/community/index.ts
|
This pr has changes not related to the title and description |
Summary
COMMUNITY_CREATION_ENABLEDenvironment variable (default:false) that controls whether the/communitycommand is registered at bot startup/communitycommand block inbot/modules/community/index.tswith a conditionalregistration guarded by the env var
COMMUNITY_CREATION_ENABLED=falseto.env-samplewith an explanatory commentBehavior
COMMUNITY_CREATION_ENABLED=false(default) —/communityis not registered; community creation is disabledCOMMUNITY_CREATION_ENABLED=true—/communityis registered and users can create communities through the existingwizard flow
The wizard scene itself (
COMMUNITY_WIZARD_SCENE_ID) is unchanged — it was already fully implemented.Test plan
COMMUNITY_CREATION_ENABLEDunset orfalse, confirm/communityreturns no response / unknown commandCOMMUNITY_CREATION_ENABLED=true, confirm/communityenters the community creation wizard correctlyEOF
Summary by CodeRabbit
Release Notes