-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
312 lines (260 loc) · 13 KB
/
main.py
File metadata and controls
312 lines (260 loc) · 13 KB
1
2
3
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.tl.functions.messages import GetBotCallbackAnswerRequest
from telethon.tl.types import KeyboardButtonCallback
from telethon.tl.types import Message
from datetime import datetime, time as dt_time, timedelta
import random
import asyncio
import time
import json
with open('phone.json') as f:
phone = json.load(f)[str(random.randint(1, 25))]
api_id = input('api_id: ')
api_hash = input('api_hash: ')
mining = bool(int(input('Do you have mining (0 – no, 1 – yes): ')))
auto_withdrawal = bool(int(input('Auto-withdrawal (0 – no, 1 – yes): ')))
client = TelegramClient(session='session1', api_id=int(api_id), api_hash=api_hash, system_version="4.16.30-vxCUSTOM",
device_model=phone, app_version='Telegram Android 10.14.5',
system_lang_code='en', lang_code='en')
# Delays for random selection
click_delay = [i / 1000000 for i in range(650000, 1000000)] + [i / 1000000 for i in range(1950000, 2130000)]
check_balance = [i / 1000000 for i in range(1110000, 1500000)]
# ID bot
id_bot_touch = '@gramTouchBot'
# Global variables for process control
new_day = True
login_to_the_game = 0 # number of inputs
now_time = 0 # first click time
max_click = 0 # max number of clicks, depends on the limit and the number of inputs
quantity_click = 0 # number of clicks that were made
max_hours_wait = 16_200 # max waiting time between entries 4.5 hours
# lock = asyncio.Lock() # global lock object
async def auto_balance_withdrawal(chat_id) -> None:
last_message = await get_last_message(client, chat_id)
await asyncio.sleep(random.uniform(1.9, 3.5))
await click_button(client, chat_id, last_message, 'Биржа')
await asyncio.sleep(random.uniform(1.9, 3.5))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, 'Продать')
await asyncio.sleep(random.uniform(5, 12))
last_message = await get_last_message(client, chat_id)
balance = last_message.message.split('\n')[7].split()[1]
balance = balance[:len(balance.split('.')[0]) + 2]
await client.send_message(chat_id, balance)
await asyncio.sleep(random.uniform(3, 5))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, 'Обменять')
await asyncio.sleep(random.uniform(4, 7))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, "◀")
await asyncio.sleep(random.uniform(6, 14))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, 'Профиль')
await asyncio.sleep(random.uniform(1.8, 3))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, 'Вывести')
await asyncio.sleep(random.uniform(5, 9))
last_message = await get_last_message(client, chat_id)
balance = last_message.message.split('\n')[4].split()[1]
balance = balance[:len(balance.split('.')[0]) + 2]
await client.send_message(chat_id, balance)
async def wait_until_morning() -> None:
current_time = datetime.now().time()
if dt_time(2, 0) <= current_time < dt_time(7, 0):
sleep_until = datetime.combine(datetime.today(), dt_time(7, 0))
sleep_duration = (sleep_until - datetime.now()).total_seconds() + random.uniform(2700, 18000)
print(f"The script is on standby until the morning. Waiting time: {sleep_duration / 3600:.2f} hours.")
await asyncio.sleep(sleep_duration)
async def collections_mining(chat_id: str):
last_message = await get_last_message(client, chat_id)
await asyncio.sleep(random.uniform(1.9, 3.3))
await click_button(client, chat_id, last_message, "Майнинг")
await asyncio.sleep(random.uniform(1.5, 2.8))
last_message = await get_last_message(client, chat_id)
await click_button(client, chat_id, last_message, "Собрать")
await asyncio.sleep(random.uniform(1.8, 3))
last_message = await get_last_message(client, chat_id)
# print(last_message)
await click_button(client, chat_id, last_message, "◀")
await asyncio.sleep(random.uniform(1.5, 2.8))
with open("log_for_mining.txt", "a") as log_file:
log_file.write(f"{datetime.now()} - Function executed for client: {(await client.get_me()).phone} "
f"– {(await client.get_me()).username}\n")
async def time_based_task(chat_id: str):
while True:
now = datetime.now()
current_time = now.time()
# If the current time is between 12:00 am and 2:00 am and the task has not yet completed
if dt_time(0, 0) <= current_time <= dt_time(2, 0):
sleep_duration = random.uniform(0, 2 * 3600) # случайное время между 0 и 2 часами
await asyncio.sleep(sleep_duration)
await collections_mining(chat_id)
if int(str(current_time)[4:5]) % 2 == 0 and auto_withdrawal:
await auto_balance_withdrawal(chat_id)
# Set the next execution between 7:00 AM and 8:00 AM
next_run = datetime.combine(now.date(), dt_time(7, 0))
sleep_duration = (next_run - now).total_seconds()
print(f"Script on standby until {next_run}. Waiting time: {sleep_duration / 3600:.2f} hours.")
await asyncio.sleep(sleep_duration)
continue
# If the current time is between 7:00 AM and 8:00 AM and the task has not yet completed
elif dt_time(7, 0) <= current_time < dt_time(8, 0):
sleep_duration = random.uniform(0, 3600) # случайное время между 0 и 1 часом
await asyncio.sleep(sleep_duration)
await collections_mining(chat_id)
# We set the next execution for the next approach between 8:30 and 19:00
next_run = datetime.combine(now.date(), dt_time(8, 30))
sleep_duration = (next_run - now).total_seconds()
print(f"Script on standby until {next_run}. Waiting time: {sleep_duration / 3600:.2f} hours.")
await asyncio.sleep(sleep_duration)
continue
# If the current time is between 8:30 AM and 19:00 PM
elif dt_time(8, 30) <= current_time < dt_time(19, 0):
sleep_duration = random.uniform(1.5 * 3600, 2 * 3600) # случайное время между 1.5 и 5 часами
await asyncio.sleep(sleep_duration)
now = datetime.now() # Update the current time after waiting
current_time = now.time()
if dt_time(8, 30) <= current_time < dt_time(19, 0):
await collections_mining(chat_id)
# If the current time is after 19:00 and before 23:59
if dt_time(19, 0) <= current_time < dt_time(23, 59):
await collections_mining(chat_id)
next_run = datetime.combine(now.date() + timedelta(days=1), dt_time(0, 0))
else:
# Time delay until next start in the range 8:30 - 19:00
sleep_duration = random.uniform(1.5 * 3600, 5 * 3600)
print(f"The script is in standby mode until the next launch in the range 8:30 - 19:00. "
f"Waiting time: {sleep_duration / 3600:.2f} hours.")
await asyncio.sleep(sleep_duration)
continue
sleep_duration = (next_run - now).total_seconds()
print(f"Script on standby until {next_run}. Waiting time: {sleep_duration / 3600:.2f} hours.")
await asyncio.sleep(sleep_duration)
async def get_last_message(client: TelegramClient, chat_id: str) -> Message:
history = await client(GetHistoryRequest(
peer=chat_id,
limit=1,
offset_date=None,
offset_id=0,
max_id=0,
min_id=0,
add_offset=0,
hash=0
))
if (len(history.messages[0].message.split('\n')) == 1 or not history.messages
or 'успешно выведены!' in history.messages[0].message or not history.messages[0].reply_markup):
await client.send_message(chat_id, '/start')
await asyncio.sleep(random.uniform(1, 3))
history = await client(GetHistoryRequest(
peer=chat_id,
limit=1,
offset_date=None,
offset_id=0,
max_id=0,
min_id=0,
add_offset=0,
hash=0
))
return history.messages[0]
async def click_button(client: TelegramClient, chat_id: str, last_message: Message, text='Клик!') -> None:
try:
if last_message.reply_markup:
for button_row in last_message.reply_markup.rows:
for button in button_row.buttons:
if isinstance(button, KeyboardButtonCallback) and text in button.text:
client.loop.create_task(
client(GetBotCallbackAnswerRequest(
peer=chat_id,
msg_id=last_message.id,
data=button.data
))
)
print(f"Click button: {button.text}")
except Exception as error:
print(f"The bot did not answer to the callback query in time: {error}")
async def calculate_limits(chat_id) -> tuple:
last_message: Message = await get_last_message(client, chat_id)
limit = int(last_message.message.split('\n')[4].split('/')[1])
if limit in [300, 350, 400]:
login_to_the_game = random.randint(1, 2)
else:
login_to_the_game = random.randint(2, 4)
max_click = limit // login_to_the_game
if login_to_the_game == 1:
quantity_click = limit
else:
quantity_click = random.randint(max_click // 100 * 75, max_click)
return limit, login_to_the_game, max_click, quantity_click
async def click_button_until_limit(chat_id: str) -> None:
global new_day, login_to_the_game, now_time, max_click, quantity_click, max_hours_wait, limit, collections
logging = 0
click = 0
while True:
await wait_until_morning()
last_message = await get_last_message(client, chat_id)
if last_message is None:
break
if new_day:
new_day = False
now_time = time.time()
collections = True
await collections_mining(chat_id)
await click_button(client, chat_id, last_message)
delay = random.choice(click_delay)
print(f"Delay: {delay} seconds")
await asyncio.sleep(delay)
last_message = await get_last_message(client, chat_id)
limit, login_to_the_game, max_click, quantity_click = await calculate_limits(chat_id)
print(
f"A new day has begun. Limit: {limit}, Number of logins: {login_to_the_game}, "
f"Max clicks per login: {max_click}")
with open("log_for_click.txt", "a") as log_file:
log_file.write(f"{datetime.now()} - New day, number of inputs = {login_to_the_game}. "
f"For client: {(await client.get_me()).phone} – {(await client.get_me()).username}\n")
if "Лимит: 0" in last_message.message:
new_day = True
click = 1
collections = True
print("The limit has been reached.")
times = 86400 - (int(str(time.time()).split('.')[0]) - int(str(now_time).split('.')[0]))
await asyncio.sleep(random.uniform(times, times + 10_821))
continue
if logging != login_to_the_game:
if (not collections) and mining:
collections = True
await collections_mining(chat_id)
await click_button(client, chat_id, last_message)
click += 1
if click >= quantity_click and limit != 1:
click = 0
logging += 1
collections = False
quantity_click = random.randint(max_click // 100 * 65, max_click)
await asyncio.sleep(random.uniform(1801, max_hours_wait))
else:
delay = random.choice(click_delay)
print(f"Delay: {delay} seconds")
await asyncio.sleep(delay)
else:
if (not collections) and mining:
collections = True
await collections_mining(chat_id)
await click_button(client, chat_id, last_message)
delay = random.choice(click_delay)
print(f"Delay: {delay} seconds")
await asyncio.sleep(delay)
async def main() -> None:
# Enter chat ID
chat_id: str = id_bot_touch
# Opening the connection
client.start()
if mining:
# Running tasks
task1 = asyncio.create_task(click_button_until_limit(chat_id))
task2 = asyncio.create_task(time_based_task(chat_id))
await asyncio.gather(task1, task2)
else:
await click_button_until_limit(chat_id)
with client:
client.loop.run_until_complete(main())