Last active 1673646036

ffxiv-discord-status-category.py Raw
1#!/usr/bin/env python3
2import requests
3from datetime import datetime, timedelta
4
5with open(".bottoken") as f:
6 token = f.read().strip()
7t = '\u2705'
8f = '\u274c'
9
10class Channel:
11 category = ("1063529720538484786", "status")
12 login = ("1063529561486270494", "login")
13 gate = ("1063529595162337371", "gate")
14 dc = ("1063529626263101490", "materia")
15 server = ("1063529649507942501", "sophia")
16
17def 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
23def 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
29def 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
41def a(obj):
42 if not isinstance(obj, bool) and str(obj.status_code)[0] != "2":
43 print(obj.headers)
44 print(obj.json())
45
46data = requests.get("https://is.xivup.com/indexdata").json()
47a(update_channel_name(Channel.login, data["Realms"]["LoginzServer"]["Status"] == 1))
48a(update_channel_name(Channel.gate, data["Realms"]["GatezServer"]["Status"] == 1))
49a(update_channel_name(Channel.dc, data["DCs"]["Materia"] == 1))
50a(update_channel_name(Channel.server, data["Realms"]["Sophia"]["Status"] == 1))
51a(update_channel_name(Channel.category, None))