File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """ID handler: returns chat and user IDs."""
2+
3+ from telegram import Update
4+ from telegram .ext import CommandHandler , ContextTypes
5+
6+
7+ def create_id_handlers () -> list :
8+ """Create the /id command handler."""
9+ return [CommandHandler ("id" , _handle_id )]
10+
11+
12+ async def _handle_id (update : Update , context : ContextTypes .DEFAULT_TYPE ) -> None :
13+ """Reply with the current chat ID and user ID."""
14+ chat = update .effective_chat
15+ user = update .effective_user
16+ message = update .message
17+
18+ if chat is None or user is None or message is None :
19+ return
20+
21+ await message .reply_text (f"ID chat: { chat .id } \n ID utente: { user .id } " )
Original file line number Diff line number Diff line change 66
77from .config import Settings
88from .db import create_repository
9+ from .handlers .id import create_id_handlers
910from .handlers .moderation import create_moderation_handlers
1011from .handlers .spam import create_spam_handler
1112from .handlers .welcome import create_welcome_handlers
@@ -43,6 +44,8 @@ async def _post_init(application) -> None:
4344 application .add_handler (create_spam_handler (spam_detector ))
4445 for handler in create_moderation_handlers (moderation_service ):
4546 application .add_handler (handler )
47+ for handler in create_id_handlers ():
48+ application .add_handler (handler )
4649
4750
4851async def _post_shutdown (application ) -> None :
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def __init__(
2525 ) -> None :
2626 self ._max_messages_per_minute = max_messages_per_minute
2727 self ._duplicate_threshold_seconds = duplicate_threshold_seconds
28- self ._message_history : dict [int , list [datetime ]] = defaultdict (list )
28+ self ._message_history : dict [int , list [datetime ]] = defaultdict [ int , list [ datetime ]] (list )
2929 self ._last_message_text : dict [int , tuple [str , datetime ]] = {}
3030
3131 def _clean_old_entries (self , user_id : int ) -> None :
You can’t perform that action at this time.
0 commit comments