Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
- from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, ContextTypes
- from telethon import TelegramClient
- from telethon.errors import UserPrivacyRestrictedError
- from telethon.tl.types import (
- UserStatusOnline,
- UserStatusOffline,
- UserStatusRecently,
- UserStatusLastWeek,
- UserStatusLastMonth
- )
- from datetime import timezone
- BOT_TOKEN = "TU-TOKEN"
- api_id = TU-ID
- api_hash = "TU-API"
- usuarios_monitoreo = [
- "@berny_op",
- "@mrban01",
- "@iBuriedmyGlock",
- "@PanchoVillaALV",
- "@PantMr",
- "@josehackeos",
- "@johnhacc"
- ]
- telethon_client = TelegramClient("session", api_id, api_hash)
- # ==================
- def estado_legible(status):
- if isinstance(status, UserStatusOnline):
- return "🟢 EN LÍNEA"
- elif isinstance(status, UserStatusOffline):
- local = status.was_online.astimezone()
- utc = status.was_online.astimezone(timezone.utc)
- return (
- "🔴 ÚLTIMA VEZ:\n"
- f"UTC: {utc}\n"
- f"LOCAL: {local.strftime('%Y-%m-%d %H:%M:%S')}"
- )
- elif isinstance(status, UserStatusRecently):
- return "🟡 VISTO RECIENTEMENTE"
- elif isinstance(status, UserStatusLastWeek):
- return "🟠 VISTO ÚLTIMA SEMANA"
- elif isinstance(status, UserStatusLastMonth):
- return "🔵 VISTO ÚLTIMO MES"
- elif status is None:
- return "⚫ VISTO POR ÚLTIMA VEZ HACE MUCHO TIEMPO\n⚠️ Posible privacidad restringida o bloqueo"
- else:
- return "⚫ ESTADO DESCONOCIDO"
- # ---------- START ----------
- async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
- keyboard = [
- [InlineKeyboardButton("🔎 Ver conexión", callback_data="ver_conexion")]
- ]
- reply_markup = InlineKeyboardMarkup(keyboard)
- await update.message.reply_text(
- "🤖 Bot de monitoreo de estados\n\n"
- "Consulta la última conexión de los usuarios configurados.\n"
- "Detecta posibles restricciones de privacidad.",
- reply_markup=reply_markup
- )
- # ---------- BOTÓN ----------
- async def boton(update: Update, context: ContextTypes.DEFAULT_TYPE):
- query = update.callback_query
- await query.answer()
- resultado = "📡 Estado actual:\n\n"
- for username in usuarios_monitoreo:
- try:
- entity = await telethon_client.get_entity(username)
- estado = estado_legible(entity.status)
- resultado += f"{username}\n{estado}\n\n"
- except UserPrivacyRestrictedError:
- resultado += (
- f"{username}\n"
- "⚠️ PRIVACIDAD RESTRINGIDA\n"
- "No se puede obtener información de estado.\n\n"
- )
- except Exception as e:
- resultado += f"{username} → ERROR: {str(e)}\n\n"
- await query.edit_message_text(resultado)
- # ---------- MAIN ----------
- def main():
- app = ApplicationBuilder().token(BOT_TOKEN).build()
- app.add_handler(CommandHandler("start", start))
- app.add_handler(CallbackQueryHandler(boton))
- telethon_client.start()
- print("🤖 Bot iniciado correctamente...")
- app.run_polling()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment