Skip to content

Commit b0cd5db

Browse files
Merge pull request #13 from DaRealCodeWritten/nucleares-v2-patch
Nucleares V2 Bugfixing
2 parents 9fd61b0 + 9865d51 commit b0cd5db

3 files changed

Lines changed: 56 additions & 18 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ venv/
55
# Ignore build files
66
build/
77
dist/
8-
nuclearesrpc.spec
8+
nuclearesrpc.spec
9+
10+
# Ignore log files
11+
*.log

nuclearesrpc.py

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,37 @@
44
import requests
55
import pypresence
66
import subprocess
7+
import argparse
8+
import logging
9+
import traceback
10+
import ctypes
711
from typing import Dict
812
import ctypes
913

1014

15+
__version__ = "v2.0.0"
16+
parser = argparse.ArgumentParser(
17+
prog="Nucleares Presence Client",
18+
description="Nucleares Rich Presence Client for Discord",
19+
epilog=f"Version {__version__}"
20+
)
21+
parser.add_argument("-v", "--version", action="store_true")
22+
parser.add_argument("-d", "--debug", action="store_true")
23+
params = parser.parse_args()
24+
logging.basicConfig(
25+
level="DEBUG" if params.debug else "INFO",
26+
filename="debug.log" if params.debug else None
27+
)
28+
29+
30+
if params.version:
31+
print("Nucleares Rich Presence Client")
32+
print(f"Client Version: {__version__}")
33+
print(f"PyPresence Version: {pypresence.__version__}")
34+
input("Press Enter to exit...")
35+
sys.exit(0)
36+
37+
1138
VARIABLE_TYPES = {
1239
"CORE_TEMP": float,
1340
"GENERATOR_0_KW": float,
@@ -27,7 +54,7 @@ def get_all_vars(srv_url: str) -> Dict[str, float | str]:
2754
"""
2855
results = {}
2956
for key, typeof in VARIABLE_TYPES.items():
30-
print(f"Getting key {key}, looking for type {typeof}")
57+
logging.debug(f"Getting key {key}, looking for type {typeof}")
3158
res = requests.get(
3259
srv_url,
3360
{
@@ -37,7 +64,7 @@ def get_all_vars(srv_url: str) -> Dict[str, float | str]:
3764
try:
3865
results[key] = typeof(res.text)
3966
except ValueError:
40-
print(f"Conversion of '{res.text}' to type {typeof} failed")
67+
logging.error(f"Conversion of '{res.text}' to type {typeof} failed")
4168
return results
4269

4370

@@ -54,24 +81,24 @@ def find_nucleares() -> psutil.Process | None:
5481

5582

5683
if len(sys.argv) > 1:
57-
if sys.argv[1].endswith("Nucleares.exe"):
58-
# Client is launching through steam, we are expected to launch it on Steam's behalf
59-
game_exec = subprocess.Popen(sys.argv[1])
60-
84+
for obj in sys.argv:
85+
if obj.endswith("Nucleares.exe"):
86+
# Client is launching through steam, we are expected to launch it on Steam's behalf
87+
game_exec = subprocess.Popen(obj)
6188

6289
ctypes.windll.user32.MessageBoxW(0, "Remember to turn on the WebServer, else NuclearesRPC will not work!", "Reminder!", 64)
6390
cid = 1331101603649818786
6491
presence = pypresence.Presence(cid, pipe=0)
65-
print("Locating running Nucleares executable...")
92+
logging.info("Locating running Nucleares executable...")
6693
proc = find_nucleares()
6794
while proc is None:
6895
proc = find_nucleares()
6996
time.sleep(5)
70-
print("Found: " + str(proc.pid))
97+
logging.debug("Found: " + str(proc.pid))
7198
starttime = time.time()
7299

73100

74-
print("Looking for webserver...")
101+
logging.info("Waiting for webserver...")
75102
port = "8785"
76103
url = "http://localhost:" + port + "/"
77104
while 1:
@@ -81,12 +108,12 @@ def find_nucleares() -> psutil.Process | None:
81108
break
82109
except requests.ConnectionError as e:
83110
time.sleep(5)
84-
print("Webserver is live, firing up RPC...")
111+
logging.info("Webserver is live, firing up RPC...")
85112

86113

87114
mission = False
88115
presence.connect()
89-
print("Connected. Press Ctrl+C to Exit")
116+
logging.info("Connected. Press Ctrl+C to Exit")
90117
while 1:
91118
try:
92119
dvars = get_all_vars(url)
@@ -113,15 +140,15 @@ def find_nucleares() -> psutil.Process | None:
113140
state=status,
114141
large_image="nucleares"
115142
)
116-
#print(
117-
# f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}",
143+
logging.debug(
144+
f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}",
118145
# f"- Rods: {dvars['RODS_POS_ORDERED']}"
119-
#)
146+
)
120147
time.sleep(15)
121148
except requests.ConnectionError:
122-
print("Webserver connection lost, trying to re-establish...")
149+
logging.warning("Webserver connection lost, trying to re-establish...")
123150
if find_nucleares() is None:
124-
print("Nucleares is closed, RPC will close...")
151+
logging.info("Nucleares is closed, RPC will close...")
125152
presence.close()
126153
sys.exit(0)
127154
while 1:
@@ -131,5 +158,13 @@ def find_nucleares() -> psutil.Process | None:
131158
break
132159
except requests.ConnectionError as e:
133160
time.sleep(5)
134-
print("Connected!")
161+
logging.info("Connected!")
135162
continue
163+
164+
except Exception as e:
165+
logging.critical("Client has run into an unexpected error and cannot continue")
166+
logging.critical("NuclearesRPC has crashed.", exc_info=e)
167+
logging.critical("Please send this error when asking for support")
168+
presence.close()
169+
input("Press Enter to exit...")
170+
sys.exit(1)

requirements.txt

562 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)