Skip to content

feat: add counterparty requirements configuration in /settings#827

Open
Matobi98 wants to merge 3 commits into
lnp2pBot:mainfrom
Matobi98:feat/counterparty-requirements
Open

feat: add counterparty requirements configuration in /settings#827
Matobi98 wants to merge 3 commits into
lnp2pBot:mainfrom
Matobi98:feat/counterparty-requirements

Conversation

@Matobi98

@Matobi98 Matobi98 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds counterparty requirements to the /settings wizard. Users can now set minimum conditions that must be met before someone can take their orders.

What's new

  • /counterpartyage <days> — sets the minimum account age (in days) required for the counterparty
  • /counterpartyorders <orders> — sets the minimum number of completed orders required for the counterparty
  • /resetrequirements — resets both values back to 0

The /settings panel now shows the current requirements. If a user tries to take an order and doesn't meet the maker's requirements, they receive a notification and the order stays listed.

Environment variables

Two new optional variables can be added to .env to cap the maximum values users can set:

MAX_COUNTERPARTY_AGE_REQUIREMENT=30
MAX_COUNTERPARTY_ORDERS_REQUIREMENT=10

Languages

All 10 supported languages updated (en, es, de, fr, it, pt, ru, uk, ko, fa).

Closes

Fixes #648

Summary by CodeRabbit

  • New Features

    • Users can set minimum counterparty account age and minimum completed orders to control who may take their trades
    • New settings commands: /counterpartyage, /counterpartyorders, /resetrequirements
    • Order acceptance now checks configured counterparty requirements and notifies users when a taker doesn't meet them
  • Localization

    • Full translated help and UI text for these settings across multiple languages

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Ready to act? Review this PR in Change Stack to turn feedback into patch suggestions you can inspect and refine.

Review Change Stack

Warning

Review limit reached

@Matobi98, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 minutes and 18 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3aa81bc1-6c1b-4317-abcc-a26284282935

📥 Commits

Reviewing files that changed from the base of the PR and between f56f0f9 and 0e6e7a3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • bot/modules/user/scenes/settings.ts
  • models/user.ts

Walkthrough

Users can set minimum counterparty account age and completed-orders via new /settings subcommands; order takers are checked against those thresholds and notified if they don’t meet them. Localized UI/help updated across multiple languages.

Changes

Counterparty Requirements

Layer / File(s) Summary
Data model and environment configuration
models/user.ts, .env-sample
Adds optional counterparty_requirements with min_days_using_bot and min_completed_orders to UserDocument and schema; .env-sample adds MAX_COUNTERPARTY_AGE_REQUIREMENT and MAX_COUNTERPARTY_ORDERS_REQUIREMENT.
Order-taking enforcement and notification
bot/modules/orders/takeOrder.ts, bot/messages.ts
takebuy and takesell now call meetsCounterpartyRequirements() after community-ban checks; it validates taker age and completed orders against creator thresholds and calls notMeetingRequirementsMessage() to notify and halt processing on failure.
User settings commands for requirement configuration
bot/modules/user/scenes/settings.ts
Adds /counterpartyage, /counterpartyorders, and /resetrequirements; parses/validates input, enforces env-configured maximums, initializes/persists user.counterparty_requirements, and surfaces feedback/errors in the settings wizard.
Multi-language help and UI text
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
Help and user_settings templates updated to document new commands, display current minima, and add validation/status strings (not_meeting_requirements, counterpartyage_updated, counterpartyorders_updated, requirements_reset, invalid_number, invalid_range).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • mostronatorcoder
  • grunch

Poem

A rabbit hops and sets the gate,
"Show days and trades to pass my state."
Numbers tallied, rules in place,
Gentle checks for every face.
I nibble logs and send a note — be great! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements counterparty requirements filtering but does not implement the /reject command or order reposting mechanism specified in issue #648. Implement /reject command to expire invoices and repost orders as specified in #648, or clarify if this PR is only a prerequisite feature.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title concisely summarizes the main change: adding counterparty requirements configuration in /settings, which is the primary feature in this changeset.
Out of Scope Changes check ✅ Passed All changes are directly related to adding counterparty requirements configuration in /settings; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 force-pushed the feat/counterparty-requirements branch from 5426763 to f56f0f9 Compare June 5, 2026 21:37

@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: 2

🧹 Nitpick comments (1)
bot/modules/user/scenes/settings.ts (1)

147-148: ⚡ Quick win

Use camelCase local variable names in TypeScript handlers.

Line 147 (min_days) and Line 191 (min_orders) should be camelCase for consistency with repository TS naming rules.

