Skip to content

Commit

Permalink
Merge pull request qwertyquerty#17 from LetterN/fancy-thing-for-teegee
Browse files Browse the repository at this point in the history
adds more fancy stuff, also fixes FTL13 link
  • Loading branch information
qwertyquerty authored Mar 25, 2019
2 parents 7f054ce + cc46d62 commit 82a50c0
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 123 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignores vs code config
.vscode/
# Ignores local cached file
__pycache__/
19 changes: 10 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"Goonstation RP #1": ["Goonstation RP #1", "goonhub", "goon1.goonhub.com", 26100, "fetch"],
"Yogstation 13": ["Yogstation 13", "yogstation", "game.yogstation.net", 4133, "fetch"],
"BeeStation 13": ["BeeStation", "beestation", "198.58.107.171", 3333, "fetch"],
"ss13": ["Unknown Server", "ss13"],
"Oracle Station | Medium RP": ["Oracle Station", "oraclestation"], #"byond.oraclestation.com", 5000
"Hippie Station": ["Hippie Station", "hippiestation", "62.210.11.24", 1337, "fetch"],
"/tg/Station Bagil": ["Station Bagil", "tgstation", "bagil.aws.tgstation13.org", 2337, "fetch"],
"/tg/Station Sybil": ["Station Sybil", "tgstation", "sybil.aws.tgstation13.org", 1337, "fetch"],
"/tg/Station Terry": ["Station Terry", "tgstation", "terry.tgstation13.org", 3337, "fetch"],
"/tg/Station Bagil": ["Bagil Station", "tgstation", "bagil.tgstation13.org", 2337, "fetch"],
"/tg/Station Sybil": ["Sybil Station", "tgstation", "sybil.tgstation13.org", 1337, "fetch"],
"/tg/Station Terry": ["Terry Station", "tgstation", "terry.tgstation13.org", 3337, "fetch"],
"TerraGov Marine Corps": ["TGMC", "tgmc", "tgmc.tgstation13.org", 5337, "fetch"],
"[99% FREE LAG] Convict Conclave": ["Convict Conclave", "ss13"],
"[ss13.ru] Yellow Circus": ["Yellow Circus", "ss13"],
"Persistence Station 13": ["Persistence Station", "persistence"],
"Apollo Gaming": ["Apollo Gaming","apollo"],
"Lebensraum Alpha": ["Lebensraum Alpha", "ss13"],
"Baystation 12": ["Baystation 12", "bs12", "https://baystation12.net/status.dat", 80, "http"],
"FTL13": ["FTL13", "ftl13", "ftl13.com", 7777, "fetch"],
"Baystation 12": ["Baystation 12", "bs12", "baystation12.net/status.dat", 80, "http"],
"FTL13": ["FTL13", "ftl13", "stable.ftl13.com", 7777, "fetch"],
"Tool Box Station": ["Toolbox Station", "toolbox"],
"Pressurized Roleplay": ["Pressurized Roleplay", "pressure"],
"StarTrek13": ["Star Trek 13", "startrek"],
Expand All @@ -24,8 +24,9 @@
"Aurora Station": ["Aurora Station", "ss13"],
"VOREStation": ["VOREStation", "citadel", "citadel-station.net", 44150, "fetch"],
"Citadel Station 13": ["Citadel Station", "citadel", "citadel-station.net", 44130, "fetch"],
"Colonial Marines": ["Colonial Marines", "cm"]
"Colonial Marines": ["Colonial Marines", "cm"],
"ss13": ["Unknown Server", "ss13"]
}


client_id = "440289271580983308"
# formula: "Server Name": ["Big text name", "icon", "ip", port]
client_id = "440289271580983308"
241 changes: 127 additions & 114 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,119 +11,132 @@
import webbrowser

if "join" in sys.argv:
print("joining game...")
def join(ev):
ie = webbrowser.get(webbrowser.iexplore)
ie.open('google.com')
rp = pypresence.Client(client_id)
rp.start()
print(rp.read())
rp.register_event("ACTIVITY_JOIN", join)
rp.loop.run_forever()
print("joining game...")
def join(ev):
ie = webbrowser.get(webbrowser.BackgroundBrowser)
ie.open('') #py 3.6 breaks this
rp = pypresence.Client(client_id)
rp.start()
print(rp.read())
rp.register_event("ACTIVITY_JOIN", join)
rp.loop.run_forever()

else:

while True:
try:
rp = pypresence.Client(client_id)
rp.start()
break
except:
time.sleep(20)





def get_hwnds_for_pid (pid):
def callback (hwnd, hwnds):
if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd):
_, found_pid = win32process.GetWindowThreadProcessId (hwnd)
if found_pid == pid:
hwnds.append (hwnd)
return True

hwnds = []
win32gui.EnumWindows (callback, hwnds)
return hwnds



def get_server():

p = [proc for proc in psutil.process_iter() if proc.name() == "dreamseeker.exe"]

p = p[0]

windows=get_hwnds_for_pid(p.pid)


windowtitles = [i for i in [str(win32gui.GetWindowText(item))
for item in windows] if i != ""]


for title in windowtitles:
if not title == "Space Station 13":
for i in servers.keys():
if title.startswith(i):

return servers[i]

else:
server = "ss13"
return servers[server]


while True:
try:
server = get_server()
activity = {"state": server[0], "large_text": server[0], "large_image":server[1]}
if len(server) == 5:
try:
if server[4] == "fetch":
status = util.fetch(server[2], server[3], "status")
elif server[4] == "http":
status = requests.get(server[2]).json()

