generated from nhcarrigan/template
chore: lints
CI / dependency-pin-check-python (pull_request) Successful in 4s
CI / dependency-pin-check-typescript (pull_request) Successful in 4s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 55s
CI / python (pull_request) Successful in 9m25s
CI / typescript (pull_request) Successful in 9m46s
CI / dependency-pin-check-python (pull_request) Successful in 4s
CI / dependency-pin-check-typescript (pull_request) Successful in 4s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 55s
CI / python (pull_request) Successful in 9m25s
CI / typescript (pull_request) Successful in 9m46s
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Update Cohort Leads role permissions to allow pinging in team channels.
|
||||
"""
|
||||
"""Update Cohort Leads role permissions to allow pinging in team channels."""
|
||||
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
import os
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
# Discord configuration
|
||||
BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
|
||||
@@ -15,26 +13,66 @@ BASE_URL = "https://discord.com/api/v10"
|
||||
|
||||
# Team channel IDs from send_team_messages.py
|
||||
TEAM_CHANNELS = {
|
||||
"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",
|
||||
},
|
||||
}
|
||||
|
||||
HEADERS = {
|
||||
"Authorization": f"Bot {BOT_TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
HEADERS = {"Authorization": f"Bot {BOT_TOKEN}", "Content-Type": "application/json"}
|
||||
|
||||
|
||||
def get_guild_roles():
|
||||
"""Get all roles in the guild to find Cohort Leads"""
|
||||
@@ -47,6 +85,7 @@ def get_guild_roles():
|
||||
print(f"Error getting roles: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
|
||||
def find_cohort_leads_role(roles):
|
||||
"""Find the Cohort Leads role from the list"""
|
||||
for role in roles:
|
||||
@@ -54,6 +93,7 @@ def find_cohort_leads_role(roles):
|
||||
return role
|
||||
return None
|
||||
|
||||
|
||||
def update_channel_permissions(channel_id, role_id, team_name):
|
||||
"""Update channel permissions for a specific role"""
|
||||
url = f"{BASE_URL}/channels/{channel_id}/permissions/{role_id}"
|
||||
@@ -66,7 +106,7 @@ def update_channel_permissions(channel_id, role_id, team_name):
|
||||
data = {
|
||||
"allow": "2251799813816320", # MENTION_EVERYONE + PIN_MESSAGES permissions
|
||||
"deny": "0",
|
||||
"type": 0 # Role permission type
|
||||
"type": 0, # Role permission type
|
||||
}
|
||||
|
||||
response = requests.put(url, headers=HEADERS, json=data)
|
||||
@@ -80,9 +120,13 @@ def update_channel_permissions(channel_id, role_id, team_name):
|
||||
time.sleep(retry_after)
|
||||
return update_channel_permissions(channel_id, role_id, team_name)
|
||||
else:
|
||||
print(f"✗ Failed to update {team_name} channel: {response.status_code} - {response.text}")
|
||||
print(
|
||||
f"✗ Failed to update {team_name} channel: "
|
||||
f"{response.status_code} - {response.text}"
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
print("Fetching guild roles...")
|
||||
roles = get_guild_roles()
|
||||
@@ -100,7 +144,10 @@ def main():
|
||||
print(f" - {role['name']} (ID: {role['id']})")
|
||||
return
|
||||
|
||||
print(f"\nFound Cohort Leads role: {cohort_leads_role['name']} (ID: {cohort_leads_role['id']})")
|
||||
print(
|
||||
f"\nFound Cohort Leads role: {cohort_leads_role['name']} "
|
||||
f"(ID: {cohort_leads_role['id']})"
|
||||
)
|
||||
print(f"Updating permissions for {len(TEAM_CHANNELS)} team channels...")
|
||||
print("-" * 50)
|
||||
|
||||
@@ -108,7 +155,9 @@ def main():
|
||||
fail_count = 0
|
||||
|
||||
for team_name, team_data in TEAM_CHANNELS.items():
|
||||
if update_channel_permissions(team_data["channel_id"], cohort_leads_role["id"], team_name):
|
||||
if update_channel_permissions(
|
||||
team_data["channel_id"], cohort_leads_role["id"], team_name
|
||||
):
|
||||
success_count += 1
|
||||
else:
|
||||
fail_count += 1
|
||||
@@ -124,7 +173,11 @@ def main():
|
||||
print("Cohort Leads can now:")
|
||||
print(" - Use @everyone, @here, and mention all roles")
|
||||
print(" - Pin and unpin messages")
|
||||
print("\nNote: They cannot view these channels unless they have the specific team role.")
|
||||
print(
|
||||
"\nNote: They cannot view these channels unless they have "
|
||||
"the specific team role."
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user