Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Commit d201556

Browse files
committed
Improve Discord invite URL extraction and normalization
Updated the regex to support more Discord invite URL formats and made the extraction case-insensitive. Added normalization to strip trailing slashes and remove duplicates while preserving order.
1 parent 044276e commit d201556

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Tool-05-Database-Field-Inspector.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ def load_servers_js(file_path):
1414
with open(file_path, "r", encoding="utf-8") as f:
1515
content = f.read()
1616

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
17+
pattern = r"https?://(?:discord(?:app)?\.com/invite|discord\.gg)/[A-Za-z0-9_-]+/?"
18+
invites = re.findall(pattern, content, flags=re.IGNORECASE)
19+
20+
# Normalize (strip trailing slash) and remove duplicates while preserving order
21+
seen = set()
22+
result = []
23+
for inv in invites:
24+
inv = inv.rstrip('/')
25+
if inv not in seen:
26+
seen.add(inv)
27+
result.append(inv)
28+
29+
return result
2130
except Exception as e:
2231
print(f"Error loading servers.js: {e}")
2332
return []

0 commit comments

Comments
 (0)