From 428b46d41bbf0acda0fdee46e3476ede97e9765c Mon Sep 17 00:00:00 2001 From: Emma Lysne Date: Fri, 31 Jan 2025 01:44:29 -0800 Subject: [PATCH 1/3] Update documentation further and add a secret --- nuclearesrpc.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nuclearesrpc.py b/nuclearesrpc.py index 50d7dfa..2353bda 100644 --- a/nuclearesrpc.py +++ b/nuclearesrpc.py @@ -4,6 +4,7 @@ import requests import pypresence import subprocess +from typing import Dict VARIABLE_TYPES = { @@ -11,15 +12,17 @@ "GENERATOR_0_KW": float, "GENERATOR_1_KW": float, "GENERATOR_2_KW": float, - "CORE_IMMINENT_FUSION": str + "CORE_IMMINENT_FUSION": str, + "RODS_POS_ORDERED": float } -def get_all_vars(srv_url: str): +def get_all_vars(srv_url: str) -> Dict[str, float | str]: """ Request a list of dvars from the webserver :param srv_url: URL to the webserver, typically localhost:8785 :return: A dictionary of cast variables and their names + :rtype: Dict[str, float | str] """ results = {} for key, typeof in VARIABLE_TYPES.items(): @@ -33,9 +36,10 @@ def get_all_vars(srv_url: str): return results -def find_nucleares(): +def find_nucleares() -> psutil.Process | None: """ Find the running Nucleares.exe process, if it exists + :rtype: psutil.Process :return: A psutil Process representing Nucleares """ for process in psutil.process_iter(): @@ -90,6 +94,10 @@ def find_nucleares(): status = "Generator Offline" if dvars["CORE_IMMINENT_FUSION"] == "TRUE": details = "Imminent Meltdown" + if dvars["CORE_TEMP"] == 20 and dvars["RODS_POS_ORDERED"] == 87.5: + # I can give you my complete assurance that my work will be back to normal~ + details = "This mission is too important" + status = "The intruder must be dealt with" presence.update( pid=proc.pid, start=round(starttime), @@ -97,14 +105,16 @@ def find_nucleares(): state=status, large_image="nucleares" ) - #print( - # f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}" - #) + print( + f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}", + f"- Rods: {dvars['RODS_POS_ORDERED']}" + ) time.sleep(15) except requests.ConnectionError: print("Webserver connection lost, trying to re-establish...") if find_nucleares() is None: print("Nucleares is closed, RPC will close...") + presence.close() sys.exit(0) while 1: try: From 5dea5507043e4fe72f9906a0ae63edb7c73be7c9 Mon Sep 17 00:00:00 2001 From: Emma Lysne Date: Fri, 31 Jan 2025 01:53:05 -0800 Subject: [PATCH 2/3] Make variable sticky until restart --- nuclearesrpc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nuclearesrpc.py b/nuclearesrpc.py index 2353bda..b859b81 100644 --- a/nuclearesrpc.py +++ b/nuclearesrpc.py @@ -78,6 +78,7 @@ def find_nucleares() -> psutil.Process | None: print("Webserver is live, firing up RPC...") +mission = False presence.connect() print("Connected. Press Ctrl+C to Exit") while 1: @@ -94,8 +95,9 @@ def find_nucleares() -> psutil.Process | None: status = "Generator Offline" if dvars["CORE_IMMINENT_FUSION"] == "TRUE": details = "Imminent Meltdown" - if dvars["CORE_TEMP"] == 20 and dvars["RODS_POS_ORDERED"] == 87.5: + if (dvars["CORE_TEMP"] == 20 and dvars["RODS_POS_ORDERED"] == 87.5) or mission: # I can give you my complete assurance that my work will be back to normal~ + mission = True details = "This mission is too important" status = "The intruder must be dealt with" presence.update( From b7384948d41d25cf7683f9b55bda677602f2f435 Mon Sep 17 00:00:00 2001 From: Emma Lysne Date: Fri, 31 Jan 2025 01:53:35 -0800 Subject: [PATCH 3/3] Remove debug print --- nuclearesrpc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nuclearesrpc.py b/nuclearesrpc.py index b859b81..8b689a1 100644 --- a/nuclearesrpc.py +++ b/nuclearesrpc.py @@ -107,10 +107,10 @@ def find_nucleares() -> psutil.Process | None: state=status, large_image="nucleares" ) - print( - f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}", - f"- Rods: {dvars['RODS_POS_ORDERED']}" - ) + #print( + # f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}", + # f"- Rods: {dvars['RODS_POS_ORDERED']}" + #) time.sleep(15) except requests.ConnectionError: print("Webserver connection lost, trying to re-establish...")