22import datetime
33import os
44import re
5+ import requests
6+ import sys
7+ import importlib .util
8+
9+
10+ def load_servers_js (file_path ):
11+ """Load the servers.js file and extract server invites"""
12+ try :
13+ # Read the file content
14+ with open (file_path , "r" , encoding = "utf-8" ) as f :
15+ content = f .read ()
16+
17+ # Extract invite URLs using regex
18+ pattern = r"https://discord\.com/invite/[a-zA-Z0-9]+"
19+ invites = re .findall (pattern , content )
20+ return invites
21+ except Exception as e :
22+ print (f"Error loading servers.js: { e } " )
23+ return []
24+
25+
26+ def get_server_member_count (invite_code ):
27+ """Get member count for a Discord server using its invite code"""
28+ try :
29+ invite_code = invite_code .split ("/" )[- 1 ] # Extract just the code part
30+ url = f"https://discord.com/api/v9/invites/{ invite_code } ?with_counts=true"
31+ headers = {
32+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
33+ }
34+ response = requests .get (url , headers = headers )
35+ data = response .json ()
36+
37+ if "approximate_member_count" in data :
38+ return data ["approximate_member_count" ]
39+ return 0
40+ except Exception as e :
41+ print (f"Error fetching member count for { invite_code } : { e } " )
42+ return 0
543
644
7- def process_json (json_file , output_file , date_str ):
45+ def process_json (json_file , output_file , date_str , total_protected_members = 0 ):
846 with open (json_file , "r" , encoding = "utf-8" ) as f :
947 data = json .load (f )
1048
@@ -33,6 +71,8 @@ def process_json(json_file, output_file, date_str):
3371 f .write (f'<div align="center">\n \n ' )
3472 f .write (f"# Database Inspection - { date_str } \n \n " )
3573 f .write (f"## Total Cases: { case_count } \n \n " )
74+ if total_protected_members > 0 :
75+ f .write (f"## Protected Members: { total_protected_members :,} \n \n " )
3676 f .write (f"</div>\n \n " )
3777
3878 for field , values in unique_values .items ():
@@ -62,7 +102,7 @@ def append_other_counts(output_file, counts_dict):
62102
63103
64104def update_readme (
65- readme_path , date_str , inspection_filename , case_count , additional_counts
105+ readme_path , date_str , inspection_filename , case_count , additional_counts , total_protected_members = 0
66106):
67107 with open (readme_path , "r" , encoding = "utf-8" ) as f :
68108 content = f .read ()
@@ -71,12 +111,14 @@ def update_readme(
71111 f"- **{ name } **: { count } entries" for name , count in additional_counts .items ()
72112 )
73113
114+ protected_members_line = f"**Protected Members**: { total_protected_members :,} " if total_protected_members > 0 else ""
115+
74116 new_section = f"""<!-- INSPECTION-START -->
75117## Latest Database Inspection - { date_str }
76118
77119**Inspection File**: [`{ inspection_filename } `](Inspection-Database/{ inspection_filename } )
78- **Total Cases**: { case_count }
79-
120+ - **Total Cases**: { case_count }
121+ - ** { protected_members_line } **
80122{ additional_lines }
81123<!-- INSPECTION-END -->"""
82124
@@ -90,7 +132,7 @@ def update_readme(
90132 content += "\n \n " + new_section
91133 else :
92134 content = (
93- content [:insert_point ] + new_section + "\n \n " + content [insert_point :]
135+ content [:insert_point ] + new_section + "\n \n " + content [insert_point :]
94136 )
95137
96138 with open (readme_path , "w" , encoding = "utf-8" ) as f :
@@ -106,18 +148,28 @@ def update_readme(
106148
107149 json_file = "../Database-Files/Edit-Database/Compromised-Discord-Accounts.json"
108150 readme_path = "../Database-Files/README.md"
151+ servers_js_path = "../thedartproject.github.io/assets/js/servers.js" # Path to servers.js
152+
153+ # Get server invites and count members
154+ total_protected_members = 0
155+ invite_links = load_servers_js (servers_js_path )
156+
157+ print (f"Found { len (invite_links )} server invites in servers.js" )
158+ for invite in invite_links :
159+ members = get_server_member_count (invite )
160+ print (f"Server invite { invite } : { members } members" )
161+ total_protected_members += members
162+
163+ print (f"Total protected members: { total_protected_members } " )
109164
110165 # Count primary file
111- case_count = process_json (json_file , inspection_path , today )
166+ case_count = process_json (json_file , inspection_path , today , total_protected_members )
112167
113168 # Count entries from additional files
114169 additional_counts = {
115170 "Discord IDs" : count_entries_from_file (
116171 "../Database-Files/Filter-Database/Discord-IDs.json"
117172 ),
118- "Malicious URLs" : count_entries_from_file (
119- "../Database-Files/Filter-Database/Malicious-URLs.json"
120- ),
121173 "Discord Servers" : count_entries_from_file (
122174 "../Database-Files/Filter-Database/Discord-Servers.json"
123175 ),
@@ -128,5 +180,10 @@ def update_readme(
128180
129181 append_other_counts (inspection_path , additional_counts )
130182 update_readme (
131- readme_path , today , inspection_filename , case_count , additional_counts
132- )
183+ readme_path ,
184+ today ,
185+ inspection_filename ,
186+ case_count ,
187+ additional_counts ,
188+ total_protected_members
189+ )
0 commit comments