Update guess/main.py
Browse files- guess/main.py +104 -50
guess/main.py
CHANGED
@@ -1,50 +1,104 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#telegram = @tfdrag
|
2 |
+
|
3 |
+
from telethon import events, TelegramClient
|
4 |
+
import os
|
5 |
+
import asyncio
|
6 |
+
|
7 |
+
# API credentials for your Telegram bot
|
8 |
+
API_ID = 28241554 # Replace with your API_ID
|
9 |
+
API_HASH = '1d923a19f2c518a255b0623cd7674662' # Replace with your API_HASH
|
10 |
+
USER_ID = 8135073992 # Replace with your Telegram user ID (you can get this using the previous steps)
|
11 |
+
YOUR_USERNAME = "@D3AGE" # Replace with your Telegram username (optional)
|
12 |
+
|
13 |
+
# Initialize the Telegram client
|
14 |
+
guessSolver = TelegramClient('saitama/temp', API_ID, API_HASH)
|
15 |
+
|
16 |
+
# Replace with the chat ID of the group or channel where you want to send /guess
|
17 |
+
CHAT_ID = -1002423849589 # Change this to the target chat ID
|
18 |
+
|
19 |
+
from telethon.tl.types import PhotoStrippedSize
|
20 |
+
|
21 |
+
async def send_guess_continuously():
|
22 |
+
"""Continuously sends /guess messages to the specified chat."""
|
23 |
+
while True:
|
24 |
+
try:
|
25 |
+
await guessSolver.send_message(entity=CHAT_ID, message='/guess')
|
26 |
+
await asyncio.sleep(300) # Wait 5 minutes before sending the next /guess
|
27 |
+
except Exception as e:
|
28 |
+
print(f"Error occurred while sending /guess: {e}")
|
29 |
+
await notify_user(f"Error occurred while sending /guess: {e}") # Send the error to your personal account
|
30 |
+
await asyncio.sleep(10) # Retry after 10 seconds
|
31 |
+
|
32 |
+
async def notify_user(message):
|
33 |
+
"""Sends error logs directly to your personal Telegram account."""
|
34 |
+
try:
|
35 |
+
await guessSolver.send_message(USER_ID, f"Hey {YOUR_USERNAME}, {message}")
|
36 |
+
except Exception as e:
|
37 |
+
print(f"Error in sending notification to user: {e}")
|
38 |
+
|
39 |
+
@guessSolver.on(events.NewMessage(from_users=5289069294, pattern=r".bin", outgoing=True))
|
40 |
+
async def handle_bin_command(event):
|
41 |
+
"""Handles .bin command and starts the /guess loop."""
|
42 |
+
print("Received .bin command. Starting to send /guess.")
|
43 |
+
# Start sending /guess messages continuously
|
44 |
+
asyncio.create_task(send_guess_continuously())
|
45 |
+
|
46 |
+
@guessSolver.on(events.NewMessage(from_users=572621020, pattern="Who's that pokemon?", chats=CHAT_ID, incoming=True))
|
47 |
+
async def handle_pokemon_question(event):
|
48 |
+
"""Handles the 'Who's that pokemon?' message and guesses the pokemon."""
|
49 |
+
try:
|
50 |
+
for size in event.message.photo.sizes:
|
51 |
+
if isinstance(size, PhotoStrippedSize):
|
52 |
+
size_str = str(size)
|
53 |
+
for file in os.listdir("cache/"):
|
54 |
+
with open(f"cache/{file}", 'r') as f:
|
55 |
+
file_content = f.read()
|
56 |
+
if file_content == size_str:
|
57 |
+
chat = await event.get_chat()
|
58 |
+
pokemon_name = file.split(".txt")[0]
|
59 |
+
|
60 |
+
# Check if the name has been sent before
|
61 |
+
if not hasattr(event, "name_sent"):
|
62 |
+
await guessSolver.send_message(chat, pokemon_name)
|
63 |
+
await asyncio.sleep(10) # Add delay to avoid duplicate sends
|
64 |
+
await guessSolver.send_message(chat, "/guess")
|
65 |
+
|
66 |
+
# Mark the name as sent to prevent duplication in the future
|
67 |
+
event.name_sent = True
|
68 |
+
break
|
69 |
+
# Write the new size to cache.txt
|
70 |
+
with open("saitama/cache.txt", 'w') as temp_file:
|
71 |
+
temp_file.write(size_str)
|
72 |
+
except Exception as e:
|
73 |
+
print(f"Error in handling pokemon question: {e}")
|
74 |
+
await notify_user(f"Error in handling pokemon question: {e}")
|
75 |
+
|
76 |
+
@guessSolver.on(events.NewMessage(from_users=572621020, pattern="The pokemon was ", chats=CHAT_ID))
|
77 |
+
async def handle_correct_pokemon(event):
|
78 |
+
"""Handles the message when the correct pokemon is revealed."""
|
79 |
+
try:
|
80 |
+
pokemon_name = (event.message.text.split("The pokemon was **")[1]).split("**")[0]
|
81 |
+
with open(f"cache/{pokemon_name}.txt", 'w') as cache_file:
|
82 |
+
with open("saitama/cache.txt", 'r') as temp_file:
|
83 |
+
cache_file.write(temp_file.read())
|
84 |
+
os.remove("saitama/cache.txt")
|
85 |
+
chat = await event.get_chat()
|
86 |
+
await guessSolver.send_message(chat, "/guess")
|
87 |
+
except Exception as e:
|
88 |
+
print(f"Error in handling correct pokemon: {e}")
|
89 |
+
await notify_user(f"Error in handling correct pokemon: {e}")
|
90 |
+
|
91 |
+
# Start the client and run
|
92 |
+
async def main():
|
93 |
+
try:
|
94 |
+
await guessSolver.start()
|
95 |
+
print("Bot is running.")
|
96 |
+
# Start the continuous /guess sending loop at startup
|
97 |
+
asyncio.create_task(send_guess_continuously())
|
98 |
+
await guessSolver.run_until_disconnected()
|
99 |
+
except Exception as e:
|
100 |
+
print(f"Error starting the bot: {e}")
|
101 |
+
await notify_user(f"Error starting the bot: {e}")
|
102 |
+
|
103 |
+
# Run the bot
|
104 |
+
asyncio.run(main())
|