Alyssa Smith revised this gist . Go to revision
1 file changed, 51 insertions
ffxiv-discord-status-category.py(file created)
| @@ -0,0 +1,51 @@ | |||
| 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)) | |
Newer
Older