Created
January 14, 2023 07:40
-
-
Save alyssadev/cc991d7d206f3e71afbac0e093a90954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment