IvanCastl

Telegram-estado

Feb 19th, 2026
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | Cybersecurity | 0 0
  1. from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
  2. from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, ContextTypes
  3. from telethon import TelegramClient
  4. from telethon.errors import UserPrivacyRestrictedError
  5. from telethon.tl.types import (
  6.     UserStatusOnline,
  7.     UserStatusOffline,
  8.     UserStatusRecently,
  9.     UserStatusLastWeek,
  10.     UserStatusLastMonth
  11. )
  12. from datetime import timezone
  13.  
  14. BOT_TOKEN = "TU-TOKEN"
  15. api_id = TU-ID
  16. api_hash = "TU-API"
  17.  
  18. usuarios_monitoreo = [
  19.     "@berny_op",
  20.     "@mrban01",
  21.     "@iBuriedmyGlock",
  22.     "@PanchoVillaALV",
  23.     "@PantMr",
  24.     "@josehackeos",
  25.     "@johnhacc"
  26.  
  27. ]
  28.  
  29. telethon_client = TelegramClient("session", api_id, api_hash)
  30. # ==================
  31.  
  32.  
  33. def estado_legible(status):
  34.     if isinstance(status, UserStatusOnline):
  35.         return "🟢 EN LÍNEA"
  36.  
  37.     elif isinstance(status, UserStatusOffline):
  38.         local = status.was_online.astimezone()
  39.         utc = status.was_online.astimezone(timezone.utc)
  40.         return (
  41.             "🔴 ÚLTIMA VEZ:\n"
  42.             f"UTC: {utc}\n"
  43.             f"LOCAL: {local.strftime('%Y-%m-%d %H:%M:%S')}"
  44.         )
  45.  
  46.     elif isinstance(status, UserStatusRecently):
  47.         return "🟡 VISTO RECIENTEMENTE"
  48.  
  49.     elif isinstance(status, UserStatusLastWeek):
  50.         return "🟠 VISTO ÚLTIMA SEMANA"
  51.  
  52.     elif isinstance(status, UserStatusLastMonth):
  53.         return "🔵 VISTO ÚLTIMO MES"
  54.  
  55.     elif status is None:
  56.         return "⚫ VISTO POR ÚLTIMA VEZ HACE MUCHO TIEMPO\n⚠️ Posible privacidad restringida o bloqueo"
  57.  
  58.     else:
  59.         return "⚫ ESTADO DESCONOCIDO"
  60.  
  61.  
  62. # ---------- START ----------
  63. async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
  64.     keyboard = [
  65.         [InlineKeyboardButton("🔎 Ver conexión", callback_data="ver_conexion")]
  66.     ]
  67.     reply_markup = InlineKeyboardMarkup(keyboard)
  68.  
  69.     await update.message.reply_text(
  70.         "🤖 Bot de monitoreo de estados\n\n"
  71.         "Consulta la última conexión de los usuarios configurados.\n"
  72.         "Detecta posibles restricciones de privacidad.",
  73.         reply_markup=reply_markup
  74.     )
  75.  
  76.  
  77. # ---------- BOTÓN ----------
  78. async def boton(update: Update, context: ContextTypes.DEFAULT_TYPE):
  79.     query = update.callback_query
  80.     await query.answer()
  81.  
  82.     resultado = "📡 Estado actual:\n\n"
  83.  
  84.     for username in usuarios_monitoreo:
  85.         try:
  86.             entity = await telethon_client.get_entity(username)
  87.             estado = estado_legible(entity.status)
  88.             resultado += f"{username}\n{estado}\n\n"
  89.  
  90.         except UserPrivacyRestrictedError:
  91.             resultado += (
  92.                 f"{username}\n"
  93.                 "⚠️ PRIVACIDAD RESTRINGIDA\n"
  94.                 "No se puede obtener información de estado.\n\n"
  95.             )
  96.  
  97.         except Exception as e:
  98.             resultado += f"{username} → ERROR: {str(e)}\n\n"
  99.  
  100.     await query.edit_message_text(resultado)
  101.  
  102.  
  103. # ---------- MAIN ----------
  104. def main():
  105.     app = ApplicationBuilder().token(BOT_TOKEN).build()
  106.  
  107.     app.add_handler(CommandHandler("start", start))
  108.     app.add_handler(CallbackQueryHandler(boton))
  109.  
  110.     telethon_client.start()
  111.  
  112.     print("🤖 Bot iniciado correctamente...")
  113.     app.run_polling()
  114.  
  115.  
  116. if __name__ == "__main__":
  117.     main()
Advertisement
Add Comment
Please, Sign In to add comment