Skip to content

feat: add in-chat logs for mod-actions and report#66

Merged
lorenzocorallo merged 2 commits intomainfrom
inchat-logs
Mar 15, 2026
Merged

feat: add in-chat logs for mod-actions and report#66
lorenzocorallo merged 2 commits intomainfrom
inchat-logs

Conversation

@lorenzocorallo
Copy link
Copy Markdown
Member

No description provided.

@lorenzocorallo lorenzocorallo requested a review from toto04 March 10, 2026 12:47
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06e8ceb0-19e7-4ae6-984a-4eafa9a10dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 16b67e9 and 044b4cd.

📒 Files selected for processing (1)
  • src/commands/report.ts

Walkthrough

Suppresses success confirmations across moderation commands (ban/del/kick/mute), making handlers reply only on error; enhances report to give conditional formatted feedback; adds TgLogger.chat-side moderation logging for moderator actions; extends fmtUser to optionally hide user IDs.

Changes

Cohort / File(s) Summary
Moderation command replies
src/commands/ban.ts, src/commands/del.ts, src/commands/kick.ts, src/commands/mute.ts
Removed unconditional "OK" success replies; handlers now only reply on error (formatted error message), then auto-delete that reply after 5s. Successful actions produce no user-facing confirmation.
Report flow and reply formatting
src/commands/report.ts
Captures result of tgLogger.report(...) and replies with conditional formatted feedback: success message when reported, failure guidance otherwise; retains deletion of the reported message and reply parameters.
Chat-facing moderation logging
src/modules/tg-logger/index.ts
Added private logModActionInChat(p: ModerationAction) and invoke it for moderator-initiated actions to post formatted moderation summaries to the chat; errors during posting are logged as warnings.
Utilities & cleanup
src/modules/moderation/index.ts, src/utils/format.ts
Removed an in-file TODO and updated fmtUser signature to fmtUser(user, showId = true) allowing omission of the numeric ID in formatted user output.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Moderator
participant Bot
participant TgLogger
participant Chat

Moderator->>Bot: Issue moderation command (ban/kick/mute)
Bot->>TgLogger: perform moderationAction(...)
TgLogger-->>Bot: result (success / error)
alt error
    Bot->>Moderator: reply with formatted error (auto-delete after 5s)
else success
    TgLogger->>Chat: logModActionInChat(...) (post moderation summary)
    Note right of Chat: message posted to chat (non-bot moderator action)
end

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 PR title 'feat: add in-chat logs for mod-actions and report' accurately reflects the main changes across all modified files, particularly the new logModActionInChat helper method and the report feedback improvements.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can validate your CodeRabbit configuration file in your editor.

If your editor has YAML language server, you can enable auto-completion and validation by adding # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json at the top of your CodeRabbit configuration file.

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

🧹 Nitpick comments (1)
src/commands/ban.ts (1)

30-34: Consider centralizing the transient error-reply flow.

The same reply → wait(5000) → delete sequence is now repeated in ban, tban, and unban here, and the same pattern shows up in the other moderation commands in this PR. A tiny helper would keep timeout/delete behavior consistent and give you one place to harden if reply deletion starts failing.

Also applies to: 70-74, 109-113

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/ban.ts` around lines 30 - 34, Extract the repeated "reply →
wait(5000) → delete" flow into a single helper (e.g., sendTransientReply or
replyThenDelete) and replace the blocks in ban, tban, and unban that check
res.isErr() (and any similar moderation command error branches) to call that
helper instead of duplicating the logic; the helper should accept the
context/message content and optional timeout (default 5000ms), await the reply,
await the timeout, attempt to delete the message and catch/log delete errors so
failures are handled centrally and consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands/report.ts`:
- Around line 19-33: The public reply in the context.reply success branch
exposes the reporter by using fmtUser(context.from); update the behavior so the
acknowledgment is anonymous: remove fmtUser(context.from) from the success
message and replace it with a generic confirmation (e.g., "Thanks — moderators
have been notified.") or send the confirmation privately via a direct message to
the reporter (use context.from to DM, but do not mention them in the group
reply). Change the message construction in the code block that uses reportSent
and fmt to eliminate any reference to context.from or fmtUser while keeping the
same reply metadata (reply_parameters/message_id) logic.

In `@src/modules/tg-logger/index.ts`:
- Around line 513-520: The message construction for MOD_ACTION_TITLE(p)
currently includes moderator-supplied p.reason (see msg creation and fmtUser
usage), which must not be echoed to public chat; remove inclusion of "reason"
from the public fmt output and only include action, target, moderator and
optional duration, and if you need a public-facing rationale use a separate
curated field (e.g., p.publicReason) instead; keep the original p.reason in
internal/admin logs but ensure the code paths that build the public msg (the fmt
call that produces msg and the same pattern at the related block around 524-528)
do not interpolate p.reason into messages sent to the group.

---

Nitpick comments:
In `@src/commands/ban.ts`:
- Around line 30-34: Extract the repeated "reply → wait(5000) → delete" flow
into a single helper (e.g., sendTransientReply or replyThenDelete) and replace
the blocks in ban, tban, and unban that check res.isErr() (and any similar
moderation command error branches) to call that helper instead of duplicating
the logic; the helper should accept the context/message content and optional
timeout (default 5000ms), await the reply, await the timeout, attempt to delete
the message and catch/log delete errors so failures are handled centrally and
consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a10ce5f-978d-47b5-97df-738bcb658194

📥 Commits

Reviewing files that changed from the base of the PR and between 6d4ae93 and 16b67e9.

📒 Files selected for processing (8)
  • src/commands/ban.ts
  • src/commands/del.ts
  • src/commands/kick.ts
  • src/commands/mute.ts
  • src/commands/report.ts
  • src/modules/moderation/index.ts
  • src/modules/tg-logger/index.ts
  • src/utils/format.ts
💤 Files with no reviewable changes (1)
  • src/modules/moderation/index.ts

Comment thread src/commands/report.ts
Comment thread src/modules/tg-logger/index.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.

2 participants