Address PR #19 review feedback: simplify models
- Remove GroupBounty/PersonalBounty subclasses, use Bounty with optional created_by_user_id - Combine UserData/GroupData into RoomData with room_id and is_group fields - Add group_id field to TrackingData (supports negative Telegram group IDs) - Add test_bounty_comparison_not_equal for verifying different bounties are not equal - Update core/__init__.py exports
This commit is contained in:
@@ -6,27 +6,18 @@ from typing import Optional
|
||||
|
||||
@dataclass
|
||||
class Bounty:
|
||||
"""Base bounty with common fields."""
|
||||
"""Bounty - used for both group and personal bounties.
|
||||
|
||||
Use created_by_user_id to distinguish: if set, it's a group bounty
|
||||
created by that user. If None, it's a personal/DM bounty.
|
||||
"""
|
||||
|
||||
id: int
|
||||
text: Optional[str]
|
||||
link: Optional[str]
|
||||
due_date_ts: Optional[int]
|
||||
created_at: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class GroupBounty(Bounty):
|
||||
"""Bounty created in a group context."""
|
||||
|
||||
created_by_user_id: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class PersonalBounty(Bounty):
|
||||
"""Bounty created in DM/personal context."""
|
||||
|
||||
pass
|
||||
created_by_user_id: Optional[int] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -38,26 +29,27 @@ class TrackedBounty:
|
||||
|
||||
|
||||
@dataclass
|
||||
class GroupData:
|
||||
"""All data for a group."""
|
||||
class RoomData:
|
||||
"""All data for a room (group or DM).
|
||||
|
||||
group_id: int
|
||||
bounties: list[GroupBounty]
|
||||
For groups: is_group=True, room_id is negative (Telegram group ID)
|
||||
For DMs: is_group=False, room_id is the user_id (positive)
|
||||
next_id is used to generate unique bounty IDs within this room.
|
||||
"""
|
||||
|
||||
room_id: int
|
||||
is_group: bool
|
||||
bounties: list[Bounty]
|
||||
next_id: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class TrackingData:
|
||||
"""User tracking data within a group."""
|
||||
"""User tracking data within a group.
|
||||
|
||||
group_id is the Telegram group ID (always negative).
|
||||
"""
|
||||
|
||||
group_id: int
|
||||
user_id: int
|
||||
tracked: list[TrackedBounty]
|
||||
|
||||
|
||||
@dataclass
|
||||
class UserData:
|
||||
"""All personal bounties for a user (DM mode)."""
|
||||
|
||||
user_id: int
|
||||
bounties: list[PersonalBounty]
|
||||
next_id: int
|
||||
|
||||
Reference in New Issue
Block a user