-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
483 lines (381 loc) · 18.1 KB
/
Copy pathbot.py
File metadata and controls
483 lines (381 loc) · 18.1 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
import asyncio
import aiohttp
import json
import os
import sys
import signal
import random
import string
from colorama import Fore, Style, init
init(autoreset=True)
from utils.banner import show_banner
MY_PROJECT = "GDrop App"
G = Fore.GREEN + Style.BRIGHT
Y = Fore.YELLOW + Style.BRIGHT
R = Fore.RED + Style.BRIGHT
BASE_URL = "https://modapkam.shop/api"
HEADERS_BASE = {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/json",
"origin": "https://modapkam.shop",
"pragma": "no-cache",
"priority": "u=1, i",
"referer": "https://modapkam.shop/?tgWebAppStartParam=r6004380466",
"sec-ch-ua": '"Chromium";v="151", "Not=A?Brand";v="99", "Microsoft Edge WebView2";v="151", "Microsoft Edge";v="151"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 Edg/151.0.0.0",
}
def generate_device_id() -> str:
chars = string.ascii_lowercase + string.digits
return "".join(random.choices(chars, k=25))
def mask_ip(ip: str) -> str:
parts = ip.split(".")
if len(parts) == 4:
return f"{parts[0]}*****{parts[3]}"
return ip
def format_proxy_log(proxy: str) -> str:
try:
without_scheme = proxy.split("://", 1)[1]
credentials, hostpart = without_scheme.rsplit("@", 1)
host = hostpart.split(":")[0]
port = hostpart.split(":")[1] if ":" in hostpart else ""
masked = mask_ip(host)
return f"http://user:pass@{masked}:{port}"
except Exception:
return "http://user:pass@*****"
def load_initdata() -> list:
if not os.path.exists("data.txt"):
print(R + "File data.txt not found")
sys.exit(1)
with open("data.txt", "r") as f:
lines = [l.strip() for l in f if l.strip()]
if not lines:
print(R + "File data.txt is empty")
sys.exit(1)
return lines
def load_proxies() -> list:
if not os.path.exists("proxy.txt"):
return []
with open("proxy.txt", "r") as f:
lines = [l.strip() for l in f if l.strip()]
return lines
def load_config() -> dict:
default = {"settings": {"sleep_seconds": 3600}}
if not os.path.exists("config.json"):
return default
with open("config.json", "r") as f:
return json.load(f)
def get_proxy_for_index(proxies: list, index: int):
if not proxies:
return None
return proxies[index % len(proxies)]
def make_headers(initdata: str, device_id: str) -> dict:
h = dict(HEADERS_BASE)
h["x-telegram-initdata"] = initdata
h["x-device-id"] = device_id
return h
async def fetch_me(session: aiohttp.ClientSession, initdata: str, device_id: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.get(f"{BASE_URL}/me", headers=headers, proxy=proxy) as resp:
if resp.status in (401, 403):
print(R + "Session expired or initdata is invalid")
return None
if resp.status != 200:
print(R + f"Failed to retrieve user info, status {resp.status}")
return None
return await resp.json()
except Exception:
print(R + "Connection error while retrieving user info")
return None
async def start_task(session: aiohttp.ClientSession, initdata: str, device_id: str, task_id: str, proxy: str | None) -> bool:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/tasks/{task_id}/start", headers=headers, json={}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return False
data = await resp.json()
return data.get("ok", False)
except Exception:
return False
async def verify_task(session: aiohttp.ClientSession, initdata: str, device_id: str, task_id: str, proxy: str | None) -> bool:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/tasks/{task_id}/verify", headers=headers, json={}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return False
data = await resp.json()
return data.get("joined", False)
except Exception:
return False
async def claim_task(session: aiohttp.ClientSession, initdata: str, device_id: str, task_id: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/tasks/{task_id}/claim", headers=headers, json={}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def ads_start(session: aiohttp.ClientSession, initdata: str, device_id: str, purpose: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/ads/start", headers=headers, json={"purpose": purpose}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def ads_complete(session: aiohttp.ClientSession, initdata: str, device_id: str, nonce: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/ads/complete", headers=headers, json={"nonce": nonce}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def bonus_claim(session: aiohttp.ClientSession, initdata: str, device_id: str, nonce: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/bonus/claim", headers=headers, json={"adNonce": nonce}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def game_start(session: aiohttp.ClientSession, initdata: str, device_id: str, game: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/games/start", headers=headers, json={"game": game}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def game_finish(session: aiohttp.ClientSession, initdata: str, device_id: str, nonce: str, game: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
score_map = {"catch": 600, "merge": 6000, "flappy": 600, "whack": 600}
score = score_map.get(game, 600)
try:
async with session.post(f"{BASE_URL}/games/finish", headers=headers, json={"nonce": nonce, "score": score}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def game_claim(session: aiohttp.ClientSession, initdata: str, device_id: str, session_id: str, ad_nonce: str, proxy: str | None) -> dict | None:
headers = make_headers(initdata, device_id)
try:
async with session.post(f"{BASE_URL}/games/claim", headers=headers, json={"sessionId": session_id, "adNonce": ad_nonce}, proxy=proxy) as resp:
if resp.status not in (200, 201):
return None
return await resp.json()
except Exception:
return None
async def ad_countdown(seconds: int):
for remaining in range(seconds, 0, -1):
h = remaining // 3600
m = (remaining % 3600) // 60
s = remaining % 60
print(Y + f"Ad watching, completing in {h:02d}:{m:02d}:{s:02d}", end="\r", flush=True)
await asyncio.sleep(1)
print(" " * 60, end="\r", flush=True)
async def run_ad_cycle(session: aiohttp.ClientSession, initdata: str, device_id: str, purpose: str, proxy: str | None) -> str | None:
ad_data = await ads_start(session, initdata, device_id, purpose, proxy)
if not ad_data or "nonce" not in ad_data:
print(R + f"Ad start failed for purpose {purpose}")
return None
nonce = ad_data["nonce"]
min_watch = ad_data.get("minWatch", 5)
cooldown = ad_data.get("cooldownSecs", 3)
await ad_countdown(min_watch + cooldown)
result = await ads_complete(session, initdata, device_id, nonce, proxy)
if not result:
print(R + f"Ad complete failed for purpose {purpose}")
return None
return nonce
async def process_tasks(session: aiohttp.ClientSession, initdata: str, device_id: str, tasks: list, proxy: str | None):
claimable = [t for t in tasks if t.get("status") == "idle"]
if not claimable:
print(Y + "No pending tasks available today")
return
for task in claimable:
task_id = task["id"]
title = task["title"]
verify_secs = task.get("verifySecs", 5)
started = await start_task(session, initdata, device_id, task_id, proxy)
if not started:
print(R + f"Task {title} failed to start")
continue
print(Y + f"Task {title} started, verifying after {verify_secs} seconds")
await asyncio.sleep(verify_secs + 1)
verified = await verify_task(session, initdata, device_id, task_id, proxy)
if not verified:
print(R + f"Task {title} verification returned not joined")
continue
claimed = await claim_task(session, initdata, device_id, task_id, proxy)
if claimed and "reward" in claimed:
print(G + f"Task {title} claimed, reward {claimed['reward']} GD, balance {claimed.get('balance', 0)} GD")
else:
print(R + f"Task {title} claim request failed")
async def process_earn_ads(session: aiohttp.ClientSession, initdata: str, device_id: str, adsgram_used: int, adsgram_cap: int, monetag_used: int, monetag_cap: int, proxy: str | None):
adsgram_remaining = max(0, adsgram_cap - adsgram_used)
monetag_remaining = max(0, monetag_cap - monetag_used)
if adsgram_remaining == 0 and monetag_remaining == 0:
print(Y + "All earn ad slots consumed today")
return
for i in range(adsgram_remaining):
nonce = await run_ad_cycle(session, initdata, device_id, "earn", proxy)
if nonce:
print(G + f"Adsgram earn ad {i + 1} of {adsgram_remaining} completed successfully")
await asyncio.sleep(3)
for i in range(monetag_remaining):
nonce = await run_ad_cycle(session, initdata, device_id, "monetag", proxy)
if nonce:
print(G + f"Monetag earn ad {i + 1} of {monetag_remaining} completed successfully")
await asyncio.sleep(3)
async def process_daily_bonus(session: aiohttp.ClientSession, initdata: str, device_id: str, proxy: str | None):
nonce = await run_ad_cycle(session, initdata, device_id, "bonus", proxy)
if not nonce:
print(R + "Daily bonus ad cycle failed")
return
result = await bonus_claim(session, initdata, device_id, nonce, proxy)
if result and "reward" in result:
print(G + f"Daily bonus claimed, reward {result['reward']} GD, balance {result.get('balance', 0)} GD")
else:
print(R + "Daily bonus claim request failed")
async def run_game_ad_cycle(session: aiohttp.ClientSession, initdata: str, device_id: str, proxy: str | None, max_retries: int = 3) -> str | None:
for _ in range(max_retries):
ad_data = await ads_start(session, initdata, device_id, "game", proxy)
if not ad_data or "nonce" not in ad_data:
continue
if ad_data.get("purpose") != "game" or ad_data.get("provider") != "adsgram":
continue
nonce = ad_data["nonce"]
min_watch = ad_data.get("minWatch", 5)
cooldown = ad_data.get("cooldownSecs", 3)
await ad_countdown(min_watch + cooldown)
if await ads_complete(session, initdata, device_id, nonce, proxy):
return nonce
print(R + "Ad start failed for purpose game")
return None
async def claim_game_reward(session: aiohttp.ClientSession, initdata: str, device_id: str, session_id: str, proxy: str | None) -> dict | None:
await ad_countdown(30)
ad_nonce = await run_game_ad_cycle(session, initdata, device_id, proxy, max_retries=3)
if not ad_nonce:
return None
return await game_claim(session, initdata, device_id, str(session_id), ad_nonce, proxy)
async def claim_pending(session: aiohttp.ClientSession, initdata: str, device_id: str, pending: dict, proxy: str | None) -> bool:
session_id = str(pending.get("sessionId", ""))
if not session_id:
return False
claim_data = await claim_game_reward(session, initdata, device_id, session_id, proxy)
if claim_data and "reward" in claim_data:
print(G + f"Pending reward claimed, reward {claim_data['reward']} GD, balance {claim_data.get('balance', 0)} GD")
return True
print(R + "Pending reward claim failed")
return False
async def process_game(session: aiohttp.ClientSession, initdata: str, device_id: str, game: str, plays_left: int, proxy: str | None) -> bool:
if plays_left <= 0:
print(Y + f"Game {game} has no plays remaining")
return True
for round_num in range(plays_left):
start_data = await game_start(session, initdata, device_id, game, proxy)
if not start_data or "nonce" not in start_data:
print(R + f"Game {game} round {round_num + 1} failed to start")
return False
game_nonce = start_data["nonce"]
await asyncio.sleep(5)
finish_data = await game_finish(session, initdata, device_id, game_nonce, game, proxy)
if not finish_data or "sessionId" not in finish_data:
print(R + f"Game {game} round {round_num + 1} finish failed")
return False
session_id = str(finish_data["sessionId"])
claim_data = await claim_game_reward(session, initdata, device_id, session_id, proxy)
if not claim_data:
print(R + f"Game {game} round {round_num + 1} ad cycle failed")
return False
if claim_data and "reward" in claim_data:
print(G + f"Game {game} round {round_num + 1} reward claimed, reward {claim_data['reward']} GD, balance {claim_data.get('balance', 0)} GD")
else:
print(R + f"Game {game} round {round_num + 1} claim failed")
return False
if round_num < plays_left - 1:
await asyncio.sleep(3)
return True
async def run_account(initdata: str, proxy: str | None, account_index: int):
proxy_display = format_proxy_log(proxy) if proxy else "No proxy configured"
device_id = generate_device_id()
connector = aiohttp.TCPConnector(ssl=False)
async with aiohttp.ClientSession(connector=connector) as session:
print(Y + f"Proxy in use: {proxy_display}")
me_data = await fetch_me(session, initdata, device_id, proxy)
if not me_data:
print(R + f"Account {account_index + 1} skipped due to session error")
return
user = me_data.get("user", {})
username = user.get("username") or user.get("name", "unknown")
balance = user.get("balance", 0)
daily_bonus_claimed = user.get("dailyBonusClaimed", False)
plays_left = user.get("playsLeft", {})
ad_counters = user.get("adCounters", {})
tasks = me_data.get("tasks", [])
adsgram_used = ad_counters.get("adsgram", {}).get("used", 0)
adsgram_cap = ad_counters.get("adsgram", {}).get("cap", 8)
monetag_used = ad_counters.get("monetag", {}).get("used", 0)
monetag_cap = ad_counters.get("monetag", {}).get("cap", 6)
pending_claim = user.get("pendingClaim")
print(G + f"Processing account {account_index + 1} {username}, current balance {balance} GD")
print(Y + "Processing all available tasks")
await process_tasks(session, initdata, device_id, tasks, proxy)
print(Y + "Processing all earn ad slots")
await process_earn_ads(session, initdata, device_id, adsgram_used, adsgram_cap, monetag_used, monetag_cap, proxy)
if not daily_bonus_claimed:
print(Y + "Claiming daily check-in bonus")
await process_daily_bonus(session, initdata, device_id, proxy)
else:
print(Y + "Daily bonus already claimed today")
if pending_claim:
print(Y + "Claiming pending game reward before starting games")
if not await claim_pending(session, initdata, device_id, pending_claim, proxy):
return
game_order = ["catch", "merge", "flappy", "whack"]
for game in game_order:
left = int(plays_left.get(game, 0) or 0)
print(Y + f"Processing game {game}, plays remaining {left}")
if not await process_game(session, initdata, device_id, game, left, proxy):
return
async def countdown(seconds: int):
for remaining in range(seconds, 0, -1):
h = remaining // 3600
m = (remaining % 3600) // 60
s = remaining % 60
print(Y + f"Next cycle starts in {h:02d}:{m:02d}:{s:02d}", end="\r", flush=True)
await asyncio.sleep(1)
print(" " * 60, end="\r")
async def main():
show_banner(MY_PROJECT)
initdata_list = load_initdata()
proxies = load_proxies()
config = load_config()
sleep_seconds = config.get("settings", {}).get("sleep_seconds", 3600)
while True:
for index, initdata in enumerate(initdata_list):
proxy = get_proxy_for_index(proxies, index)
await run_account(initdata, proxy, index)
print("")
await countdown(sleep_seconds)
show_banner(MY_PROJECT)
def handle_sigint(sig, frame):
print("\n" + R + "Script stopped by user")
sys.exit(0)
signal.signal(signal.SIGINT, handle_sigint)
if __name__ == "__main__":
asyncio.run(main())