Created
January 19, 2025 21:34
-
-
Save Dviros/5aa21446864b5b61e944b7a00a647d1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import time | |
| from colorama import Fore, Style | |
| # Replace with your bot token | |
| BOT_TOKEN = '<bot token here>' | |
| BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" | |
| # Function to make API requests | |
| def make_request(endpoint, params=None): | |
| url = f"{BASE_URL}/{endpoint}" | |
| response = requests.get(url, params=params) | |
| if response.status_code == 200: | |
| return response.json() | |
| else: | |
| print(Fore.RED + f"Error: {response.status_code} - {response.text}" + Style.RESET_ALL) | |
| return None | |
| # Get Bot Info | |
| def get_bot_info(): | |
| print(Fore.CYAN + "Fetching bot info..." + Style.RESET_ALL) | |
| response = make_request('getMe') | |
| print(Fore.YELLOW + "Bot Info:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Webhook Info | |
| def get_webhook_info(): | |
| print(Fore.CYAN + "Fetching webhook info..." + Style.RESET_ALL) | |
| response = make_request('getWebhookInfo') | |
| print(Fore.YELLOW + "Webhook Info:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Chat Info | |
| def get_chat_info(chat_id): | |
| print(Fore.CYAN + "Fetching chat info..." + Style.RESET_ALL) | |
| response = make_request('getChat', params={'chat_id': chat_id}) | |
| print(Fore.YELLOW + "Chat Info:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Chat Members Count | |
| def get_chat_members_count(chat_id): | |
| print(Fore.CYAN + "Fetching chat members count..." + Style.RESET_ALL) | |
| response = make_request('getChatMembersCount', params={'chat_id': chat_id}) | |
| print(Fore.YELLOW + "Chat Members Count:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Chat Administrators | |
| def get_chat_administrators(chat_id): | |
| print(Fore.CYAN + "Fetching chat administrators..." + Style.RESET_ALL) | |
| response = make_request('getChatAdministrators', params={'chat_id': chat_id}) | |
| print(Fore.YELLOW + "Chat Administrators:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Specific Chat Member Info | |
| def get_chat_member(chat_id, user_id): | |
| print(Fore.CYAN + f"Fetching info for user ID {user_id}..." + Style.RESET_ALL) | |
| response = make_request('getChatMember', params={'chat_id': chat_id, 'user_id': user_id}) | |
| print(Fore.YELLOW + f"Chat Member {user_id} Info:" + Style.RESET_ALL, response) | |
| return response | |
| # Get Profile Photo | |
| def get_chat_photo(file_id): | |
| print(Fore.CYAN + "Fetching chat profile photo..." + Style.RESET_ALL) | |
| response = make_request('getFile', params={'file_id': file_id}) | |
| if response and 'result' in response: | |
| file_path = response['result']['file_path'] | |
| print(Fore.YELLOW + "Downloading photo..." + Style.RESET_ALL) | |
| photo_url = f"https://api.telegram.org/file/bot{BOT_TOKEN}/{file_path}" | |
| photo_response = requests.get(photo_url) | |
| if photo_response.status_code == 200: | |
| with open("profile_photo.jpg", "wb") as file: | |
| file.write(photo_response.content) | |
| print(Fore.GREEN + "Profile photo downloaded as 'profile_photo.jpg'." + Style.RESET_ALL) | |
| else: | |
| print(Fore.RED + "Failed to download photo." + Style.RESET_ALL) | |
| else: | |
| print(Fore.RED + "No photo found." + Style.RESET_ALL) | |
| # Listen for Updates in a Loop | |
| def listen_for_updates(): | |
| print(Fore.CYAN + "Listening for updates..." + Style.RESET_ALL) | |
| offset = None | |
| while True: | |
| try: | |
| response = make_request('getUpdates', params={'offset': offset, 'timeout': 10}) | |
| if response and 'result' in response: | |
| for update in response['result']: | |
| offset = update['update_id'] + 1 | |
| print(Fore.GREEN + "New Update:" + Style.RESET_ALL, update) | |
| time.sleep(1) # Avoid flooding the API | |
| except KeyboardInterrupt: | |
| print(Fore.RED + "\nStopped listening for updates." + Style.RESET_ALL) | |
| break | |
| except Exception as e: | |
| print(Fore.RED + f"Error: {e}" + Style.RESET_ALL) | |
| break | |
| # Main Function | |
| def main(): | |
| # Fetch bot info | |
| get_bot_info() | |
| # Fetch webhook info | |
| get_webhook_info() | |
| # Fetch chat info dynamically from updates | |
| print(Fore.CYAN + "Fetching chat ID dynamically from updates..." + Style.RESET_ALL) | |
| updates = make_request('getUpdates') | |
| if updates and 'result' in updates and updates['result']: | |
| first_update = updates['result'][0] | |
| chat_id = first_update['message']['chat']['id'] | |
| print(Fore.GREEN + f"Dynamic Chat ID: {chat_id}" + Style.RESET_ALL) | |
| else: | |
| print(Fore.RED + "No updates found to fetch chat ID." + Style.RESET_ALL) | |
| return | |
| # Fetch chat details | |
| chat_info = get_chat_info(chat_id) | |
| # Extract profile photo file ID if it exists | |
| chat_photo_file_id = None | |
| if chat_info and 'result' in chat_info and 'photo' in chat_info['result']: | |
| chat_photo_file_id = chat_info['result']['photo']['big_file_id'] | |
| print(Fore.GREEN + f"Dynamic Profile Photo File ID: {chat_photo_file_id}" + Style.RESET_ALL) | |
| # Fetch administrators and creator info | |
| admins = get_chat_administrators(chat_id) | |
| creator_id = None | |
| if admins and 'result' in admins: | |
| for admin in admins['result']: | |
| if admin['status'] == 'creator': | |
| creator_id = admin['user']['id'] | |
| print(Fore.GREEN + f"Dynamic Creator ID: {creator_id}" + Style.RESET_ALL) | |
| break | |
| # Fetch creator details | |
| if creator_id: | |
| get_chat_member(chat_id, creator_id) | |
| # Download chat profile photo | |
| if chat_photo_file_id: | |
| get_chat_photo(chat_photo_file_id) | |
| # Fetch chat members count | |
| get_chat_members_count(chat_id) | |
| # Listen for updates | |
| listen_for_updates() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment