from telegram import ChatType, ParseMode, TelegramError from telegram.utils.helpers import mention_html from telegram.ext import Updater import logging # Set up logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) # Initialize the updater and bot updater = Updater(token='6558743995:AAGASl5dAQKOiOEB_MSFi4TTja-uf-xXJls', use_context=True) bot = updater.bot def search_chats(query): results = bot.search_chats(query, limit=10) if results: for chat in results: chat_id = chat.id chat_type = chat.type chat_name = chat.title chat_link = f'https://t.me/{chat.username}' if chat.username else None if chat_type in [ChatType.GROUP, ChatType.SUPERGROUP, ChatType.CHANNEL]: message = f'Found {chat_type} - {chat_name}' if chat_link: message += f' (link)' message += f' - ID: {chat_id}' print(message) else: print("No chats found for the given query.") try: # Search chats by ID chat_id = int(input("Enter Chat ID: ")) try: chat = bot.get_chat(chat_id) search_chats(chat.title) except TelegramError: print("Invalid Chat ID.") # Search chats by name chat_name = input("Enter Chat Name: ") search_chats(chat_name) except ValueError: print("Invalid input. Please enter a number for Chat ID.") # Start the script updater.start_polling() updater.idle()