dragxd commited on
Commit
148b9e6
·
verified ·
1 Parent(s): 1f31a19

Update guess/main.py

Browse files
Files changed (1) hide show
  1. guess/main.py +104 -50
guess/main.py CHANGED
@@ -1,50 +1,104 @@
1
- from telethon import events, TelegramClient
2
- import os
3
- import asyncio
4
-
5
- api_id = 26471869
6
- api_hash = '0a368c9793d89946fbb539ef3bd21aa7'
7
- guessSolver = TelegramClient('saitama/temp', api_id, api_hash)
8
- chatid = -1002337182058 #change
9
- from telethon.tl.types import PhotoStrippedSize
10
- @guessSolver.on(events.NewMessage(from_users=5289069294, pattern=".bin",outgoing=True))
11
- async def guesser(event):
12
- await guessSolver.send_message(entity=chatid,message='/guess')
13
- for i in range(1,3000):
14
- await asyncio.sleep(300)
15
- await guessSolver.send_message(entity=chatid,message='/guess')
16
- @guessSolver.on(events.NewMessage(from_users=572621020, pattern="Who's that pokemon?",chats=(int(chatid)),incoming=True))
17
- async def guesser(event):
18
- for size in event.message.photo.sizes:
19
- if isinstance(size, PhotoStrippedSize):
20
- size = str(size)
21
- for file in (os.listdir("cache/")):
22
- with open(f"cache/{file}", 'r') as f:
23
- file_content = f.read()
24
- if file_content == size:
25
- chat = await event.get_chat()
26
- Msg = file.split(".txt")[0]
27
- await guessSolver.send_message(chat,Msg)
28
- await asyncio.sleep(10)
29
- await guessSolver.send_message(chat,"/guess")
30
- break
31
- with open("saitama/cache.txt", 'w') as file:
32
- file.write(size)
33
- file.close()
34
-
35
- @guessSolver.on(events.NewMessage(from_users=572621020, pattern="The pokemon was ",chats=int(chatid)))
36
- async def guesser(event):
37
- massage = ((event.message.text).split("The pokemon was **")[1]).split("**")[0]
38
- with open(f"cache/{massage}.txt", 'w') as file:
39
- with open("saitama/cache.txt",'r') as inf:
40
- cont = inf.read()
41
- file.write(cont)
42
- inf.close()
43
- file.close()
44
- os.remove("saitama/cache.txt")
45
- chat = await event.get_chat()
46
- await guessSolver.send_message(chat, "/guess")
47
-
48
-
49
- guessSolver.start()
50
- guessSolver.run_until_disconnected()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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())