1414logger = logging .getLogger (__name__ )
1515
1616
17- async def _track_user (repo : AsyncRepository , user : object ) -> None :
18- """Track a Telegram user in the known_users table."""
19- await repo .upsert_known_user (
20- user_id = user .id , # type: ignore[attr-defined]
21- username = getattr (user , "username" , None ),
22- first_name = getattr (user , "first_name" , None ),
23- last_name = getattr (user , "last_name" , None ),
24- )
25-
26-
2717async def _is_admin (
2818 context : ContextTypes .DEFAULT_TYPE , chat_id : int , user_id : int
2919) -> bool :
@@ -81,7 +71,6 @@ async def _handle_force_group_registration(
8171async def _handle_ban (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
8272 """Ban a user globally. Usage: /ban user_id|@username [reason] or reply with /ban [reason]."""
8373 moderation_service : ModerationService = context .bot_data ["moderation_service" ]
84- repository : AsyncRepository = context .bot_data ["repository" ]
8574 message = update .message
8675 if message is None or message .from_user is None :
8776 return
@@ -90,9 +79,6 @@ async def _handle_ban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non
9079 if chat is None or chat .type == "private" :
9180 return
9281
93- # Track the invoking admin
94- await _track_user (repository , message .from_user )
95-
9682 if not await _is_admin (context , chat .id , message .from_user .id ):
9783 await message .reply_text (strings .ONLY_ADMINS )
9884 return
@@ -152,7 +138,6 @@ async def _handle_ban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non
152138async def _handle_unban (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
153139 """Unban a user globally. Usage: /unban user_id or reply to message with /unban."""
154140 moderation_service : ModerationService = context .bot_data ["moderation_service" ]
155- repository : AsyncRepository = context .bot_data ["repository" ]
156141 message = update .message
157142 if message is None or message .from_user is None :
158143 return
@@ -161,9 +146,6 @@ async def _handle_unban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
161146 if chat is None or chat .type == "private" :
162147 return
163148
164- # Track the invoking admin
165- await _track_user (repository , message .from_user )
166-
167149 if not await _is_admin (context , chat .id , message .from_user .id ):
168150 await message .reply_text (strings .ONLY_ADMINS )
169151 return
@@ -197,7 +179,6 @@ async def _handle_unban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
197179async def _handle_mute (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
198180 """Mute a user. Usage: /mute @username [duration_minutes] [reason]."""
199181 moderation_service : ModerationService = context .bot_data ["moderation_service" ]
200- repository : AsyncRepository = context .bot_data ["repository" ]
201182 message = update .message
202183 if message is None or message .from_user is None :
203184 return
@@ -206,9 +187,6 @@ async def _handle_mute(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
206187 if chat is None or chat .type == "private" :
207188 return
208189
209- # Track the invoking admin
210- await _track_user (repository , message .from_user )
211-
212190 if not await _is_admin (context , chat .id , message .from_user .id ):
213191 await message .reply_text (strings .ONLY_ADMINS )
214192 return
@@ -270,7 +248,6 @@ async def _handle_mute(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
270248async def _handle_unmute (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
271249 """Unmute a user. Usage: /unmute @username."""
272250 moderation_service : ModerationService = context .bot_data ["moderation_service" ]
273- repository : AsyncRepository = context .bot_data ["repository" ]
274251 message = update .message
275252 if message is None or message .from_user is None :
276253 return
@@ -279,9 +256,6 @@ async def _handle_unmute(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
279256 if chat is None or chat .type == "private" :
280257 return
281258
282- # Track the invoking admin
283- await _track_user (repository , message .from_user )
284-
285259 if not await _is_admin (context , chat .id , message .from_user .id ):
286260 await message .reply_text (strings .ONLY_ADMINS )
287261 return
@@ -329,7 +303,6 @@ async def _handle_unmute(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
329303async def _handle_report (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
330304 """Report a message or user. Usage: /report [reason] or reply to message with /report [reason]."""
331305 moderation_service : ModerationService = context .bot_data ["moderation_service" ]
332- repository : AsyncRepository = context .bot_data ["repository" ]
333306 message = update .message
334307 if message is None or message .from_user is None :
335308 return
@@ -338,9 +311,6 @@ async def _handle_report(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
338311 if chat is None or chat .type == "private" :
339312 return
340313
341- # Track the reporter
342- await _track_user (repository , message .from_user )
343-
344314 args = message .text .split (maxsplit = 1 )[1 :] if message .text else []
345315 reason = args [0 ] if args else None
346316
@@ -387,7 +357,6 @@ async def _handle_admin_mention(
387357 update : Update , context : ContextTypes .DEFAULT_TYPE
388358) -> None :
389359 """Handle @admin mention: notify admins of intervention request (no reply needed)."""
390- repository : AsyncRepository = context .bot_data ["repository" ]
391360 message = update .message
392361 if message is None or message .from_user is None :
393362 return
@@ -396,9 +365,6 @@ async def _handle_admin_mention(
396365 if chat is None or chat .type == "private" :
397366 return
398367
399- # Track the user
400- await _track_user (repository , message .from_user )
401-
402368 text = message .text or message .caption or ""
403369 reason = _extract_reason_after_admin (text )
404370
0 commit comments