Skip to content

Commit 8dc8786

Browse files
committed
feat(postgres): implement welcome message and global verification methods
- Added methods to get and set welcome messages for group chats in the PostgresRepository. - Implemented functionality to check and mark users as globally verified. - Enhanced database interactions for managing group settings and user verification status.
1 parent 721844c commit 8dc8786

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/python_italy_bot/db/postgres.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,54 @@ async def add_report(
158158
(reporter_id, reported_user_id, chat_id, message_id, reason),
159159
)
160160

161+
async def get_welcome_message(self, chat_id: int) -> str | None:
162+
async with self._pool.connection() as conn:
163+
async with conn.cursor() as cur:
164+
await cur.execute(
165+
"SELECT welcome_message FROM group_settings WHERE chat_id = %s",
166+
(chat_id,),
167+
)
168+
row = await cur.fetchone()
169+
return row[0] if row else None
170+
171+
async def set_welcome_message(self, chat_id: int, message: str | None) -> None:
172+
async with self._pool.connection() as conn:
173+
if message is None:
174+
await conn.execute(
175+
"DELETE FROM group_settings WHERE chat_id = %s",
176+
(chat_id,),
177+
)
178+
else:
179+
await conn.execute(
180+
"""
181+
INSERT INTO group_settings (chat_id, welcome_message, updated_at)
182+
VALUES (%s, %s, NOW())
183+
ON CONFLICT (chat_id)
184+
DO UPDATE SET welcome_message = EXCLUDED.welcome_message,
185+
updated_at = NOW()
186+
""",
187+
(chat_id, message),
188+
)
189+
190+
async def is_globally_verified(self, user_id: int) -> bool:
191+
async with self._pool.connection() as conn:
192+
async with conn.cursor() as cur:
193+
await cur.execute(
194+
"SELECT 1 FROM globally_verified_users WHERE user_id = %s",
195+
(user_id,),
196+
)
197+
return await cur.fetchone() is not None
198+
199+
async def mark_globally_verified(self, user_id: int) -> None:
200+
async with self._pool.connection() as conn:
201+
await conn.execute(
202+
"""
203+
INSERT INTO globally_verified_users (user_id, verified_at)
204+
VALUES (%s, NOW())
205+
ON CONFLICT (user_id) DO NOTHING
206+
""",
207+
(user_id,),
208+
)
209+
161210
async def close(self) -> None:
162211
await self._pool.close()

0 commit comments

Comments
 (0)