Skip to content

Conversation

@Colk-tech
Copy link
Member

No description provided.

@Colk-tech Colk-tech self-assigned this Jan 4, 2026
Copilot AI review requested due to automatic review settings January 4, 2026 08:45
@Colk-tech Colk-tech added the enhancement New feature or request label Jan 4, 2026
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

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.

Comment on lines 72 to 74
if database_url and "asyncpg" in database_url:
database_url = database_url.replace("postgresql+asyncpg://", "postgresql://")
database_url = database_url.replace("asyncpg://", "postgresql://")
Copy link

Copilot AI Jan 4, 2026

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment on lines 21 to 22
# 固定 ULID(再実行可能にするため、26文字)
# ULID は 0123456789ABCDEFGHJKMNPQRSTVWXYZ のみ使用可能
Copy link

Copilot AI Jan 4, 2026

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.

Suggested change
# 固定 ULID(再実行可能にするため、26文字)
# ULID は 0123456789ABCDEFGHJKMNPQRSTVWXYZ のみ使用可能
# Fixed ULID (26 characters so that the migration can be re-run deterministically)
# ULID may only use the characters 0123456789ABCDEFGHJKMNPQRSTVWXYZ

Copilot uses AI. Check for mistakes.
) -> RecordNicknameChangeResponse:
now = utcnow()

# メッセンジャーを取得
Copy link

Copilot AI Jan 4, 2026

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.

Copilot uses AI. Check for mistakes.

messenger = messenger_response.response

# ユーザーを取得または作成
Copy link

Copilot AI Jan 4, 2026

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.

Copilot uses AI. Check for mistakes.

existing_user = user_response.response

# ニックネーム変更履歴を作成
Copy link

Copilot AI Jan 4, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants