#telegram = @tfdrag from telethon import events, TelegramClient import os import asyncio # API credentials for your Telegram bot API_ID = 28241554 # Replace with your API_ID API_HASH = '1d923a19f2c518a255b0623cd7674662' # Replace with your API_HASH USER_ID = 8135073992 # Replace with your Telegram user ID (you can get this using the previous steps) YOUR_USERNAME = "@D3AGE" # Replace with your Telegram username (optional) # Initialize the Telegram client guessSolver = TelegramClient('saitama/temp', API_ID, API_HASH) # Replace with the chat ID of the group or channel where you want to send /guess CHAT_ID = -1002423849589 # Change this to the target chat ID from telethon.tl.types import PhotoStrippedSize async def send_guess_continuously(): """Continuously sends /guess messages to the specified chat.""" while True: try: await guessSolver.send_message(entity=CHAT_ID, message='/guess') await asyncio.sleep(300) # Wait 5 minutes before sending the next /guess except Exception as e: print(f"Error occurred while sending /guess: {e}") await notify_user(f"Error occurred while sending /guess: {e}") # Send the error to your personal account await asyncio.sleep(10) # Retry after 10 seconds async def notify_user(message): """Sends error logs directly to your personal Telegram account.""" try: await guessSolver.send_message(USER_ID, f"Hey {YOUR_USERNAME}, {message}") except Exception as e: print(f"Error in sending notification to user: {e}") @guessSolver.on(events.NewMessage(from_users=5289069294, pattern=r".bin", outgoing=True)) async def handle_bin_command(event): """Handles .bin command and starts the /guess loop.""" print("Received .bin command. Starting to send /guess.") # Start sending /guess messages continuously asyncio.create_task(send_guess_continuously()) @guessSolver.on(events.NewMessage(from_users=572621020, pattern="Who's that pokemon?", chats=CHAT_ID, incoming=True)) async def handle_pokemon_question(event): """Handles the 'Who's that pokemon?' message and guesses the pokemon.""" try: for size in event.message.photo.sizes: if isinstance(size, PhotoStrippedSize): size_str = str(size) for file in os.listdir("cache/"): with open(f"cache/{file}", 'r') as f: file_content = f.read() if file_content == size_str: chat = await event.get_chat() pokemon_name = file.split(".txt")[0] # Check if the name has been sent before if not hasattr(event, "name_sent"): await guessSolver.send_message(chat, pokemon_name) await asyncio.sleep(10) # Add delay to avoid duplicate sends await guessSolver.send_message(chat, "/guess") # Mark the name as sent to prevent duplication in the future event.name_sent = True break # Write the new size to cache.txt with open("saitama/cache.txt", 'w') as temp_file: temp_file.write(size_str) except Exception as e: print(f"Error in handling pokemon question: {e}") await notify_user(f"Error in handling pokemon question: {e}") @guessSolver.on(events.NewMessage(from_users=572621020, pattern="The pokemon was ", chats=CHAT_ID)) async def handle_correct_pokemon(event): """Handles the message when the correct pokemon is revealed.""" try: pokemon_name = (event.message.text.split("The pokemon was **")[1]).split("**")[0] with open(f"cache/{pokemon_name}.txt", 'w') as cache_file: with open("saitama/cache.txt", 'r') as temp_file: cache_file.write(temp_file.read()) os.remove("saitama/cache.txt") chat = await event.get_chat() await guessSolver.send_message(chat, "/guess") except Exception as e: print(f"Error in handling correct pokemon: {e}") await notify_user(f"Error in handling correct pokemon: {e}") # Start the client and run async def main(): try: await guessSolver.start() print("Bot is running.") # Start the continuous /guess sending loop at startup asyncio.create_task(send_guess_continuously()) await guessSolver.run_until_disconnected() except Exception as e: print(f"Error starting the bot: {e}") await notify_user(f"Error starting the bot: {e}") # Run the bot asyncio.run(main())