forked from Tominous/owrpc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathowrpc.py
More file actions
339 lines (299 loc) · 15.1 KB
/
owrpc.py
File metadata and controls
339 lines (299 loc) · 15.1 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# owrpc.py | Overwatch RPC Client
# https://www.github.com/maxicc/owrpc
try:
### - IMPORTS AND MAIN SETUP - ###
# Importing default Python modules
import time
import sys
import random
try:
# Importing custom project-specific modules
import requests
from owrpcconfig import configs as x
from owrpcconfig import maps as m
# Importing pypresence
from pypresence import Presence
# If imports didn't work...
except Exception as e:
# Warn the user that the modules can't be imported then exit with error code 1
print("[!] Error! Couldn't import a module. Did you download the dependencies (requests and pypresence)?")
print("[!] Check the instructions at git.io/owrpc and make sure, then try running again.")
print("[!] If you need more help, join the Discord at discord.gg/keErGbZ and show this to maxic:")
print(str(e))
sys.exit(1)
try:
# Try to open .nocol, if we can't then it doesn't exist so we can import normal colours
f = open(".nocol","r")
f.close()
from mansi import nocolours as c
except:
from mansi import colours as c
# Initialise the Discord Presence using pypresence then connect to Discord
dp = Presence(x.client)
dp.connect()
# Define the status class
class status():
ingame = 0
devmode = False
currmap = ''
currmode = ''
presets = {
"example":["details","state","overwatch","large_text","overwatch-dark","small_text"],
"inmenus":["In Menus",None,"overwatch","owrpc v" + x.ver + " by maxic#9999! git.io/owrpc",None,None],
"inqueue":["In Queue",None,"overwatch","owrpc v" + x.ver + " by maxic#9999! git.io/owrpc",None,None],
"inqueue-comp":["Competitive: In Queue",None,"overwatch","owrpc v" + x.ver + " by maxic#9999! git.io/owrpc",None,None],
"inqueue-quick":["Quick Play: In Queue",None,"overwatch","owrpc v" + x.ver + " by maxic#9999! git.io/owrpc",None,None],
"inqueue-arcade":["Arcade: In Queue",None,"overwatch","owrpc v" + x.ver + " by maxic#9999! git.io/owrpc",None,None],
"devmode":["Overwatch RPC Client","I'm being programmed!","maxic","Created by maxic#9999","overwatch","Under development!"]
}
### - DEFINE FUNCTIONS - ###
def buildList(source):
list = ''
for x in source.keys():
if list == '':
list = "'" + x + "'"
else:
list = list + ", '" + x + "'"
return list
def clearPresence():
try:
dp.clear()
except Exception as e:
print(c.fail + "Couldn't clear your presence! :(")
print(c.fail + "The error message from pypresence is: " + str(e))
sys.exit(1)
print(c.success + "Your presence has been cleared! Discord may take a few seconds to update.")
def devMode():
"""
This function will toggle the value of status.devmode when called.
status.devmode starts as False.
"""
status.devmode = not status.devmode
if status.devmode == True:
print(c.success + "Enabled development mode. Be afraid!")
clearPresence()
else:
print(c.success + "Disabled development mode... you can relax now.")
clearPresence()
def showGreeting():
print(c.smile + "Overwatch RPC Client v" + x.ver + " by github.com/maxicc (maxic#9999)")
onlver = requests.get("https://maxicc.github.io/owrpc/VERSION.txt").text.rstrip()
if x.ver != onlver:
print(c.warn + "You're out-of-date! The latest version on GitHub is " + str(onlver) + " and you're on " + x.ver + ".")
print(c.warn + "Time to update! Clone the git repo again or redownload the files from git.io/owrpc.")
else:
print(c.success + "You're up-to-date! Thanks for using the latest version.")
print(c.info + "Need help? Want a new feature? Join the Discord at discord.gg/keErGbZ")
print(c.info + "...or open an issue on the GitHub page at git.io/owrpc!")
print(c.blank + random.choice(owquotes))
def setupGame():
modes = buildList(m.modes)
print(c.info + "What gamemode are you playing?")
print(c.info + "Your options are: " + modes)
user = input(c.ask)
mode = ["","",""]
while mode == ["","",""]:
if user not in modes:
print(c.fail + "That's not a valid mode. Your options are: " + modes)
user = input(c.ask)
else:
mode[0] = user # Config file key
mode[1] = m.modes[user][0] # Friendly mode name
mode[2] = m.modes[user][1] # Map set used
print(str(mode))
if mode[2] == "standard":
maps = buildList(m.standard)
elif mode[2] == "any":
maps = buildList(m.standard) + ", " + buildList(m.arcade)
else:
print(c.fail + "Something unexpected went wrong! Please report this at git.io/owrpc or discord.gg/keErGbZ and say you hit point 1.")
print(c.info + "If you try and do whatever you were trying to do again, it should work. Hopefully. Sorry about that.")
print(c.info + "What map are you playing on?")
print(c.info + "Your options are: " + maps)
user = input(c.ask)
map = ["","","",""]
while map == ["","","",""]:
if (mode[2] == "standard" and user not in m.standard) or (mode[2] == "any" and user not in m.standard and user not in m.arcade):
print(c.fail + "That's not a valid map. Please try again!")
user = input(c.ask)
elif (mode[2] == "standard" and user in m.standard) or (mode[2] == "any" and user in m.standard):
map[0] = user # Config file key
map[1] = m.standard[user][0] # Friendly map name
map[2] = m.standard[user][1] # Map mode
map[3] = m.standard[user][2] # Image key
print(str(map))
elif mode[2] == "any" and user in m.arcade:
map[0] = user # Config file key
map[1] = m.arcade[user][0] # Friendly map name
map[2] = m.arcade[user][1] # Map mode
map[3] = m.arcade[user][2] # Image key
print(str(map))
else:
print(c.fail + "Something unexpected went wrong! Please report this at git.io/owrpc or discord.gg/keErGbZ and say you hit point 2.")
print(c.info + "If you try and do whatever you were trying to do again, it should work. Hopefully. Sorry about that.")
if mode[0] == "competitive":
print(c.info + "What is your skill rating (SR)?")
user = input(c.ask)
sr = [0,""]
while sr == [0,""]:
try:
if user == "<500":
sr = [user,"bronze"]
else:
user = int(user)
if user < 1 or user > 5000:
raise ValueError
elif user < 1500:
if user < 500:
sr = ["<500","bronze"]
else:
sr = [user,"bronze"]
elif user < 2000:
sr = [user,"silver"]
elif user < 2500:
sr = [user,"gold"]
elif user < 3000:
sr = [user,"platinum"]
elif user < 3500:
sr = [user,"diamond"]
elif user < 4000:
sr = [user,"masters"]
else:
sr = [user,"grandmaster"]
except Exception as e:
print(c.fail + "The SR you entered is invalid, so I'm going to set your SR to Bronze. You probably belong there anyway.")
sr = [-1,"bronze"]
print(str(e))
setPresence(None,details=mode[1] + ': In Game',state=map[2] + ' on ' + map[1],large_image=map[3],large_text=map[1],small_image=sr[1],small_text=str(sr[0]) + ' SR')
else:
if mode[2] == "standard" :
roles = buildList(m.roles)
print(c.info + "What is your role?")
print(c.info + "Your options are: " + roles)
user = input(c.ask)
role = ["",""]
while role == ["",""] :
if user == "tank" or "heal" or "dps" :
role[0] = m.roles[user][0] # Role name
role[1] = m.roles[user][1] # Image key
else:
print(c.fail + "Something unexpected went wrong! Please report this at git.io/owrpc or discord.gg/keErGbZ and say you hit point 3.")
print(c.info + "If you try and do whatever you were trying to do again, it should work. Hopefully. Sorry about that.")
setPresence(None,details=mode[1] + ': In Game',state=map[2] + ' on ' + map[1],large_image=map[3],large_text=map[1],small_image=role[1],small_text='Playing as ' + role[0])
else:
setPresence(None,details=mode[1] + ': In Game',state=map[2] + ' on ' + map[1],large_image=map[3],large_text=map[1],small_image=None,small_text=None)
def setPresence(preset,details='',state='',large_image='',large_text='',small_image='',small_text=''):
"""
This function sets the Discord Rich Presence.
[details,state,large_image,large_text,small_image,small_text]
"""
silent = 0
if preset != None:
if preset.endswith("_silent"):
preset = preset[:-7]
silent = 1
details = status.presets.get(preset)[0]
state = status.presets.get(preset)[1]
large_image = status.presets.get(preset)[2]
large_text = status.presets.get(preset)[3]
small_image = status.presets.get(preset)[4]
small_text = status.presets.get(preset)[5]
if status.devmode == True:
details = "DEV MODE | " + str(details)
try:
# Update the presence using the details provided when calling the function
dp.update(details=details,state=state,large_image=large_image,large_text=large_text,small_image=small_image,small_text=small_text,start=int(time.time()))
except Exception as e:
# If there is an exception, inform the user then exit with error code 1
print(c.fail + "Couldn't set your presence properly! :(")
print(c.fail + "The error message from pypresence is: " + str(e))
sys.exit(1)
if silent == 0:
print(c.success + "Your presence has been updated! Discord may take a few seconds to update.")
else:
pass
def setupCustom():
print(c.warn + "Here be dragons!")
print(c.warn + "This is a more advanced version of the presence selector. The normal one (accessed through !game) should be easier for you.")
print(c.warn + "To ignore a line, just hit Enter immediately and leave it blank.")
print(c.blank)
options = {
"details":'',
"state":'',
"large_image":'',
"large_text":'',
"small_image":'',
"small_text":''
}
print(c.info + '' + "Please enter your top line.")
options["details"] = input(c.ask)
print(c.info + '' + "Please enter your bottom line.")
options["state"] = input(c.ask)
print(c.info + "Please enter your large image key.")
options["large_image"] = '' + input(c.ask)
print(c.info + "Please enter your large image text.")
options["large_text"] = '' + input(c.ask)
print(c.info + "Please enter your small image key.")
options["small_image"] = '' + input(c.ask)
print(c.info + "Please enter your small image text.")
options["small_text"] = '' + input(c.ask)
for option in options:
if options[option] == '':
options[option] = None
if options["large_image"] == None:
options["large_image"] = "overwatch"
setPresence(None,details=options["details"],state=options["state"],large_image=options["large_image"],large_text=options["large_text"],small_image=options["small_image"],small_text=options["small_text"])
owquotes = ["Cheers, love! The cavalry's here!","¡Apagando las luces!","Look out world, Tracer's here!","Nerf this!","Fire in the hole!","Die, die, die!","Justice rains from above!","I will be your shield!","All systems buzzing!","What is that melody?","Your guardian angel.","Do you even lift?","Gotcha something!","This... is my will."]
showGreeting()
setPresence("inmenus_silent")
while True:
if status.devmode == True:
print(c.warn + "Development mode is enabled. Remember to disable it when you're done!")
command = input(c.cmd)
if command.startswith("!dev"):
devMode()
elif command.startswith("!help"):
showGreeting()
print(c.warn + "MAINTENANCE COMMANDS")
print(c.info + "!dev - Toggle development mode on or off.")
print(c.info + "!help - View this help document.")
print(c.info + "!quit - Close the program.")
print(c.blank)
print(c.warn + "PRESENCE COMMANDS")
print(c.info + "!game - Start set up for a game.")
print(c.info + "!custom - Set up a custom presence.")
print(c.info + "!menus - Set your presence to In Menus.")
print(c.info + "!queue [a/c/q] - Set your presence to In Queue for [a]rcade, [c]ompetitive or [q]uickplay.")
print(c.info + "!clear - Remove your presence from Discord.")
elif command.startswith("!quit"):
sys.exit(0)
elif command.startswith("!game"):
setupGame()
elif command.startswith("!custom"):
setupCustom()
elif command.startswith("!menus"):
setPresence("inmenus")
elif command.startswith("!queue"):
params = command.split()
try:
params[1]
except:
setPresence("inqueue")
continue
if params[1].lower().startswith("c"):
setPresence("inqueue-comp")
elif params[1].lower().startswith("q"):
setPresence("inqueue-quick")
elif params[1].lower().startswith("a"):
setPresence("inqueue-arcade")
else:
setPresence("inqueue")
elif command.startswith("!clear"):
clearPresence()
else:
print(c.fail + "Couldn't find that command! Do !help if you need a refresher, or check out the documentation at git.io/owrpc. Need help? Ask at discord.gg/keErGbZ.")
pass
except KeyboardInterrupt:
print()
print(c.fail + "Got your CTRL+C! Exiting...")
sys.exit(0)