-
Notifications
You must be signed in to change notification settings - Fork 1
/
presence.py
96 lines (91 loc) · 3.97 KB
/
presence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from pypresence import Presence
import json, pprint, configparser, time, psutil, sys
import pygetwindow as gw
import os
class rich_presence:
def __init__(self):
self.config = configparser.ConfigParser()
self.config.read("config.ini")
self.assets = json.load(open("assets.json", "r"))
self.client_id = self.config["Rich Presence"]["client_id"]
self.RPC = Presence(self.client_id)
self.RPC.connect()
self.previous_format_dict = {}
self.previous_format_dict["start"] = time.time()
while True:
if (
"Ninja Kiwi Archive.exe" in (p.name() for p in psutil.process_iter())
) and (sys.platform.startswith("win32")):
pvars = self.presence_gen(self.format_gen())
# print("-------------------------\npresence_dict\n-------------------------")
# pprint.pprint(pvars)
self.RPC.update(
large_image=pvars["large_image"],
large_text=pvars["large_text"],
small_image=pvars["small_image"],
small_text=pvars["small_text"],
details=pvars["details"],
state=pvars["state"],
start=pvars["start"],
)
pprint.pprint(pvars)
print("--------------------")
elif sys.platform.startswith("win32"):
print("Ninja Kiwi Archive is not running")
self.RPC.clear()
if close_on_close:
exit()
else:
pvars = self.presence_gen(self.format_gen)
# print("-------------------------\npresence_dict\n-------------------------")
# pprint.pprint(pvars)
self.RPC.update(
large_image=pvars["large_image"],
large_text=pvars["large_text"],
small_image=pvars["small_image"],
small_text=pvars["small_text"],
details=pvars["details"],
state=pvars["state"],
start=pvars["start"],
)
pprint.pprint(pvars)
print("--------------------")
time.sleep(15)
def format_gen(self):
self.format_dict = {
"game_hf": "",
"game_image": "",
"icon": "icon",
"in_game": False,
"game_updated": True,
"start": self.previous_format_dict["start"],
}
self.windows = gw.getAllTitles()
for window in self.windows:
if window in self.assets["games"]:
self.format_dict["game_hf"] = window
self.format_dict["game_image"] = self.assets["games"][window]["image"]
self.format_dict["in_game"] = True
if self.format_dict != self.previous_format_dict:
self.format_dict["start"] = time.time()
self.previous_format_dict = self.format_dict
return self.format_dict
def presence_gen(self, format_dict):
self.presence_dict = {"start": format_dict["start"]}
if format_dict["in_game"]:
for field in list(self.config["In Menu"].keys()):
self.presence_dict[field] = self.config["In Game"][field].format(
**self.format_dict
)
else:
for field in list(self.config["In Game"].keys()):
self.presence_dict[field] = self.config["In Menu"][field].format(
**self.format_dict
)
for field in list(self.presence_dict.keys()):
if self.presence_dict[field] == "" or self.presence_dict[field] == []:
self.presence_dict[field] = None
return self.presence_dict
os.chdir(sys.path[0])
close_on_close = len(sys.argv) > 1 and sys.argv[1] == "bkgrnd"
rich_presence()