generated from nhcarrigan/template
feat: add multi-lang support and cohort scripts (#1)
CI / dependency-pin-check-typescript (push) Successful in 4s
CI / dependency-pin-check-python (push) Successful in 3s
CI / typescript (push) Successful in 9m38s
CI / python (push) Successful in 9m23s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m6s
CI / dependency-pin-check-typescript (push) Successful in 4s
CI / dependency-pin-check-python (push) Successful in 3s
CI / typescript (push) Successful in 9m38s
CI / python (push) Successful in 9m23s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m6s
### Explanation _No response_ ### Issue _No response_ ### Attestations - [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [ ] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Co-authored-by: Hikari <hikari@nhcarrigan.com> Reviewed-on: #1 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
# Configuration
|
||||
BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
|
||||
GUILD_ID = "692816967895220344"
|
||||
BASE_URL = "https://discord.com/api/v10"
|
||||
|
||||
# Read Discord IDs from table.md
|
||||
with open("table.md") as f:
|
||||
content = f.read()
|
||||
|
||||
lines = content.strip().split("\n")
|
||||
|
||||
# Find the table header line (starts with |)
|
||||
header_line = None
|
||||
header_idx = 0
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith("| Discord"):
|
||||
header_line = line
|
||||
header_idx = i
|
||||
break
|
||||
|
||||
if not header_line:
|
||||
print("Could not find table header!")
|
||||
exit(1)
|
||||
|
||||
headers = [h.strip() for h in header_line.split("|")[1:-1]]
|
||||
|
||||
discord_idx = 0 # Discord ID is the first column
|
||||
|
||||
discord_ids = []
|
||||
for line in lines[header_idx + 2 :]: # Skip header and separator
|
||||
if not line.startswith("|"):
|
||||
continue
|
||||
cols = [c.strip() for c in line.split("|")[1:-1]]
|
||||
if len(cols) > discord_idx:
|
||||
discord_id = cols[discord_idx].strip()
|
||||
if discord_id and discord_id.isdigit():
|
||||
discord_ids.append(discord_id)
|
||||
|
||||
print(f"Found {len(discord_ids)} Discord IDs to verify")
|
||||
|
||||
# Verify each ID against the guild
|
||||
verified = []
|
||||
missing = []
|
||||
errors = []
|
||||
|
||||
for i, discord_id in enumerate(discord_ids):
|
||||
url = f"{BASE_URL}/guilds/{GUILD_ID}/members/{discord_id}"
|
||||
req = urllib.request.Request(url)
|
||||
req.add_header("Authorization", f"Bot {BOT_TOKEN}")
|
||||
|
||||
try:
|
||||
response = urllib.request.urlopen(req)
|
||||
data = json.loads(response.read().decode())
|
||||
username = data.get("user", {}).get("username", "Unknown")
|
||||
verified.append((discord_id, username))
|
||||
print(f"[{i + 1}/{len(discord_ids)}] ✓ {discord_id} - {username}")
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 404:
|
||||
missing.append(discord_id)
|
||||
print(f"[{i + 1}/{len(discord_ids)}] ✗ {discord_id} - NOT IN SERVER")
|
||||
elif e.code == 429:
|
||||
# Rate limited - wait and retry
|
||||
retry_after = json.loads(e.read().decode()).get("retry_after", 1)
|
||||
print(
|
||||
f"[{i + 1}/{len(discord_ids)}] Rate limited, waiting {retry_after}s..."
|
||||
)
|
||||
time.sleep(retry_after + 0.5)
|
||||
# Retry
|
||||
try:
|
||||
req2 = urllib.request.Request(url)
|
||||
req2.add_header("Authorization", f"Bot {BOT_TOKEN}")
|
||||
response = urllib.request.urlopen(req2)
|
||||
data = json.loads(response.read().decode())
|
||||
username = data.get("user", {}).get("username", "Unknown")
|
||||
verified.append((discord_id, username))
|
||||
msg = f"[{i + 1}/{len(discord_ids)}] ✓ {discord_id}"
|
||||
print(f"{msg} - {username} (after retry)")
|
||||
except urllib.error.HTTPError as e2:
|
||||
if e2.code == 404:
|
||||
missing.append(discord_id)
|
||||
msg = f"[{i + 1}/{len(discord_ids)}] ✗ {discord_id}"
|
||||
print(f"{msg} - NOT IN SERVER (after retry)")
|
||||
else:
|
||||
errors.append((discord_id, f"HTTP {e2.code}"))
|
||||
print(
|
||||
f"[{i + 1}/{len(discord_ids)}] ? {discord_id} - Error {e2.code}"
|
||||
)
|
||||
else:
|
||||
errors.append((discord_id, f"HTTP {e.code}"))
|
||||
print(f"[{i + 1}/{len(discord_ids)}] ? {discord_id} - Error {e.code}")
|
||||
|
||||
# Small delay to avoid rate limits
|
||||
time.sleep(0.1)
|
||||
|
||||
print("\n=== SUMMARY ===")
|
||||
print(f"Verified: {len(verified)}")
|
||||
print(f"Missing: {len(missing)}")
|
||||
print(f"Errors: {len(errors)}")
|
||||
|
||||
# Save results
|
||||
with open("discord_verification.json", "w") as f:
|
||||
json.dump({"verified": verified, "missing": missing, "errors": errors}, f, indent=2)
|
||||
|
||||
print("\nResults saved to discord_verification.json")
|
||||
Reference in New Issue
Block a user