|
|
|
|
|
from telethon import events, TelegramClient |
|
import os |
|
import asyncio |
|
|
|
|
|
API_ID = 28241554 |
|
API_HASH = '1d923a19f2c518a255b0623cd7674662' |
|
USER_ID = 8135073992 |
|
YOUR_USERNAME = "@D3AGE" |
|
|
|
|
|
guessSolver = TelegramClient('saitama/temp', API_ID, API_HASH) |
|
|
|
|
|
CHAT_ID = -1002423849589 |
|
|
|
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) |
|
except Exception as e: |
|
print(f"Error occurred while sending /guess: {e}") |
|
await notify_user(f"Error occurred while sending /guess: {e}") |
|
await asyncio.sleep(10) |
|
|
|
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.") |
|
|
|
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] |
|
|
|
|
|
if not hasattr(event, "name_sent"): |
|
await guessSolver.send_message(chat, pokemon_name) |
|
await asyncio.sleep(10) |
|
await guessSolver.send_message(chat, "/guess") |
|
|
|
|
|
event.name_sent = True |
|
break |
|
|
|
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}") |
|
|
|
|
|
async def main(): |
|
try: |
|
await guessSolver.start() |
|
print("Bot is running.") |
|
|
|
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}") |
|
|
|
|
|
asyncio.run(main()) |
|
|