ol_rusty/command_permissions.py

70 lines
1.8 KiB
Python

import requests
import toml
import json
import sys
CONFIG_FILE = "data/config/01-discord.toml"
CONFIG_FILE2 = "data/config/30-high-tier.toml"
data1 = toml.load(CONFIG_FILE2)
ROLE_ID = data1.get("high_tier", {}).get("role", 294950710737502209)
GUILD = data1.get("high_tier", {}).get("guild", 117992911781494787)
HT_COMS = data1.get("high_tier", {}).get("coms", ["links"])
data = toml.load(CONFIG_FILE)
app_id = data["discord"].get("app_id", 936990391847223316)
print("Using token: ", data["discord"]["token"])
token = "Bot " + data["discord"]["token"]
print(token)
Headers = {
"Authorization": token,
"User=Agent": "DiscordBot https://github.com/ 1 manual browser requests",
}
r = requests.get(f"https://discord.com/api/v8/applications/{app_id}/guilds/{GUILD}/commands", headers=Headers)
print(json.dumps(r.json(), indent=2))
commands = r.json()
com_id = None
json = {
"permissions": [
{
"id": ROLE_ID,
"type": 1,
"permission": True
}
]
}
count = 0
for command in commands:
if command["name"] in HT_COMS:
id = command["id"]
url = f"https://discord.com/api/v8/applications/{app_id}/guilds/{GUILD}/commands/{str(id)}"
r = requests.patch(url, headers=Headers, json={"default_permission": False})
print(r.json())
r = requests.put(url+"/permissions", headers=Headers, json=json)
print(r.json())
count += 1
print("Updated", count, "commands")
# print("Which id to set")
# id = input()
# url = f"https://discord.com/api/v8/applications/{app_id}/guilds/{GUILD}/commands/{str(id)}"
# r = requests.patch(url, headers=Headers, json={"default_permission": False})
# print(r.json())
# r = requests.put(url+"/permissions", headers=Headers, json=json)
# print(r.json())