diff options
author | Jesusaves <cpntb1@ymail.com> | 2024-02-05 19:07:46 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2024-02-05 19:07:46 -0300 |
commit | efca87a1a71d76c9ce461f677ee1128156ee3e45 (patch) | |
tree | ff0d5abf1539678edb832497f1eb8f4b755e0660 | |
parent | 2f775f73a509aa4b66f470466d697bf475a31534 (diff) | |
download | tkinter-efca87a1a71d76c9ce461f677ee1128156ee3e45.tar.gz tkinter-efca87a1a71d76c9ce461f677ee1128156ee3e45.tar.bz2 tkinter-efca87a1a71d76c9ce461f677ee1128156ee3e45.tar.xz tkinter-efca87a1a71d76c9ce461f677ee1128156ee3e45.zip |
Discord RPC can now be used.
Deleting the folder before running will disable Discord.
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | __main__.py | 63 |
2 files changed, 62 insertions, 3 deletions
@@ -1,2 +1,4 @@ *.b64 manaplus/ +__pycache__ + diff --git a/__main__.py b/__main__.py index 8ff730c..ef52fa7 100755 --- a/__main__.py +++ b/__main__.py @@ -16,6 +16,7 @@ from tkinter.messagebox import showinfo, showerror, askyesno from functools import partial OBFS = uuid.getnode() % 256 # Get a number which *usually* doesn't change +OBFS = 185 # <- For debugging (FIXME ^ above didn't held up in practice) print("Obfuscation key = %d" % OBFS) # <- Just to not leave it in plain text ## Internal wrapper for preferences @@ -40,6 +41,7 @@ try: ## XXX: use ord() if int(x) fails pref = bytearray(int(x) ^ int(OBFS) for x in pref) pref = pref.decode('utf8') + print(repr(pref)) pref = json.loads(str(pref)) print("User settings loaded...") except: @@ -53,7 +55,8 @@ except: "mana": False, # <- Prefer Mana over ManaVerse "plus": False, # <- Prefer ManaPlus over ManaVerse "local": True, # <- system-wide vs manaplus/ folder - "shell": True} # <- output to console + "shell": True, # <- output to console + "discord": None} # <- Whenever to use Discord RPC or not ## If it is an error, give an option to not destroy the old settings if ("FileNotFoundError" in err): _savePref() @@ -64,6 +67,55 @@ except: else: saveSettings = False +## TODO FIXME +if not "discord" in list(pref.keys()): + pref["discord"] = True + +## Auto-detect if Discord should be used +## Don't crash only if a new FLOSS purist will immediately deleted discordrpc +if pref["discord"] in [True, None]: + try: + import discordrpc + except ImportError: + if pref["discord"] == None: + pref["discord"] = False + else: + raise + +## Value may have changed +if pref["discord"]: + try: + _rpc = discordrpc.RPC.set_id(app_id=840427221193195541) + _rpc.set_activity( + state="The Mana World - Minimal", + details="Main Menu", + large_image="launcher", + large_text="Mana Launcher", + timestamp=_rpc.timestamp + ) + except discordrpc.exceptions.DiscordNotOpened: + err = traceback.format_exc().split("\n")[-2] + _rpc = None + print("Failed to load Discord RPC!\n%s" % err) + +## Value may have changed +if not pref["discord"]: + _rpc = None + +## This is how we'll actually update Discord stuff +def RPCUpdate(status, image): + global _rpc, pref + if not pref["discord"] or _rpc is None: + return + _rpc.set_activity( + state="The Mana World - Minimal", + details=status, + large_image=image, + large_text="Mana Launcher", + timestamp=_rpc.timestamp + ) + return + ## Prepare some basic stuff execute=subprocess.call serverlist = [] @@ -92,17 +144,19 @@ if "localhost" in VAULT_HOST: vault.verify=False ##################################### +## Just print stuff to console, bold or not def stdout(message, bd=False): if bd: print("\033[1m%s\033[0m" % message) else: print(message) +## Smart Delay def sdelay(delta=0.02): time.sleep(delta) return -# IF Then Else (IFTE) +## IF Then Else (IFTE) def ifte(ifs, then, elses): if (ifs): return then @@ -116,7 +170,7 @@ def ifte(ifs, then, elses): def san(cmd): return cmd.replace(";", "").replace("|", "").replace(">", "").replace("<", "").replace("&", "").replace("(", "").replace(")", "").replace("\n", "").replace("[[", "").replace("]]", "") -# Returns number of seconds since UNIX EPOCH +## Returns number of seconds since UNIX EPOCH def now(): return int(time.time()) @@ -270,6 +324,9 @@ def launch_game(idx): if pref["mana"]: OPT=OPT.replace(" -L ", " --localdata-dir ") + ## Update Discord if relevant + RPCUpdate(serverlist[idx]["Name"], serverlist[idx]["Back"]) + ## Execute the app ## TODO: Threading? if pref["shell"]: |