-
Notifications
You must be signed in to change notification settings - Fork 0
feat: group-specific actions middleware #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (1)
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughAdds 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
Sequence DiagramsequenceDiagram
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
Estimated code review effortHigh — 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)
✅ Passed checks (1 passed)
✏️ 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. Comment |
There was a problem hiding this 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 undefinedctx.fromto prevent runtime errors.
ctx.fromcan beundefinedfor messages sent on behalf of a channel (sender_chat) or anonymous group admins. Accessingctx.from.idwithout a guard will throw aTypeError.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
📒 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
Resulttype.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).
There was a problem hiding this 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.
Summary by CodeRabbit
Documentation
New Features
✏️ Tip: You can customize this high-level summary in your review settings.