Add /id Telegram command for replied-to user ID lookup
This commit is contained in:
@@ -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: <a href=\"{profile_link}\">{display_name}</a>",
|
||||
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...")
|
||||
|
||||
Reference in New Issue
Block a user