@@ -18,15 +18,15 @@ def load_env():
1818 env_vars [key ] = value
1919 except FileNotFoundError :
2020 print (".env file not found. Using default values." )
21- env_vars ["PROXY_URL" ] = "https://api.codetabs.com/v1/proxy/?quest= "
21+ env_vars ["PROXY_URL" ] = ""
2222 env_vars ["DISCORD_INVITE_RATE_LIMIT" ] = "20"
2323 return env_vars
2424
2525
2626env_vars = load_env ()
2727
2828# Configuration
29- PROXY_URL = env_vars .get ("PROXY_URL" , "https://api.codetabs.com/v1/proxy/?quest= " )
29+ PROXY_URL = env_vars .get ("" )
3030RATE_LIMIT = int (env_vars .get ("DISCORD_INVITE_RATE_LIMIT" , 20 ))
3131JSON_FILE_PATH = os .path .join (
3232 os .path .dirname (__file__ ),
@@ -65,60 +65,37 @@ def check_invite(invite_code):
6565
6666 if response .status_code == 200 :
6767 try :
68- # Parse the proxy response
69- proxy_data = response .json ()
70-
71- # Check if we're using a proxy service like allorigins.win
72- if 'contents' in proxy_data :
73- # Extract the actual Discord API response from proxy wrapper
74- actual_response = proxy_data ['contents' ]
75-
76- # Parse the actual Discord response
77- try :
78- discord_data = json .loads (actual_response )
79- except (json .JSONDecodeError , TypeError ):
80- # If contents is not JSON string, it might be already parsed
81- discord_data = actual_response
82-
83- # Check HTTP status from proxy metadata if available
84- if 'status' in proxy_data :
85- status_info = proxy_data ['status' ]
86- actual_http_code = status_info .get ('http_code' , 200 )
87-
88- # If Discord API returned 404 (Unknown Invite)
89- if actual_http_code == 404 :
90- return False , f"https://discord.com/invite/{ invite_code } "
91-
92- # Check Discord API response content
93- if isinstance (discord_data , dict ):
94- # Check for "Unknown Invite" error
95- if (discord_data .get ("code" ) == 10006 and
96- discord_data .get ("message" ) == "Unknown Invite" ):
97- return False , f"https://discord.com/invite/{ invite_code } "
98-
99- # If we got valid guild data, the invite is active
100- if "guild" in discord_data :
101- return True , f"https://discord.com/invite/{ invite_code } "
102-
103- # If we can't determine status from content, assume inactive
104- return False , f"https://discord.com/invite/{ invite_code } "
105-
106- else :
107- # Direct API response (no proxy)
108- data = proxy_data
109- if (data .get ("code" ) == 10006 and
110- data .get ("message" ) == "Unknown Invite" ):
68+ data = response .json ()
69+
70+ # Handle direct API response (no proxy)
71+ if isinstance (data , dict ):
72+ # Check for "Unknown Invite" error
73+ if (
74+ data .get ("code" ) == 10006
75+ and data .get ("message" ) == "Unknown Invite"
76+ ):
11177 return False , f"https://discord.com/invite/{ invite_code } "
11278
113- if "guild" in data :
79+ # Check for successful response with guild data (new format)
80+ if "guild" in data or "code" in data :
11481 return True , f"https://discord.com/invite/{ invite_code } "
11582
116- return False , f"https://discord.com/invite/{ invite_code } "
83+ # Check for successful response with type field (alternative format)
84+ if "type" in data and isinstance (data ["type" ], int ):
85+ return True , f"https://discord.com/invite/{ invite_code } "
86+
87+ # If none of the above but status is 200, assume active
88+ return True , f"https://discord.com/invite/{ invite_code } "
89+
90+ # If response is not a dict but status is 200, assume active
91+ return True , f"https://discord.com/invite/{ invite_code } "
11792
11893 except (json .JSONDecodeError , ValueError ) as e :
11994 if PRINT_RESPONSE :
12095 print (f"Error parsing JSON response for { invite_code } : { str (e )} " )
12196 return False , f"https://discord.com/invite/{ invite_code } "
97+ elif response .status_code == 404 :
98+ return False , f"https://discord.com/invite/{ invite_code } "
12299 else :
123100 return False , f"https://discord.com/invite/{ invite_code } "
124101
@@ -198,8 +175,8 @@ def process_accounts():
198175 surface_domain = account_data .get ("SURFACE_URL_DOMAIN" , "" )
199176
200177 if not (
201- surface_domain in ["discord.gg" , "discord.com" ]
202- and surface_url .startswith (("http://" , "https://" ))
178+ surface_domain in ["discord.gg" , "discord.com" ]
179+ and surface_url .startswith (("http://" , "https://" ))
203180 ):
204181 print (
205182 f"[{ i + 1 } /{ total_accounts } ] Skipping { account_id } : Not a Discord invite URL"
@@ -262,4 +239,4 @@ def process_accounts():
262239
263240
264241if __name__ == "__main__" :
265- process_accounts ()
242+ process_accounts ()
0 commit comments