if server[0] in ["Baystation 12"]:
details = status["map"]+" | "+str(status["players"])+" players"

elif server[0] in ["Goonstation #2","Goonstation RP #1", "Hippie Station", "BeeStation", "FTL13", "Station Bagil", "Station Terry", "Station Sybil", "Citadel Station", "Yogstation 13"]:
activity["details"] = status["map_name"]+" | "+str(status["players"])+" players"

if server[0] in ["Goonstation #2","Goonstation RP #1"]:
activity["start"] = int(time.time())-int(status["elapsed"])

elif server[0] in ["Hippie Station", "BeeStation", "FTL13", "Station Bagil", "Station Terry", "Station Sybil", "Citadel Station", "Yogstation 13"]:
activity["start"] = int(time.time())-int(status["round_duration"])

except Exception as E:
pass


#activity["party_id"] = "234412341"
#activity["join"] = "432452421342"
#activity["party_size"] = [1,4]
#activity["match"] = "23431234"
#activity["instance"] = True
#activity["spectate"] = "53242523421"

rp.set_activity(**activity)

time.sleep(15)

except Exception as e:
print(e)
time.sleep(10)
try:
rp.clear_activity()
time.sleep(5)
except Exception as e:
print(e)
while True:
try:
rp = pypresence.Client(client_id)
rp.start()
break
except:
time.sleep(20)
while True:
try:
rp = pypresence.Client(client_id)
rp.start()
break
except:
time.sleep(15)

def get_hwnds_for_pid (pid):
def callback (hwnd, hwnds):
if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd):
_, found_pid = win32process.GetWindowThreadProcessId (hwnd)
if found_pid == pid:
hwnds.append (hwnd)
return True
hwnds = []
win32gui.EnumWindows (callback, hwnds)
return hwnds

def get_server():
p = [proc for proc in psutil.process_iter() if proc.name() == "dreamseeker.exe"]
p = p[0]

windows=get_hwnds_for_pid(p.pid)
windowtitles = [i for i in [str(win32gui.GetWindowText(item))
for item in windows] if i != ""]
for title in windowtitles:
if not title == "Space Station 13":
for i in servers.keys():
if title.startswith(i):
return servers[i]
else:
server = "ss13"
return servers[server]

while True:
try:
server = get_server()
activity = {"large_text": server[0], "large_image":server[1]}
if len(server) >= 5:
try:
if server[4] == "fetch":
status = util.fetch(server[2], server[3], "status")
print("Status (fetch): "+str(status))
elif server[4] == "http":
status = requests.get(server[2]).json()
print("Status (http): "+str(status))

if server[0] in ["Bagil Station", "Terry Station", "Sybil Station", "Citadel Station", "FTL13"]:
activity["start"] = int(time.time())-int(status["round_duration"])
activity["party_id"] = str(status["round_id"]) + " | " + status["map_name"] #apparently terry has NO revision
#activity["join"] = party id + server name
#activity["spectate"] = party id + server name

if status["round_id"]: #check if round id is avalable
activity["details"] = "Map: "+status["map_name"]+" | Gamemode: "+status["mode"]+" | Round id: "+str(status["round_id"])
else:
activity["details"] = "Map: "+status["map_name"]+" | Gamemode: "+status["mode"]

if status["popcap"]: #fetch popcap
activity["party_size"] = [int(status["players"])] + [int(status["popcap"])]
else: #best guess maxcap
activity["party_size"] = [int(status["players"])] + [90]

actualstatus = int(status["gamestate"])
if actualstatus == 0: #0: init, 1:lobbywait 2:start
activity["state"] = "Initializing game"
activity["instance"] = False
elif actualstatus == 1:
activity["state"] = "Waiting on Lobby"
activity["instance"] = True
elif actualstatus == 2:
activity["state"] = "Starting"
elif actualstatus == 3:
activity["state"] = "Started"
elif actualstatus == 4:
activity["state"] = "Round ended!"
activity["instance"] = False

if server[0] in ["Baystation 12"]:
activity["details"] = "Map: "+status["map"]+" | Players"+str(status["players"])
elif server[0] in ["Goonstation #2","Goonstation RP #1", "Hippie Station", "BeeStation", "Yogstation 13"]:
activity["details"] = "Map: "+status["map_name"]+" | Players"+str(status["players"])
elif server[0] in ["VOREStation"]: #apparently this fucker dosen't return map data
activity["details"] = "Gamemode: "+status["mode"]+" | Players"+status["players"]

if server[0] in ["Goonstation #2","Goonstation RP #1"]:
activity["start"] = int(time.time())-int(status["elapsed"])
elif server[0] in ["Hippie Station", "BeeStation", "Yogstation 13"]:
activity["start"] = int(time.time())-int(status["round_duration"])
elif server[0] in ["VOREStation"]: #andd also it fucking returns time (in string) not in VARS!
ittimetostop = status["roundduration"]
ittimetostop = ittimetostop.split(':')
activity["start"] = int(time.time())-(int(ittimetostop[0]) + int(ittimetostop[1]))

except Exception as E:
print(E)
pass

rp.set_activity(**activity)
print(str(activity))
time.sleep(15)

except Exception as e:
print(e)
time.sleep(10)
try:
rp.clear_activity()
time.sleep(5)
except Exception as e:
print(e)
while True:
try:
rp = pypresence.Client(client_id)
rp.start()
break
except:
time.sleep(20)

0 comments on commit 82a50c0

Please sign in to comment.