ffxiv-discord-status-category.py
· 2.0 KiB · Python
Raw
#!/usr/bin/env python3
import requests
from datetime import datetime, timedelta
with open(".bottoken") as f:
token = f.read().strip()
t = '\u2705'
f = '\u274c'
class Channel:
category = ("1063529720538484786", "status")
login = ("1063529561486270494", "login")
gate = ("1063529595162337371", "gate")
dc = ("1063529626263101490", "materia")
server = ("1063529649507942501", "sophia")
def get(*args, **kwargs):
if "headers" not in kwargs:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = f"Bot {token}"
return requests.get(*args, **kwargs)
def patch(*args, **kwargs):
if "headers" not in kwargs:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = f"Bot {token}"
return requests.patch(*args, **kwargs)
def update_channel_name(channel, status):
channel_id, name = channel
if status is None: # timestamping
dt = datetime.now() + timedelta(hours=1)
time = "{hour}:{minute}".format(hour=dt.hour, minute=dt.minute)
return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": f"{name}-{time}-AEDT"})
channel_data = get("https://discord.com/api/channels/{}".format(channel_id)).json()
if (status and t not in channel_data["name"]) or (not status and t in channel_data["name"]):
return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": f"{name}{t if status else f}"})
else:
return True
def a(obj):
if not isinstance(obj, bool) and str(obj.status_code)[0] != "2":
print(obj.headers)
print(obj.json())
data = requests.get("https://is.xivup.com/indexdata").json()
a(update_channel_name(Channel.login, data["Realms"]["LoginzServer"]["Status"] == 1))
a(update_channel_name(Channel.gate, data["Realms"]["GatezServer"]["Status"] == 1))
a(update_channel_name(Channel.dc, data["DCs"]["Materia"] == 1))
a(update_channel_name(Channel.server, data["Realms"]["Sophia"]["Status"] == 1))
a(update_channel_name(Channel.category, None))
| 1 | #!/usr/bin/env python3 |
| 2 | import requests |
| 3 | from datetime import datetime, timedelta |
| 4 | |
| 5 | with open(".bottoken") as f: |
| 6 | token = f.read().strip() |
| 7 | t = '\u2705' |
| 8 | f = '\u274c' |
| 9 | |
| 10 | class Channel: |
| 11 | category = ("1063529720538484786", "status") |
| 12 | login = ("1063529561486270494", "login") |
| 13 | gate = ("1063529595162337371", "gate") |
| 14 | dc = ("1063529626263101490", "materia") |
| 15 | server = ("1063529649507942501", "sophia") |
| 16 | |
| 17 | def get(*args, **kwargs): |
| 18 | if "headers" not in kwargs: |
| 19 | kwargs["headers"] = {} |
| 20 | kwargs["headers"]["Authorization"] = f"Bot {token}" |
| 21 | return requests.get(*args, **kwargs) |
| 22 | |
| 23 | def patch(*args, **kwargs): |
| 24 | if "headers" not in kwargs: |
| 25 | kwargs["headers"] = {} |
| 26 | kwargs["headers"]["Authorization"] = f"Bot {token}" |
| 27 | return requests.patch(*args, **kwargs) |
| 28 | |
| 29 | def update_channel_name(channel, status): |
| 30 | channel_id, name = channel |
| 31 | if status is None: # timestamping |
| 32 | dt = datetime.now() + timedelta(hours=1) |
| 33 | time = "{hour}:{minute}".format(hour=dt.hour, minute=dt.minute) |
| 34 | return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": f"{name}-{time}-AEDT"}) |
| 35 | channel_data = get("https://discord.com/api/channels/{}".format(channel_id)).json() |
| 36 | if (status and t not in channel_data["name"]) or (not status and t in channel_data["name"]): |
| 37 | return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": f"{name}{t if status else f}"}) |
| 38 | else: |
| 39 | return True |
| 40 | |
| 41 | def a(obj): |
| 42 | if not isinstance(obj, bool) and str(obj.status_code)[0] != "2": |
| 43 | print(obj.headers) |
| 44 | print(obj.json()) |
| 45 | |
| 46 | data = requests.get("https://is.xivup.com/indexdata").json() |
| 47 | a(update_channel_name(Channel.login, data["Realms"]["LoginzServer"]["Status"] == 1)) |
| 48 | a(update_channel_name(Channel.gate, data["Realms"]["GatezServer"]["Status"] == 1)) |
| 49 | a(update_channel_name(Channel.dc, data["DCs"]["Materia"] == 1)) |
| 50 | a(update_channel_name(Channel.server, data["Realms"]["Sophia"]["Status"] == 1)) |
| 51 | a(update_channel_name(Channel.category, None)) |