Skip to content

Commit 721844c

Browse files
committed
feat(welcome): add welcome message handling to repository interfaces
- Introduced abstract methods for getting and setting custom welcome messages in both synchronous and asynchronous repository classes. - Implemented in-memory storage for welcome messages and global verification status in the InMemoryRepository class. - Enhanced user verification logic to support global verification across all chats.
1 parent 9d8371b commit 721844c

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/python_italy_bot/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ def __init__(self) -> None:
4949
)
5050
self.main_group_id: int | None = _get_optional_int("MAIN_GROUP_ID")
5151
self.local_group_ids: list[int] = _get_int_list("LOCAL_GROUP_IDS")
52+
self.rules_url: str | None = _get_optional_env("RULES_URL")

src/python_italy_bot/db/base.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ def add_report(
8686
"""Record a report."""
8787
...
8888

89+
@abstractmethod
90+
def get_welcome_message(self, chat_id: int) -> str | None:
91+
"""Get custom welcome message for a chat."""
92+
...
93+
94+
@abstractmethod
95+
def set_welcome_message(self, chat_id: int, message: str | None) -> None:
96+
"""Set custom welcome message for a chat. Pass None to remove."""
97+
...
98+
99+
@abstractmethod
100+
def is_globally_verified(self, user_id: int) -> bool:
101+
"""Check if user is globally verified across all chats."""
102+
...
103+
104+
@abstractmethod
105+
def mark_globally_verified(self, user_id: int) -> None:
106+
"""Mark user as globally verified."""
107+
...
108+
89109

90110
class AsyncRepository(ABC):
91111
"""Abstract interface for data persistence (async)."""
@@ -170,6 +190,26 @@ async def add_report(
170190
"""Record a report."""
171191
...
172192

193+
@abstractmethod
194+
async def get_welcome_message(self, chat_id: int) -> str | None:
195+
"""Get custom welcome message for a chat."""
196+
...
197+
198+
@abstractmethod
199+
async def set_welcome_message(self, chat_id: int, message: str | None) -> None:
200+
"""Set custom welcome message for a chat. Pass None to remove."""
201+
...
202+
203+
@abstractmethod
204+
async def is_globally_verified(self, user_id: int) -> bool:
205+
"""Check if user is globally verified across all chats."""
206+
...
207+
208+
@abstractmethod
209+
async def mark_globally_verified(self, user_id: int) -> None:
210+
"""Mark user as globally verified."""
211+
...
212+
173213
async def close(self) -> None:
174214
"""Close any resources (override if needed)."""
175215
pass

src/python_italy_bot/db/in_memory.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __init__(self) -> None:
1515
self._bans: list[Ban] = []
1616
self._mutes: list[Mute] = []
1717
self._reports: list[Report] = []
18+
self._welcome_messages: dict[int, str] = {}
19+
self._globally_verified: set[int] = set()
1820

1921
async def add_pending_verification(self, user_id: int, chat_id: int) -> None:
2022
self._pending.add((user_id, chat_id))
@@ -117,3 +119,18 @@ async def add_report(
117119
created_at=datetime.now(timezone.utc),
118120
)
119121
)
122+
123+
async def get_welcome_message(self, chat_id: int) -> str | None:
124+
return self._welcome_messages.get(chat_id)
125+
126+
async def set_welcome_message(self, chat_id: int, message: str | None) -> None:
127+
if message is None:
128+
self._welcome_messages.pop(chat_id, None)
129+
else:
130+
self._welcome_messages[chat_id] = message
131+
132+
async def is_globally_verified(self, user_id: int) -> bool:
133+
return user_id in self._globally_verified
134+
135+
async def mark_globally_verified(self, user_id: int) -> None:
136+
self._globally_verified.add(user_id)

0 commit comments

Comments
 (0)