generated from nhcarrigan/template
4fdb5d06f1
- Port 19 cohort scripts from /home/naomi/docs/cohort/ - Replace all hardcoded tokens and dotenv usage with os.environ - Add pandas==3.0.1 dependency - Add E501 to ruff ignore list for Discord message string content - Make remove_resigned_members.py reusable (empty RESIGNED_IDS constant) - Make update_roster_messages.py reusable (iterates all teams from JSON) - Exclude 12 one-off/event-specific scripts as non-reusable
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Check if removed members are still in the Discord server."""
|
|
|
|
import asyncio
|
|
import os
|
|
|
|
import aiohttp
|
|
|
|
DISCORD_BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
|
|
BASE_URL = "https://discord.com/api/v10"
|
|
GUILD_ID = "1354624415861833870"
|
|
|
|
SAMPLE_MEMBERS = [
|
|
"899092786802987069",
|
|
"1318882254365397032",
|
|
"799293680799711273",
|
|
"237793557992308736",
|
|
]
|
|
|
|
|
|
async def check_member(session: aiohttp.ClientSession, user_id: str) -> bool | None:
|
|
"""Check if a member is in the server."""
|
|
url = f"{BASE_URL}/guilds/{GUILD_ID}/members/{user_id}"
|
|
headers = {"Authorization": f"Bot {DISCORD_BOT_TOKEN}"}
|
|
|
|
async with session.get(url, headers=headers) as resp:
|
|
if resp.status == 200:
|
|
data = await resp.json()
|
|
roles = data.get("roles", [])
|
|
print(f"✅ User {user_id} IS in server - has {len(roles)} roles: {roles}")
|
|
return True
|
|
if resp.status == 404:
|
|
print(f"❌ User {user_id} NOT in server (left or was kicked)")
|
|
return False
|
|
error = await resp.text()
|
|
print(f"⚠️ Error checking {user_id}: {resp.status} - {error}")
|
|
return None
|
|
|
|
|
|
async def main() -> None:
|
|
"""Check if sample members are still in the server."""
|
|
async with aiohttp.ClientSession() as session:
|
|
for user_id in SAMPLE_MEMBERS:
|
|
await check_member(session, user_id)
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|