-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.pyw
82 lines (71 loc) · 3.1 KB
/
main.pyw
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
from configparser import ConfigParser # Used to get configs
from pypresence import Presence as DiscordRichPresence # Used for Discord RPC
import time, os, PIL.Image, PIL.ImageDraw, pystray, threading # Used for system tray and more
config = ConfigParser() # Loading config
config.read("settings.ini")
firstButton = config["BUTTON"]["firstButton"]
secondButton = config["BUTTON"]["secondButton"] # Setting all vars for easier access later.
button1 = config["BUTTON1"] # This can definitely be done better, but for now I'll go with this for simplicity.
button2 = config["BUTTON2"]
text = config["PRESENCE"]
image = config["IMAGE"]
defaultArgs = [text["details"], text["state"], image["largeImage"], text["imageText"], '', image["smallImage"], text["smallText"]]
rpc = DiscordRichPresence(config["PRESENCE"]["rpc"], pipe = 0)
rpc.connect()
def create_image():
# Generate an image and draw a pattern
image = PIL.Image.new('RGB', (64, 64), 'black')
dc = PIL.ImageDraw.Draw(image)
dc.rectangle(
(64 // 2, 0, 64, 64 // 2),
fill='white')
dc.rectangle(
(0, 64 // 2, 64 // 2, 64),
fill='white')
return image
def UpdateRPC(data):
details = data[0]
state = data[1]
largeImage = data[2]
largeImageTex = data[3]
smallImage = data[5]
smallImageTex = data[6]
if firstButton == 'True' and secondButton == 'True':
buttons = [{"label": button1["label"], "url": button1["url"]}, {"label": button2["label"], "url": button2["url"]}]
elif firstButton == 'True' and secondButton == 'False':
buttons = [{"label": button1["label"], "url": button1["url"]}]
else:
buttons = []
rpc.update(details = details, state = state, large_image = largeImage, large_text = largeImageTex,
small_image = smallImage, small_text = smallImageTex)
if buttons != []:
rpc.update(details = details, state = state, large_image = largeImage, large_text = largeImageTex,
small_image = smallImage, small_text = smallImageTex, buttons = buttons)
# System Tray Section Start
def on_clicked(icon, item):
if str(item) == "Exit":
icon.stop()
os._exit(0)
icon = pystray.Icon("Taco's RPC", icon = create_image(), menu = pystray.Menu(
pystray.MenuItem("Taco's RPC", on_clicked, enabled = False),
pystray.MenuItem("Exit", on_clicked)))
def Tray():
icon.run()
threading.Thread(target = Tray).start()
# System Tray Section End
print("Creating RPC.")
UpdateRPC(defaultArgs) # Create RPC with the default set arguments.
print("RPC Created.")
while True:
time.sleep(5)
new_config = ConfigParser()
new_config.read("settings.ini")
if new_config != config:
firstButton = new_config["BUTTON"]["firstButton"]
secondButton = new_config["BUTTON"]["secondButton"]
button1 = new_config["BUTTON1"]
button2 = new_config["BUTTON2"]
text = new_config["PRESENCE"]
image = new_config["IMAGE"]
args = [text["details"], text["state"], image["largeImage"], text["imageText"], '', image["smallImage"], text["smallText"]]
UpdateRPC(args)