generated from nhcarrigan/template
fix: resolve lint issues for Python and TypeScript
CI / dependency-pin-check-typescript (pull_request) Successful in 4s
CI / dependency-pin-check-python (pull_request) Successful in 4s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m15s
CI / typescript (pull_request) Successful in 9m40s
CI / python (pull_request) Successful in 9m22s
CI / dependency-pin-check-typescript (pull_request) Successful in 4s
CI / dependency-pin-check-python (pull_request) Successful in 4s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m15s
CI / typescript (pull_request) Successful in 9m40s
CI / python (pull_request) Successful in 9m22s
- Update pyproject.toml to ignore T201 (print statements) and other rules - Fix quote styles, bare except, set comprehensions in Python scripts - Rename interactive-runner.ts to interactiveRunner.ts (camelCase) - Refactor TypeScript to use import.meta.url instead of __dirname - Add proper JSDoc headers and rename abbreviated variables
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
# Amari's bot token
|
||||
@@ -12,32 +13,75 @@ MESSAGE_IDS_FILE = "team_message_ids.json"
|
||||
|
||||
# Team channel IDs and role IDs
|
||||
TEAMS = {
|
||||
"Jade Jasmine": {"channel_id": "1464316501573107886", "role_id": "1464314923780931677"},
|
||||
"Crimson Dahlia": {"channel_id": "1464316744909852682", "role_id": "1464315093402784015"},
|
||||
"Rose Camellia": {"channel_id": "1464316751268286611", "role_id": "1464315098452726106"},
|
||||
"Amber Wisteria": {"channel_id": "1464316761410113641", "role_id": "1464315105264275600"},
|
||||
"Ivory Orchid": {"channel_id": "1464316770889240730", "role_id": "1464315109873684593"},
|
||||
"Teal Iris": {"channel_id": "1464316776459407448", "role_id": "1464315114378498152"},
|
||||
"Peach Gardenia": {"channel_id": "1464316785040953543", "role_id": "1464315118904152107"},
|
||||
"Violet Carnation": {"channel_id": "1464316805261824032", "role_id": "1464315124251754559"},
|
||||
"Azure Lotus": {"channel_id": "1464316814455472139", "role_id": "1464315128437801177"},
|
||||
"Coral Sunflower": {"channel_id": "1464316819711066263", "role_id": "1464315132896088168"},
|
||||
"Indigo Tulip": {"channel_id": "1464316826384072925", "role_id": "1464315138428633241"},
|
||||
"Scarlet Hydrangea": {"channel_id": "1464316839306985506", "role_id": "1464315142710890520"},
|
||||
"Mint Narcissus": {"channel_id": "1464316844251807952", "role_id": "1464315149203804405"},
|
||||
"Sage Marigold": {"channel_id": "1464316850669093040", "role_id": "1464315153599299803"},
|
||||
"Jade Jasmine": {
|
||||
"channel_id": "1464316501573107886",
|
||||
"role_id": "1464314923780931677",
|
||||
},
|
||||
"Crimson Dahlia": {
|
||||
"channel_id": "1464316744909852682",
|
||||
"role_id": "1464315093402784015",
|
||||
},
|
||||
"Rose Camellia": {
|
||||
"channel_id": "1464316751268286611",
|
||||
"role_id": "1464315098452726106",
|
||||
},
|
||||
"Amber Wisteria": {
|
||||
"channel_id": "1464316761410113641",
|
||||
"role_id": "1464315105264275600",
|
||||
},
|
||||
"Ivory Orchid": {
|
||||
"channel_id": "1464316770889240730",
|
||||
"role_id": "1464315109873684593",
|
||||
},
|
||||
"Teal Iris": {
|
||||
"channel_id": "1464316776459407448",
|
||||
"role_id": "1464315114378498152",
|
||||
},
|
||||
"Peach Gardenia": {
|
||||
"channel_id": "1464316785040953543",
|
||||
"role_id": "1464315118904152107",
|
||||
},
|
||||
"Violet Carnation": {
|
||||
"channel_id": "1464316805261824032",
|
||||
"role_id": "1464315124251754559",
|
||||
},
|
||||
"Azure Lotus": {
|
||||
"channel_id": "1464316814455472139",
|
||||
"role_id": "1464315128437801177",
|
||||
},
|
||||
"Coral Sunflower": {
|
||||
"channel_id": "1464316819711066263",
|
||||
"role_id": "1464315132896088168",
|
||||
},
|
||||
"Indigo Tulip": {
|
||||
"channel_id": "1464316826384072925",
|
||||
"role_id": "1464315138428633241",
|
||||
},
|
||||
"Scarlet Hydrangea": {
|
||||
"channel_id": "1464316839306985506",
|
||||
"role_id": "1464315142710890520",
|
||||
},
|
||||
"Mint Narcissus": {
|
||||
"channel_id": "1464316844251807952",
|
||||
"role_id": "1464315149203804405",
|
||||
},
|
||||
"Sage Marigold": {
|
||||
"channel_id": "1464316850669093040",
|
||||
"role_id": "1464315153599299803",
|
||||
},
|
||||
}
|
||||
|
||||
# Load team assignments and convert to dict by team name
|
||||
with open("team_assignments.json", "r") as f:
|
||||
with open("team_assignments.json") as f:
|
||||
team_list = json.load(f)
|
||||
team_data = {team["name"]: team for team in team_list}
|
||||
|
||||
# Load applicants to get project_url by discord_id
|
||||
with open("applicants_to_evaluate.json", "r") as f:
|
||||
with open("applicants_to_evaluate.json") as f:
|
||||
applicants = json.load(f)
|
||||
applicant_lookup = {str(a["discord_id"]): a for a in applicants}
|
||||
|
||||
|
||||
def extract_github_username(url):
|
||||
"""Extract GitHub username from various URL formats"""
|
||||
if not url:
|
||||
@@ -64,19 +108,26 @@ def extract_github_username(url):
|
||||
# Handle standard GitHub URLs
|
||||
if "github.com" in url:
|
||||
# Remove protocol and github.com
|
||||
path = url.replace("https://", "").replace("http://", "").replace("github.com/", "")
|
||||
path = (
|
||||
url.replace("https://", "")
|
||||
.replace("http://", "")
|
||||
.replace("github.com/", "")
|
||||
)
|
||||
# Get just the username (first part of path)
|
||||
username = path.split("/")[0]
|
||||
return username
|
||||
|
||||
return url
|
||||
|
||||
|
||||
def build_message(team_name, role_id, leader_ids, participant_ids):
|
||||
"""Build the welcome message for a team"""
|
||||
lines = [
|
||||
f"# {team_name}",
|
||||
"",
|
||||
f"Welcome, <@&{role_id}>. This is your private team channel — a space for you to collaborate, support one another, and build something meaningful together.",
|
||||
f"Welcome, <@&{role_id}>. This is your private team channel — a space "
|
||||
"for you to collaborate, support one another, and build something "
|
||||
"meaningful together.",
|
||||
"",
|
||||
"## Roster",
|
||||
"",
|
||||
@@ -105,19 +156,21 @@ def build_message(team_name, role_id, leader_ids, participant_ids):
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def send_message(channel_id, content):
|
||||
"""Send a message to a channel"""
|
||||
url = f"https://discord.com/api/v10/channels/{channel_id}/messages"
|
||||
headers = {
|
||||
"Authorization": f"Bot {TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
headers = {"Authorization": f"Bot {TOKEN}", "Content-Type": "application/json"}
|
||||
data = {"content": content}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 429:
|
||||
retry_after = float(response.headers.get("Retry-After", response.headers.get("X-RateLimit-Reset-After", 1)))
|
||||
retry_after = float(
|
||||
response.headers.get(
|
||||
"Retry-After", response.headers.get("X-RateLimit-Reset-After", 1)
|
||||
)
|
||||
)
|
||||
print(f"Rate limited, waiting {retry_after}s...")
|
||||
time.sleep(retry_after)
|
||||
return send_message(channel_id, content)
|
||||
@@ -128,6 +181,7 @@ def send_message(channel_id, content):
|
||||
print(f"Error sending message: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
|
||||
def pin_message(channel_id, message_id):
|
||||
"""Pin a message in a channel"""
|
||||
url = f"https://discord.com/api/v10/channels/{channel_id}/pins/{message_id}"
|
||||
@@ -138,13 +192,18 @@ def pin_message(channel_id, message_id):
|
||||
response = requests.put(url, headers=headers)
|
||||
|
||||
if response.status_code == 429:
|
||||
retry_after = float(response.headers.get("Retry-After", response.headers.get("X-RateLimit-Reset-After", 1)))
|
||||
retry_after = float(
|
||||
response.headers.get(
|
||||
"Retry-After", response.headers.get("X-RateLimit-Reset-After", 1)
|
||||
)
|
||||
)
|
||||
print(f"Rate limited, waiting {retry_after}s...")
|
||||
time.sleep(retry_after)
|
||||
return pin_message(channel_id, message_id)
|
||||
|
||||
return response.status_code == 204
|
||||
|
||||
|
||||
def main():
|
||||
message_ids = {}
|
||||
|
||||
@@ -170,18 +229,18 @@ def main():
|
||||
message_ids[team_name] = {
|
||||
"channel_id": channel_id,
|
||||
"message_id": message_id,
|
||||
"role_id": role_id
|
||||
"role_id": role_id,
|
||||
}
|
||||
print(f" Message sent! ID: {message_id}")
|
||||
|
||||
# Pin the message
|
||||
print(f" Pinning message...")
|
||||
print(" Pinning message...")
|
||||
if pin_message(channel_id, message_id):
|
||||
print(f" Pinned!")
|
||||
print(" Pinned!")
|
||||
else:
|
||||
print(f" Failed to pin")
|
||||
print(" Failed to pin")
|
||||
else:
|
||||
print(f" Failed to send message")
|
||||
print(" Failed to send message")
|
||||
|
||||
# Small delay between teams
|
||||
time.sleep(0.2)
|
||||
@@ -193,5 +252,6 @@ def main():
|
||||
print(f"\nDone! Message IDs saved to {MESSAGE_IDS_FILE}")
|
||||
print(f"Successfully sent and pinned messages for {len(message_ids)} teams")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user