-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTool-09-Invite-Validator.py
223 lines (186 loc) · 7.64 KB
/
Tool-09-Invite-Validator.py
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
import os
import json
import time
from datetime import datetime
import requests
from urllib.parse import urlparse
# Load environment variables
def load_env():
env_path = os.path.join(os.path.dirname(__file__), "../.env")
env_vars = {}
try:
with open(env_path) as f:
for line in f:
if line.strip() and not line.startswith("#"):
key, value = line.strip().split("=", 1)
env_vars[key] = value
except FileNotFoundError:
print(".env file not found. Using default values.")
env_vars["PROXY_URL"] = "https://api.codetabs.com/v1/proxy/?quest="
env_vars["DISCORD_INVITE_RATE_LIMIT"] = "20"
return env_vars
env_vars = load_env()
# Configuration
PROXY_URL = env_vars.get("PROXY_URL", "https://api.codetabs.com/v1/proxy/?quest=")
RATE_LIMIT = int(env_vars.get("DISCORD_INVITE_RATE_LIMIT", 20))
JSON_FILE_PATH = os.path.join(
os.path.dirname(__file__),
"../Database-Files/Edit-Database/Compromised-Discord-Accounts.json",
)
PRINT_RESPONSE = True # Set to True to see full API responses
# Discord API endpoint
DISCORD_API_URL = (
"https://discord.com/api/v10/invites/{}?with_counts=true&with_expiration=true"
)
def extract_invite_code(url):
"""Extract invite code from Discord URL"""
parsed = urlparse(url)
if parsed.netloc == "discord.gg":
return parsed.path.lstrip("/")
elif parsed.netloc == "discord.com":
if parsed.path.startswith("/invite/"):
return parsed.path.split("/")[2]
return None
def check_invite(invite_code):
"""Check if a Discord invite is active"""
url = DISCORD_API_URL.format(invite_code)
proxy_url = PROXY_URL + url if PROXY_URL else url
try:
response = requests.get(proxy_url, timeout=10)
if PRINT_RESPONSE:
print(
f"API Response for {invite_code}: {response.status_code} - {response.text}"
)
if response.status_code == 200:
# Check if the response indicates an unknown invite
try:
data = response.json()
if (
data.get("code") == 10006
and data.get("message") == "Unknown Invite"
):
return False, f"https://discord.com/invite/{invite_code}"
# If we got valid guild data, the invite is active
if "guild" in data:
return True, f"https://discord.com/invite/{invite_code}"
except ValueError:
pass
return False, f"https://discord.com/invite/{invite_code}"
else:
return False, f"https://discord.com/invite/{invite_code}"
except Exception as e:
if PRINT_RESPONSE:
print(f"Error checking invite {invite_code}: {str(e)}")
return False, f"https://discord.com/invite/{invite_code}"
def get_starting_point(total_accounts):
"""Ask user whether to do full scan or start from specific account number"""
while True:
print("\n" + "=" * 50)
print(f"Total accounts in file: {total_accounts}")
print("1. Full scan (process all accounts)")
print("2. Start from specific account number")
print("=" * 50)
choice = input("Enter your choice (1 or 2): ").strip()
if choice == "1":
return 0 # Start from beginning
elif choice == "2":
while True:
try:
start_num = int(
input(f"Enter starting account number (1-{total_accounts}): ")
)
if 1 <= start_num <= total_accounts:
return start_num - 1 # Convert to 0-based index
print(f"Please enter a number between 1 and {total_accounts}")
except ValueError:
print("Please enter a valid number")
else:
print("Invalid choice. Please enter 1 or 2")
def process_accounts():
"""Process all accounts in the JSON file"""
try:
with open(JSON_FILE_PATH, "r", encoding="utf-8") as f:
data = json.load(f)
except FileNotFoundError:
print(f"Error: JSON file not found at {JSON_FILE_PATH}")
return
except json.JSONDecodeError:
print(f"Error: Invalid JSON in file {JSON_FILE_PATH}")
return
total_accounts = len(data)
if total_accounts == 0:
print("No accounts found in the JSON file.")
return
start_index = get_starting_point(total_accounts)
processed = 0
updated_accounts = 0
skipped_accounts = 0
request_delay = 60.0 / RATE_LIMIT if RATE_LIMIT > 0 else 0
print(f"\nStarting processing of accounts...")
print(f"Starting from account number: {start_index + 1}")
print(f"Rate limit configured: {RATE_LIMIT} requests/minute")
print(f"Request delay: {request_delay:.2f} seconds between requests")
accounts_items = list(data.items())
# Cache for already checked invites
checked_invites = {}
for i in range(start_index, total_accounts):
account_id, account_data = accounts_items[i]
processed += 1
surface_url = account_data.get("SURFACE_URL", "")
surface_domain = account_data.get("SURFACE_URL_DOMAIN", "")
if not (
surface_domain in ["discord.gg", "discord.com"]
and surface_url.startswith(("http://", "https://"))
):
print(
f"[{i+1}/{total_accounts}] Skipping {account_id}: Not a Discord invite URL"
)
skipped_accounts += 1
continue
invite_code = extract_invite_code(surface_url)
if not invite_code:
print(
f"[{i+1}/{total_accounts}] Skipping {account_id}: Could not extract invite code from URL"
)
skipped_accounts += 1
continue
print(
f"[{i+1}/{total_accounts}] Processing {account_id}: Checking invite {invite_code}"
)
# Check if invite was already checked
if invite_code in checked_invites:
is_active, final_url = checked_invites[invite_code]
print(f"Invite {invite_code} already checked. Using cached result.")
else:
start_time = time.time()
is_active, final_url = check_invite(invite_code)
checked_invites[invite_code] = (is_active, final_url)
# Adjust delay to respect rate limit
request_time = time.time() - start_time
remaining_delay = max(0, request_delay - request_time)
if remaining_delay > 0:
print(
f"Waiting {remaining_delay:.2f} seconds to maintain rate limit..."
)
time.sleep(remaining_delay)
status = "ACTIVE" if is_active else "INACTIVE"
account_data["SURFACE_URL_STATUS"] = status
account_data["FINAL_URL"] = final_url
account_data["FINAL_URL_DOMAIN"] = "discord.com"
account_data["FINAL_URL_STATUS"] = status
account_data["LAST_CHECK"] = datetime.utcnow().isoformat()
updated_accounts += 1
print(f"Updated {account_id}: Status = {status}")
try:
with open(JSON_FILE_PATH, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
print("Changes saved to file")
except Exception as e:
print(f"Error saving changes to file: {str(e)}")
print(f"\nProcessing complete!")
print(f"Total accounts: {total_accounts}")
print(f"Processed: {processed}")
print(f"Updated: {updated_accounts}")
print(f"Skipped: {skipped_accounts}")
if __name__ == "__main__":
process_accounts()