-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscord_extractor.py
More file actions
303 lines (250 loc) · 10.3 KB
/
discord_extractor.py
File metadata and controls
303 lines (250 loc) · 10.3 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
"""
Discord Bot Zip Extractor
─────────────────────────
Sends /gen <app_id> to the Contrary Turtle Tool bot and downloads + extracts the zip file.
Usage:
python discord_extractor.py
Then enter app IDs when prompted.
Requirements:
pip install requests python-dotenv
"""
import os
import sys
sys.stdout.reconfigure(encoding='utf-8')
import time
import re
import json
import requests
import zipfile
import io
# ─── Configuration ────────────────────────────────────────────────────────────
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN", "YOUR_DISCORD_TOKEN_HERE")
CHANNEL_ID = "1491535143956123781"
BOT_APPLICATION_ID = "1472613875815026708"
GUILD_ID = "1491535143339557086"
OUTPUT_FOLDER = r"C:\Users\sayed\Downloads\luas"
# Discovered command details (from guild application-command-index)
GEN_COMMAND_ID = "1472651570956210237"
GEN_COMMAND_VERSION = "1472665975265689761"
# ─── Discord API ──────────────────────────────────────────────────────────────
BASE_URL = "https://discord.com/api/v9"
HEADERS = {
"Authorization": DISCORD_TOKEN,
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}
def send_gen_command(app_id):
"""Sends /gen appid:<app_id> to the Contrary Turtle Tool bot."""
payload = {
"type": 2,
"application_id": BOT_APPLICATION_ID,
"guild_id": GUILD_ID,
"channel_id": CHANNEL_ID,
"session_id": "extractor_session",
"data": {
"version": GEN_COMMAND_VERSION,
"id": GEN_COMMAND_ID,
"name": "gen",
"type": 1,
"options": [
{
"type": 3,
"name": "appid",
"value": str(app_id)
}
],
},
"nonce": str(int(time.time() * 1000000))
}
res = requests.post(f"{BASE_URL}/interactions", headers=HEADERS, json=payload)
if res.status_code in (200, 204):
print(f" [+] Sent /gen {app_id}")
return True
else:
print(f" [!] Failed to send /gen. Status: {res.status_code} - {res.text[:300]}")
return False
def get_baseline_message_ids():
"""Get current message IDs BEFORE sending a command."""
url = f"{BASE_URL}/channels/{CHANNEL_ID}/messages?limit=10"
seen = set()
try:
r = requests.get(url, headers=HEADERS)
if r.status_code == 200:
for m in r.json():
seen.add(m["id"])
except Exception:
pass
return seen
def wait_for_zip_url(app_id, baseline_ids, timeout=45, poll_interval=2):
"""
Polls channel for the bot's response. The bot embeds zip download links
inside button components, not as file attachments.
Returns (zip_url, game_name) or (None, None).
"""
print(f" [*] Waiting for bot response...")
url = f"{BASE_URL}/channels/{CHANNEL_ID}/messages?limit=10"
start = time.time()
while time.time() - start < timeout:
time.sleep(poll_interval)
try:
r = requests.get(url, headers=HEADERS)
if r.status_code != 200:
continue
for msg in r.json():
if msg["id"] in baseline_ids:
continue
# Is this from the bot?
author = msg.get("author", {})
interaction = msg.get("interaction", {})
is_bot_gen = (
author.get("id") == BOT_APPLICATION_ID or
interaction.get("name") == "gen"
)
if not is_bot_gen:
baseline_ids.add(msg["id"])
continue
baseline_ids.add(msg["id"])
# Get game name from embed title
game_name = "Unknown"
embeds = msg.get("embeds", [])
for emb in embeds:
title = emb.get("title", "")
if title and "not found" not in title.lower():
game_name = title
elif "not found" in title.lower():
print(f" [!] Bot says: File not found for app {app_id}")
return None, None
# Extract URL from button components
components = msg.get("components", [])
for row in components:
for comp in row.get("components", []):
comp_url = comp.get("url", "")
if "http" in comp_url:
print(f" [+] Found link for: {game_name}")
return comp_url, game_name
# Also check attachments just in case
for att in msg.get("attachments", []):
if att.get("filename", "").endswith(".zip"):
return att["url"], game_name
print(f" [~] Bot responded but no zip link found")
except Exception as e:
print(f" [!] Poll error: {e}")
print(f" [!] Timed out after {timeout}s")
return None, None
def download_and_extract(zip_url, app_id, game_name, output_folder):
"""Downloads zip and extracts .lua files."""
os.makedirs(output_folder, exist_ok=True)
print(f" [*] Downloading zip...")
try:
r = requests.get(zip_url)
r.raise_for_status()
# Save raw zip
zip_path = os.path.join(output_folder, f"{app_id}.zip")
with open(zip_path, "wb") as f:
f.write(r.content)
# Extract
with zipfile.ZipFile(io.BytesIO(r.content)) as z:
files = z.namelist()
print(f" [*] Zip contains {len(files)} files. Extracting .lua only...")
for name in files:
if not name.endswith(".lua"):
continue
data = z.read(name)
# Save with app_id prefix for clarity
save_name = f"{app_id}.lua"
save_path = os.path.join(output_folder, save_name)
with open(save_path, "wb") as f:
f.write(data)
print(f" [+] Saved LUA: {save_path}")
print(f" [OK] {game_name} (ID: {app_id}) complete!")
return True
except zipfile.BadZipFile:
print(f" [!] Not a valid zip file, treating as a raw .lua file.")
save_path = os.path.join(output_folder, f"{app_id}.lua")
with open(save_path, "wb") as f:
f.write(r.content)
print(f" [+] Saved LUA: {save_path}")
print(f" [OK] {game_name} (ID: {app_id}) complete!")
return True
except Exception as e:
print(f" [!] Error: {e}")
return False
def process(app_id):
"""Full pipeline for one app ID."""
print(f"\n{'='*50}")
print(f" App ID: {app_id}")
print(f"{'='*50}")
# Snapshot BEFORE sending so we don't miss fast bot replies
baseline = get_baseline_message_ids()
if not send_gen_command(app_id):
return False
zip_url, game_name = wait_for_zip_url(app_id, baseline)
if not zip_url:
return False
return download_and_extract(zip_url, app_id, game_name, OUTPUT_FOLDER)
def main():
print("""
+======================================================+
| Contrary Turtle Tool - Auto Zip Extractor v2.0 |
| Sends /gen <appid> and downloads the lua zip |
+======================================================+
""")
print(f" Output: {OUTPUT_FOLDER}")
print(f" Bot: Contrary Turtle Tool ({BOT_APPLICATION_ID})")
print(f" Command: /gen (ID: {GEN_COMMAND_ID})")
print(f" Press Ctrl+C to exit.\n")
while True:
try:
user_input = input("Enter App ID(s) [e.g. '730,440', '100-200', or 'auto 100' for infinite]: ").strip()
if not user_input:
continue
app_ids = []
# --- Auto Continuous Mode ---
if user_input.lower().startswith("auto"):
parts = user_input.split()
if len(parts) >= 2 and parts[1].isdigit():
start_id = int(parts[1])
print(f"\n[*] Starting CONTINUOUS extraction from App ID {start_id}...")
print(f"[*] Most Steam base games increment by 10 (10, 20, 30...).")
print(f"[*] (Press Ctrl+C to stop the infinite loop)\n")
app_id = start_id
while True:
process(str(app_id))
app_id += 1 # Incrementing by 1 covers EVERY single ID
delay = 4
print(f" [*] Rate limit pause ({delay}s)...")
time.sleep(delay)
else:
print(" [!] Invalid auto syntax. Usage: auto <start_id> (e.g., auto 100)")
continue
# Parse standard input
for part in user_input.split(","):
part = part.strip()
if "-" in part and part.replace("-", "").isdigit():
a, b = part.split("-", 1)
app_ids.extend(str(i) for i in range(int(a), int(b) + 1))
elif part.isdigit():
app_ids.append(part)
else:
print(f" [!] Skipping invalid: {part}")
if not app_ids:
continue
success = 0
fail = 0
for i, app_id in enumerate(app_ids):
result = process(app_id)
if result:
success += 1
else:
fail += 1
# Rate limit between commands
if i < len(app_ids) - 1:
delay = 4
print(f" [*] Rate limit pause ({delay}s)...")
time.sleep(delay)
print(f"\n Done! {success} succeeded, {fail} failed out of {len(app_ids)} total.\n")
except KeyboardInterrupt:
print("\n\nExiting...")
break
if __name__ == "__main__":
main()