Skip to content

feat(bot): implement role create and delete audit log handlers - #388

Merged
LucasSantana-Dev merged 3 commits into
mainfrom
feat/role-audit-events
Mar 30, 2026
Merged

LucasSantana-Dev merged 3 commits into
mainfrom
feat/role-audit-events

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Mar 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Implemented GuildRoleCreate and GuildRoleDelete audit log handlers
  • Added feature toggle checks (isServerLogsEnabled) to both role handlers
  • Registered event listeners in handleAuditEvents
  • Added 8 comprehensive tests (4 per event) covering:
    • Successful logging with audit log data
    • Feature toggle disabled scenarios
    • Missing audit log gracefully handled
    • Error handling during logging
    • Error wrapper tests

Changes

  • auditHandler.ts: Added event registration for Events.GuildRoleCreate and Events.GuildRoleDelete
  • auditHandler.ts: Added feature toggle checks to handleRoleCreate and handleRoleDelete
  • auditHandler.spec.ts: Added 8 tests for role events + 2 error wrapper tests
  • Removed outdated comment about role events not being available

Test Results

All 34 tests passing in auditHandler.spec.ts

Related

Closes the TODO comment at lines 383-385 in auditHandler.ts

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced handling of role creation and deletion audit events with robust error management and proper feature toggle integration.
  • Tests

    • Expanded test suite with comprehensive coverage for role audit event handlers, including error scenarios and edge cases.

@vercel

vercel Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Mar 30, 2026 8:21pm

Request Review

@coderabbitai

coderabbitai Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR adds test coverage and implementation for Discord audit event handlers for role creation and deletion. A refactored shared helper function handleRoleEvent consolidates common audit-logging logic, with explicit event listeners registered for Events.GuildRoleCreate and Events.GuildRoleDelete. Tests validate logging behavior, feature toggle controls, and error handling.

Changes

Cohort / File(s) Summary
Role Event Handlers
packages/bot/src/handlers/auditHandler.ts
Introduced handleRoleEvent shared helper to unify role create/delete logic with parameterized audit log actions and logged message text. Updated handleAuditEvents to register explicit Discord.js listeners for role events with try/catch error logging.
Handler Test Suite
packages/bot/src/handlers/auditHandler.spec.ts
Added comprehensive test coverage for role event handlers, including registration assertions, feature toggle checks, successful logging validation, audit log fetch failure handling, and server log creation error scenarios.

Sequence Diagram

sequenceDiagram
    participant Discord as Discord.js Events
    participant Handler as auditHandler
    participant Toggle as featureToggleService
    participant Guild as Guild
    participant AuditLog as auditLogService
    participant ServerLog as serverLogService

    Discord->>Handler: GuildRoleCreate / GuildRoleDelete event
    Handler->>Toggle: isEnabled('SERVER_LOGS')
    Toggle-->>Handler: enabled/disabled
    alt Feature Enabled
        Handler->>Guild: fetchAuditLogs(auditLogAction)
        Guild-->>Handler: audit log entry or undefined
        Handler->>ServerLog: createLog(role, action, moderatorId?)
        ServerLog-->>Handler: success / error
    else Feature Disabled
        Handler->>Handler: skip logging
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing audit log handlers for role creation and deletion events in the bot.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/role-audit-events

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.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
20.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 29a6841 into main Mar 30, 2026
11 of 12 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the feat/role-audit-events branch March 31, 2026 22:15

This branch was successfully deployed

1 active deployment
Preview — 266d0e59 Deployed Mar 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant