Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit a495a12

Browse files
committed
Fixes #3 + misc changes
added discord app media changed presence text a bit avoid using timer.sleep shorter toasts more info in readme
1 parent 840a335 commit a495a12

7 files changed

Lines changed: 50 additions & 38 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ csgo_richpresence.spec
77
csgo_richpresence.exe
88
csgo_richpresence_installer.spec
99
csgo_richpresence_installer.exe
10-
discordapp
1110
zip.exe
1211
Thumbs.db
1312
desktop.ini

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ Once you feed CS:GO a specific and custom configuration file, it will start send
3636

3737
## Manual:
3838

39-
1. Place the `gamestate_integration_discordrpc.cfg` file from this repository in the `cfg` folder located in your game's installation directory. The game should now be trying to send info to the program when you restart it. (port `3000` is used by default in both the file and program)
39+
1. Place the `gamestate_integration_discordrpc.cfg` file from this repository in the `cfg` folder located in your game's installation directory. *(Default, on Windows: `C:\Program Files (x86\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg`)* The game should now be trying to send info to the program when you restart it. (port `3000` is used by default in both the file and program)
4040
2. Launch the program, **keep it open until you're done playing**.
4141
- If you don't want to install Python and everything else, use the [latest release](https://github.com/Tenrys/csgo_richpresence/releases/latest)'s executable.
4242

4343
Your Discord status will now change according to what is happening in the game!
4444

45+
You don't need to setup your own Discord application, but I've included some the assets I've used for it if you need to.
46+
If you're a developer you should be able to understand how to figure everything out starting from [your Discord applications page](https://discordapp.com/developers/applications/me).
47+
The team icons are named `ct` and `t` and are considered small images. The map icons are just taken from the game's original maps folder, are considered large images and are named all lowercase based on the map's file name.
48+
4549
## Command line options:
4650

4751
### Main program:
@@ -68,3 +72,4 @@ Keep in mind this is meant to be a fun project for me to improve my Python skill
6872

6973
- More support for other operating systems?
7074
- Avoid using more than one tray icon (currently win10toaster creates an extra for every notificaton)
75+
- Figure out how to add "Ask to Join" and "Spectate" features (probably won't be allowed to just yet)

discordapp/app_icon.png

11.5 KB
Loading

discordapp/csgo_icon.png

789 KB
Loading

discordapp/ct_icon.png

253 KB
Loading

discordapp/t_icon.png

257 KB
Loading

main.py

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
from http.server import BaseHTTPRequestHandler, HTTPServer
77
import json
88

9+
want_exit = False
10+
def exit():
11+
print("Exiting...")
12+
sys.exit()
13+
def state_exit(*args, **kwargs):
14+
global want_exit
15+
want_exit = True
16+
917

1018

1119
phases = {
1220
"freezetime": "freeze time",
1321
"live": "playing",
14-
"over": "round over"
22+
"over": "round over",
23+
"warmup": "warmup"
1524
}
1625
modes = {
1726
"casual": "Casual",
@@ -39,6 +48,9 @@ def __init__(self, *args, **kwargs):
3948
HTTPServer.__init__(self, *args, **kwargs)
4049

4150
def service_actions(self):
51+
if want_exit:
52+
self.server_close()
53+
exit()
4254
running = False
4355
for pid in psutil.pids():
4456
try:
@@ -90,14 +102,14 @@ def handle_json(self, data):
90102
team_text = "Terrorist"
91103
else:
92104
team_text = "Spectator" # never seen unless I add an icon
93-
team_text += " - " + str(state["health"]) + " HP, " + str(state["armor"]) + " Armor"
105+
# team_text += " - " + str(state["health"]) + " HP, " + str(state["armor"]) + " Armor"
106+
team_text += " - $" + str(state["money"])
94107

95108
# player stats info
96-
stats_text = str(match_stats["kills"]) + "|"
97-
stats_text += str(match_stats["assists"]) + "|"
98-
stats_text += str(match_stats["deaths"]) + " - "
109+
stats_text = str(match_stats["kills"]) + "K / "
110+
stats_text += str(match_stats["assists"]) + "A /"
111+
stats_text += str(match_stats["deaths"]) + "D / "
99112
stats_text += str(match_stats["mvps"]) + " MVPs"
100-
stats_text += " - $" + str(state["money"])
101113

102114
# compile activity dict
103115
activity = {
@@ -163,13 +175,7 @@ def do_POST(self):
163175
def notify(msg):
164176
print(msg)
165177
if toaster: # silent mode only
166-
toaster.show_toast(icon_path="icon.ico", title=our_name, msg=msg, duration=10, threaded=True)
167-
168-
def exit():
169-
notify("Exiting...")
170-
if systray: # silent mode only
171-
systray.shutdown()
172-
sys.exit()
178+
toaster.show_toast(icon_path="icon.ico", title=our_name, msg=msg, duration=5, threaded=True)
173179

174180
parser = argparse.ArgumentParser(prog="csgo_richpresence")
175181
parser.add_argument("-S", "--silent", action="store_true", default=False, help="hide the console window entirely, leaving the program to run in the background (Windows only)")
@@ -230,44 +236,46 @@ def hide_window(pid):
230236
hide_window(our_process.parent().parent().pid) # fuck it, why not
231237

232238
toaster = ToastNotifier()
233-
systray = SysTrayIcon("icon.ico", our_name, on_quit=exit)
239+
systray = SysTrayIcon("icon.ico", our_name, on_quit=state_exit)
234240
systray.start()
235241

236242
server_address = ("127.0.0.1", port)
237243
httpd = None
244+
next_csgo_check = 0
238245
try:
239246
notify("Discord Rich Presence for CS:GO is now running in the background.")
240247
while True:
241-
print("Looking for csgo.exe...")
242-
found_csgo = False
243-
for pid in psutil.pids():
244-
try: # same as for enum_window_callback
245-
p = psutil.Process(pid)
246-
if p.name() == "csgo.exe":
247-
found_csgo = True
248-
break
249-
except:
250-
# print("Something could have gone wrong here while finding csgo.exe, ignore this")
251-
pass
252-
if found_csgo:
253-
notify("Found csgo.exe, running server.")
254-
if systray:
255-
systray.update(hover_text=our_name + ": running")
256-
257-
httpd = CSGOGameStateServer(server_address, CSGOGameStateRequestHandler)
258-
print("Starting httpd at {}:{}".format(server_address[0], port))
259-
httpd.serve_forever()
260-
time.sleep(30)
248+
if want_exit:
249+
exit()
250+
if next_csgo_check < time.time():
251+
print("Looking for csgo.exe...")
252+
found_csgo = False
253+
for pid in psutil.pids():
254+
try: # same as for enum_window_callback
255+
p = psutil.Process(pid)
256+
if p.name() == "csgo.exe":
257+
found_csgo = True
258+
break
259+
except:
260+
# print("Something could have gone wrong here while finding csgo.exe, ignore this")
261+
pass
262+
if found_csgo:
263+
notify("Found csgo.exe, running server.")
264+
if systray:
265+
systray.update(hover_text=our_name + ": running")
266+
267+
httpd = CSGOGameStateServer(server_address, CSGOGameStateRequestHandler)
268+
print("Starting httpd at {}:{}".format(server_address[0], port))
269+
httpd.serve_forever()
270+
next_csgo_check = time.time() + 30
261271
except KeyboardInterrupt:
262272
if httpd:
263273
print('Stopping httpd...')
264274
httpd.server_close()
265-
266275
exit()
267276
except Exception as e:
268277
notify("Error: " + str(e))
269278
input("Press Enter to quit.")
270-
271279
exit()
272280

273281
# so many try statements in this script jesus fuck i don't know how to code

0 commit comments

Comments
 (0)