Suggested fix
-const min_days = parseInt(days);
-if (isNaN(min_days) || min_days < 0) throw new Error('NotValidNumber');
+const minDays = parseInt(days);
+if (isNaN(minDays) || minDays < 0) throw new Error('NotValidNumber');
...
-user.counterparty_requirements.min_days_using_bot = min_days;
+user.counterparty_requirements.min_days_using_bot = minDays;
...
-state.feedback = { i18n: 'counterpartyage_updated', days: min_days };
+state.feedback = { i18n: 'counterpartyage_updated', days: minDays };
-const min_orders = parseInt(orders);
-if (isNaN(min_orders) || min_orders < 0)
+const minOrders = parseInt(orders);
+if (isNaN(minOrders) || minOrders < 0)
   throw new Error('NotValidNumber');
...
-user.counterparty_requirements.min_completed_orders = min_orders;
+user.counterparty_requirements.min_completed_orders = minOrders;
...
-orders: min_orders,
+orders: minOrders,

As per coding guidelines: **/*.{ts,tsx}: Use camelCase for functions and variables.

Also applies to: 191-193

🤖 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/user/scenes/settings.ts` around lines 147 - 148, Rename the
snake_case local variables to camelCase: change min_days to minDays (and
min_orders to minOrders where present) in the handler(s) that parse user input
(the parseInt(days) block and the corresponding parseInt/orders block), update
all local references within the same function/scene to use the new names, keep
the exact validation logic (isNaN/min < 0) and type handling intact, and run a
quick search in the file to update any remaining occurrences of
min_days/min_orders to avoid leaving dangling references.
🤖 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/user/scenes/settings.ts`:
- Around line 171-176: The catch block currently maps every exception to
CommunityWizardState.error.i18n = 'invalid_number' (in the handler around
ctx.scene.state, updateMessage and user.save()), which hides real runtime
failures; change the handler to distinguish validation/parsing errors (e.g.,
number parse/validation or a specific ValidationError) and only set i18n =
'invalid_number' for those cases, while for other exceptions log the full error
and either rethrow or set a generic/internal error state (or call updateMessage
with a different i18n key) so Telegram/API/save errors are not reported as
invalid input.
- Around line 149-151: Validate and sanitize the environment cap values before
enforcing the range: for the MAX_COUNTERPARTY_AGE_REQUIREMENT parse (the maxAge
variable in bot/modules/user/scenes/settings.ts) and the other env parse around
lines 194-196 (e.g., maxDistance), ensure you parse with radix 10, check that
the result is a finite non-negative integer (and >0 if that’s the requirement),
and fall back to the literal default ('30' or the other default) when the env is
empty, non-numeric, negative, or NaN; replace the current direct parseInt usage
with this validated-value logic so the range guards always receive a correct
numeric cap.

---

Nitpick comments:
In `@bot/modules/user/scenes/settings.ts`:
- Around line 147-148: Rename the snake_case local variables to camelCase:
change min_days to minDays (and min_orders to minOrders where present) in the
handler(s) that parse user input (the parseInt(days) block and the corresponding
parseInt/orders block), update all local references within the same
function/scene to use the new names, keep the exact validation logic (isNaN/min
< 0) and type handling intact, and run a quick search in the file to update any
remaining occurrences of min_days/min_orders to avoid leaving dangling
references.
🪄 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: c597be7a-0669-4782-85f2-e8cfac278bda

📥 Commits

Reviewing files that changed from the base of the PR and between 4721a27 and 5426763.

📒 Files selected for processing (15)
  • .env-sample
  • bot/messages.ts
  • bot/modules/orders/takeOrder.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/user.ts

Comment thread bot/modules/user/scenes/settings.ts Outdated
Comment thread bot/modules/user/scenes/settings.ts

@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 `@models/user.ts`:
- Around line 58-61: The counterparty_requirements nested object in the Mongoose
schema should be made truly optional to match the TypeScript interface and the
guard in takeOrder.ts (the `if (!orderCreator.counterparty_requirements)`
check). Update the schema entry for counterparty_requirements (in
models/user.ts) so it does not auto-create a default object—either wrap the two
fields in a sub-Schema and set required: false (or default: undefined), or
remove the default values for that object and explicitly set required:
false/default: undefined; keep the individual fields' min/defaults only if you
still want defaults when the object exists. This ensures the object can be
undefined for users who never configured it and makes the guard in takeOrder.ts
behave correctly.
🪄 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: 0a4963d4-443e-43e6-948a-7d71e9248708

📥 Commits

Reviewing files that changed from the base of the PR and between 5426763 and f56f0f9.

📒 Files selected for processing (15)
  • .env-sample
  • bot/messages.ts
  • bot/modules/orders/takeOrder.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/user.ts
✅ Files skipped from review due to trivial changes (6)
  • locales/pt.yaml
  • locales/fa.yaml
  • locales/fr.yaml
  • locales/de.yaml
  • locales/ko.yaml
  • locales/es.yaml
🚧 Files skipped from review as they are similar to previous changes (7)
  • bot/messages.ts
  • locales/uk.yaml
  • .env-sample
  • locales/ru.yaml
  • locales/en.yaml
  • bot/modules/user/scenes/settings.ts
  • bot/modules/orders/takeOrder.ts

Comment thread models/user.ts
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.

1 participant