From 854d5a9d56a3b4cc221b32d2b7eb98eba840cbdc Mon Sep 17 00:00:00 2001 From: Thomas Kerpe Date: Wed, 10 Jun 2026 17:29:26 +0200 Subject: [PATCH] Add /id Telegram command for replied-to user ID lookup --- bot.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bot.py b/bot.py index c02be63..727ae83 100644 --- a/bot.py +++ b/bot.py @@ -197,6 +197,35 @@ class MonitoringBot: """Verarbeitet den /start Befehl.""" await update.message.reply_text("Monitoring-Bot ist online und protokolliert Aktivitäten.") + async def id_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Verarbeitet den /id Befehl und gibt die User-ID des replied-to Users zurück.""" + if not update.message: + return + + reply = update.message.reply_to_message + if not reply or not reply.from_user: + await update.message.reply_text( + "Bitte antworte mit /id auf die Nachricht der Person, deren User-ID du wissen möchtest." + ) + return + + target_user = reply.from_user + user_id = target_user.id + username = getattr(target_user, 'username', None) + display_name = target_user.full_name or username or str(user_id) + + profile_link = None + if username: + profile_link = f"https://t.me/{username}" + else: + profile_link = f"tg://user?id={user_id}" + + await update.message.reply_text( + f"User-ID: `{user_id}`\n" + f"Profil: {display_name}", + parse_mode='HTML' + ) + # --- HILFSFUNKTIONEN ZUR TOPIC-ERKENNUNG --- def _get_topic_id(self, update: Update) -> str: """Extrahiert die Topic ID aus dem Update (Topic Aware). @@ -431,6 +460,7 @@ class MonitoringBot: # Handlers registrieren application.add_handler(CommandHandler("start", self.start_command)) + application.add_handler(CommandHandler("id", self.id_command)) application.add_handler(MessageHandler(filters.ALL & ~filters.COMMAND, self.handle_message)) print("🤖 Bot wird gestartet. Warte auf Updates...")