Skip to content

Conversation

@lorenzocorallo
Copy link
Member

@lorenzocorallo lorenzocorallo commented Oct 17, 2025

Summary by CodeRabbit

  • Documentation

    • Updated project reference links
    • Added new reference materials to README
  • New Features

    • Introduced group-specific message validation with automated error notifications

✏️ Tip: You can customize this high-level summary in your review settings.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new middleware to enforce group-specific posting rules based on required hashtags, and wires it into the bot pipeline.

  • Introduces GroupSpecificActions middleware with per-group hashtag validation and user feedback.
  • Integrates the middleware into bot.ts to run after existing moderation.
  • Updates TODO to mark the feature complete and adds a small README reference.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/middlewares/group-specific-actions.ts Implements group-specific message validation and error handling for configured groups.
src/bot.ts Registers the new GroupSpecificActions middleware in the bot middleware chain.
TODO.md Marks group-specific moderation as completed.
README.md Adds a reference link; no functional changes.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

lorenzocorallo and others added 2 commits October 18, 2025 00:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 17, 2025 23:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@lorenzocorallo
Copy link
Member Author

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Warning

Rate limit exceeded

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

⌛ 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 106377b and 9b507c5.

📒 Files selected for processing (1)
  • src/middlewares/group-specific-actions.ts

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new GroupSpecificActions middleware enforcing group-specific hashtag rules for targeted Telegram groups, registers it in the bot middleware stack, and updates README/TODO reference links.

Changes

Cohort / File(s) Summary
Documentation updates
README.md, TODO.md
Added "Maybe useful references" subsection to README.md with a private messages reference link; updated a group-specific moderation reference link in TODO.md.
Bot middleware registration
src/bot.ts
Imports and registers GroupSpecificActions in the middleware stack after AutoModerationStack and before UIActionsLogger, changing middleware execution order.
Group-specific validation middleware
src/middlewares/group-specific-actions.ts
New exported class GroupSpecificActions<C extends Context> with middleware() accessor; exported TARGET_GROUPS and TARGET_GROUP_IDS_SET; filters messages by target group, skips bots/users with roles and admins/creators; dispatches to checkAlloggi, checkRipetizioni, or checkBooks; validates required hashtags; logs violations, replies with formatted error, and schedules non-blocking deletion of the error message after 2 minutes.

Sequence Diagram

sequenceDiagram
    participant User
    participant Bot
    participant GSA as GroupSpecificActions
    participant Logger
    participant Telegram

    User->>Bot: Send message
    Bot->>GSA: Pass message to middleware

    rect rgba(220,240,255,0.5)
        Note over GSA: Filter & access checks
        GSA->>GSA: Is target group?
        GSA->>GSA: Is bot or user with role?
        GSA->>GSA: Is admin/creator?
    end

    alt Enforcement applies
        rect rgba(200,255,220,0.5)
            Note over GSA: Group-specific validation
            GSA->>GSA: Dispatch to validator (checkAlloggi / checkRipetizioni / checkBooks)
            GSA->>GSA: Validate hashtags
        end

        alt Validation fails
            rect rgba(255,230,200,0.5)
                GSA->>Logger: Log violation
                GSA->>User: Reply with formatted error
                GSA->>Telegram: Schedule deletion (2 min)
            end
        else Validation passes
            GSA->>Bot: Continue processing
        end
    else Enforcement skipped
        GSA->>Bot: Continue processing
    end
Loading

Estimated code review effort

High — focus on validation logic, exclusion checks, error-reply formatting and deletion timing, and middleware registration order.

🚥 Pre-merge checks | ✅ 1 | ❌ 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 (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: group-specific actions middleware' accurately describes the main change, which is the addition of a new GroupSpecificActions middleware in src/middlewares/group-specific-actions.ts integrated into the bot middleware stack.

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


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.

Copy link

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

♻️ Duplicate comments (1)
src/middlewares/group-specific-actions.ts (1)

24-30: Guard against undefined ctx.from to prevent runtime errors.

ctx.from can be undefined for messages sent on behalf of a channel (sender_chat) or anonymous group admins. Accessing ctx.from.id without a guard will throw a TypeError.

Add a guard at the start of the message handler:

      .on("message", async (ctx, next) => {
+        if (!ctx.from) return next() // skip channel posts / anonymous messages
        if (ctx.from.id === ctx.me.id) return next() // skip if bot
        const { roles } = await api.tg.permissions.getRoles.query({ userId: ctx.from.id })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 797c7f8 and 765a7e8.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • TODO.md (1 hunks)
  • src/bot.ts (2 hunks)
  • src/middlewares/group-specific-actions.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/middlewares/group-specific-actions.ts (6)
src/utils/types.ts (1)
  • Context (18-18)
src/backend.ts (1)
  • api (10-10)
src/logger.ts (1)
  • logger (3-8)
src/modules/index.ts (1)
  • modules (10-27)
src/utils/format.ts (2)
  • fmt (123-139)
  • fmtUser (141-144)
src/utils/wait.ts (1)
  • wait (11-17)
src/bot.ts (1)
src/middlewares/group-specific-actions.ts (1)
  • GroupSpecificActions (18-119)
🪛 GitHub Actions: Test
src/middlewares/group-specific-actions.ts

[error] 16-16: File content differs from formatting output. Formatting check failed (e.g., Prettier/formatter output mismatch).

🪛 markdownlint-cli2 (0.18.1)
TODO.md

32-32: Link text should be descriptive

(MD059, descriptive-link-text)

🔇 Additional comments (3)
README.md (1)

23-25: LGTM!

Helpful reference documentation for developers working on related messaging features.

src/bot.ts (1)

15-15: LGTM!

The middleware is correctly imported and registered in the appropriate position within the middleware stack.

Also applies to: 80-80

src/middlewares/group-specific-actions.ts (1)

71-114: Implementation looks reasonable for the check methods.

The hashtag validation logic correctly uses case-insensitive matching and returns descriptive error messages via the Result type.

Note: The code duplication across the three check methods was previously discussed and deferred to the reviewer (toto04). If you decide to refactor, consider extracting a shared helper like checkHashtags(ctx, allowedTags, errorMessage).

Copilot AI review requested due to automatic review settings January 21, 2026 01:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lorenzocorallo lorenzocorallo merged commit 7349fb5 into main Jan 21, 2026
2 checks passed
@lorenzocorallo lorenzocorallo deleted the group-specific branch January 21, 2026 02:04
@lorenzocorallo lorenzocorallo restored the group-specific branch January 21, 2026 02:04
@lorenzocorallo lorenzocorallo deleted the group-specific branch January 21, 2026 02:04
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.

3 participants