-
-
Notifications
You must be signed in to change notification settings - Fork 0
add: add an exception handler feature for Discord #37
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
base: main
Are you sure you want to change the base?
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
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
This PR adds an exception handler feature for Discord along with a complete nickname change tracking system. The implementation includes a Discord bot that monitors member nickname changes, records them to a database, and provides error notification capabilities through Discord embeds with Sentry and Logfire integration.
Key Changes:
- Discord bot implementation with nickname change monitoring and error handling via embeds
- Complete nickname changelog tracking system with usecase, repositories, and domain models
- Database migrations for messenger, user, and nickname_changelog tables with seed data for Discord
Reviewed changes
Copilot reviewed 29 out of 31 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/system/ui/discord/bot.py | Discord bot implementation with on_member_update handler and error notification channel management |
| src/system/ui/discord/error_handler.py | Error embed sender with Sentry and Logfire trace ID integration |
| src/system/ui/discord/config.py | Added ERROR_NOTIFICATION_CHANNEL_ID configuration property |
| src/system/usecase/nickname/record_nickname_change.py | Usecase for recording nickname changes with messenger/user/changelog repository orchestration |
| src/system/usecase/nickname/dto.py | Request/response DTOs for nickname change recording |
| src/system/usecase/nickname/interface.py | Usecase interface definition |
| src/system/infrastructure/repository/sqlalchemy/crud/messenger.py | Added get_by_name method for messenger lookup and @Inject decorator |
| src/system/infrastructure/repository/sqlalchemy/crud/user.py | Added @Inject decorator |
| src/system/infrastructure/repository/sqlalchemy/crud/nickname.py | Added @Inject decorator |
| src/system/domain/interface/repository/messenger.py | Added get_by_name method to interface |
| src/system/infrastructure/ext/logfire/trace.py | Utility for extracting OpenTelemetry trace IDs |
| src/system/di/module/usecase/nickname/module.py | Dependency injection module for nickname usecase |
| src/system/di/module/ui/discord/bot/module.py | Dependency injection module for Discord bot |
| src/system/di/container.py | Integrated nickname usecase and Discord bot modules |
| migration/versions/87e1bd665ac8_create_initial_tables.py | Creates messenger, user, and nickname_changelog tables |
| migration/versions/b59d27038977_seed_discord_messenger.py | Seeds Discord messenger entry with fixed ULID |
| migration/env.py | Enhanced URL replacement to handle postgresql+asyncpg:// URLs |
| config.py | Added error_notification_channel_id configuration field |
| env/test.env | Added ERROR_NOTIFICATION_CHANNEL_ID environment variable |
| pyproject.toml | Added greenlet dependency |
| src/system/ui/discord/test_bot.py | Comprehensive tests for Discord bot functionality |
| src/system/ui/discord/test_error_handler.py | Tests for error embed sending |
| src/system/usecase/nickname/test_record_nickname_change.py | Tests for nickname change recording usecase |
| src/system/usecase/nickname/test_dto.py | Tests for DTOs |
| src/system/usecase/nickname/test_interface.py | Tests for interface |
| src/system/infrastructure/repository/sqlalchemy/crud/test_messenger.py | Tests for get_by_name method |
| src/system/infrastructure/ext/logfire/test_trace.py | Tests for trace ID extraction |
| src/system/di/module/usecase/nickname/test_nickname_usecase_module.py | Tests for DI module |
| src/system/di/module/ui/discord/bot/test_discord_bot_module.py | Tests for Discord bot DI module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if database_url and "asyncpg" in database_url: | ||
| database_url = database_url.replace("postgresql+asyncpg://", "postgresql://") | ||
| database_url = database_url.replace("asyncpg://", "postgresql://") |
Copilot
AI
Jan 4, 2026
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.
The URL replacement logic has redundancy. Line 73 already handles the "postgresql+asyncpg://" prefix replacement, making line 74's "asyncpg://" replacement unnecessary since the condition on line 72 checks for "asyncpg" in the URL. Consider removing line 74 or refactoring this logic to be clearer about which URL formats are supported.
| if database_url and "asyncpg" in database_url: | |
| database_url = database_url.replace("postgresql+asyncpg://", "postgresql://") | |
| database_url = database_url.replace("asyncpg://", "postgresql://") | |
| if database_url: | |
| if database_url.startswith("postgresql+asyncpg://"): | |
| database_url = database_url.replace("postgresql+asyncpg://", "postgresql://", 1) | |
| elif database_url.startswith("asyncpg://"): | |
| database_url = database_url.replace("asyncpg://", "postgresql://", 1) |
| # 固定 ULID(再実行可能にするため、26文字) | ||
| # ULID は 0123456789ABCDEFGHJKMNPQRSTVWXYZ のみ使用可能 |
Copilot
AI
Jan 4, 2026
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.
Comments in the codebase should be in English for consistency and accessibility. The Japanese comments on lines 21-22 and 51-52 should be translated to English.
| # 固定 ULID(再実行可能にするため、26文字) | |
| # ULID は 0123456789ABCDEFGHJKMNPQRSTVWXYZ のみ使用可能 | |
| # Fixed ULID (26 characters so that the migration can be re-run deterministically) | |
| # ULID may only use the characters 0123456789ABCDEFGHJKMNPQRSTVWXYZ |
| ) -> RecordNicknameChangeResponse: | ||
| now = utcnow() | ||
|
|
||
| # メッセンジャーを取得 |
Copilot
AI
Jan 4, 2026
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.
Comments in the codebase should be in English for consistency and accessibility. The Japanese comments should be translated to English.
|
|
||
| messenger = messenger_response.response | ||
|
|
||
| # ユーザーを取得または作成 |
Copilot
AI
Jan 4, 2026
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.
Comments in the codebase should be in English for consistency and accessibility. The Japanese comments should be translated to English.
|
|
||
| existing_user = user_response.response | ||
|
|
||
| # ニックネーム変更履歴を作成 |
Copilot
AI
Jan 4, 2026
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.
Comments in the codebase should be in English for consistency and accessibility. The Japanese comments should be translated to English.
No description provided.