Download Telegram.py from Maddyroy/Python: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/Maddyroy/Python/resolve/main/Telegram.py
- Command line
-
hf download hf://Maddyroy/Python/Telegram.py
-
curl -L -o Telegram.py https://huggingface.co/Maddyroy/Python/resolve/main/Telegram.py
1.6 kB
| 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} - <b>{chat_name}</b>' | |
| if chat_link: | |
| message += f' (<a href="{chat_link}">link</a>)' | |
| message += f' - ID: <code>{chat_id}</code>' | |
| 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() |