-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
600 lines (493 loc) · 27.4 KB
/
main.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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
import traceback
import requests
import urllib3
import os
import sys
import time
import asyncio
from InquirerPy import inquirer
from src.constants import *
from src.requestsV import Requests
from src.logs import Logging
from src.config import Config
from src.colors import Colors
from src.rank import Rank
from src.content import Content
from src.names import Names
from src.presences import Presences
from src.Loadouts import Loadouts
from src.websocket import Ws
from src.states.menu import Menu
from src.states.pregame import Pregame
from src.states.coregame import Coregame
from src.table import Table
from src.server import Server
from src.errors import Error
from src.stats import Stats
from src.configurator import configure
from src.player_stats import PlayerStats
from src.chatlogs import ChatLogging
from src.rpc import Rpc
from src.os import get_os
from colr import color as colr
from rich.console import Console as RichConsole
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
os.system(f"title VALINFO API STATUS v{version}")
server = ""
def program_exit(status: int):
log(f"exited program with error code {status}")
raise sys.exit(status)
try:
Logging = Logging()
log = Logging.log
if get_os()[1] == False:
print(f"Unsupported operating system: {get_os()[0]}\n")
log(f"Unsupported operating system: {get_os()[0]}\n")
program_exit(0)
else:
log(f"Operating system: {get_os()[0]}\n")
ChatLogging = ChatLogging()
chatlog = ChatLogging.chatLog
try:
if len(sys.argv) > 1 and sys.argv[1] == "--config":
configure()
run_app = inquirer.confirm(
message="Do you want to run valinfo?", default=True
).execute()
if run_app:
os.system('mode 150,35')
os.system('cls')
else:
os._exit(0)
else:
os.system('mode 150,35')
os.system('cls')
except Exception as e:
print("Something went wrong while running configurator!")
log(f"configurator encountered an error")
log(str(traceback.format_exc()))
input("press enter to exit...\n")
os._exit(1)
ErrorSRC = Error(log)
Requests = Requests(version, log, ErrorSRC)
Requests.check_version()
Requests.check_status()
cfg = Config(log)
content = Content(Requests, log)
rank = Rank(Requests, log, content, before_ascendant_seasons)
pstats = PlayerStats(Requests, log, cfg)
namesClass = Names(Requests, log)
presences = Presences(Requests, log)
menu = Menu(Requests, log, presences)
pregame = Pregame(Requests, log)
coregame = Coregame(Requests, log)
Server = Server(log, ErrorSRC)
Server.start_server()
agent_dict = content.get_all_agents()
map_dict = content.get_maps()
colors = Colors(hide_names, agent_dict, AGENTCOLORLIST)
loadoutsClass = Loadouts(Requests, log, colors, Server)
table = Table(cfg, chatlog, log)
stats = Stats()
if cfg.get_feature_flag("discord_rpc"):
rpc = Rpc(map_dict, gamemodes, colors, log)
else:
rpc = None
Wss = Ws(Requests.lockfile, Requests, cfg, colors, hide_names, chatlog, rpc)
log(f"VALINFO API STATUS v{version}")
valoApiSkins = requests.get("https://valorant-api.com/v1/weapons/skins")
gameContent = content.get_content()
seasonID = content.get_latest_season_id(gameContent)
lastGameState = ""
print(color("""
██ ██ █████ ██ ██ ███ ██ ███████ ██████
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
██ ██ ███████ ██ ██ ██ ██ ██ █████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████ ██ ██ ███████ ██ ██ ████ ██ ██████
""", fore=(182, 44, 54)))
print(color("\nThis tool usings the API of Valorant \nNot ban able as it just uses the local client api\n", fore=(255, 253, 205)))
chatlog(color("\nWelcome to my world \nDont forget to follow me on instagram @eii3\n", fore=(255, 253, 205)))
richConsole = RichConsole()
firstTime = True
firstPrint = True
while True:
table.clear()
table.set_default_field_names()
table.reset_runtime_col_flags()
try:
if firstTime:
run = True
while run:
while True:
presence = presences.get_presence()
if presences.get_private_presence(presence) != None:
break
time.sleep(5)
if cfg.get_feature_flag("discord_rpc"):
rpc.set_rpc(presences.get_private_presence(presence))
game_state = presences.get_game_state(presence)
if game_state != None:
run = False
time.sleep(2)
log(f"game state: {game_state}")
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
game_state = loop.run_until_complete(Wss.recconect_to_websocket(game_state))
log(f"new game state: {game_state}")
loop.close()
firstTime = False
except TypeError:
raise Exception("Game has not started yet!")
if True:
log(f"getting new {game_state} scoreboard")
lastGameState = game_state
game_state_dict = {
"INGAME": color('In-Game', fore=(241, 39, 39)),
"PREGAME": color('Agent Select', fore=(103, 237, 76)),
"MENUS": color('In-Menus', fore=(238, 241, 54)),
}
if (not firstPrint) and cfg.get_feature_flag("pre_cls"):
os.system('cls')
is_leaderboard_needed = False
if game_state == "INGAME":
coregame_stats = coregame.get_coregame_stats()
if coregame_stats == None:
continue
Players = coregame_stats["Players"]
presence = presences.get_presence()
partyMembers = menu.get_party_members(Requests.puuid, presence)
partyMembersList = [a["Subject"] for a in partyMembers]
players_data = {}
players_data.update({"ignore": partyMembersList})
for player in Players:
if player["Subject"] == Requests.puuid:
if cfg.get_feature_flag("discord_rpc"):
rpc.set_data({"agent": player["CharacterID"]})
players_data.update({player["Subject"]: {"team": player["TeamID"], "agent": player["CharacterID"], "streamer_mode": player["PlayerIdentity"]["Incognito"]}})
Wss.set_player_data(players_data)
try:
server = GAMEPODS[coregame_stats["GamePodID"]]
except KeyError:
server = "New server"
presences.wait_for_presence(namesClass.get_players_puuid(Players))
names = namesClass.get_names_from_puuids(Players)
loadouts = loadoutsClass.get_match_loadouts(coregame.get_coregame_match_id(), Players, cfg.weapon, valoApiSkins, names, state="game")
isRange = False
playersLoaded = 1
with richConsole.status("Loading Players...") as status:
partyOBJ = menu.get_party_json(namesClass.get_players_puuid(Players), presence)
Players.sort(key=lambda Players: Players["PlayerIdentity"].get("AccountLevel"), reverse=True)
Players.sort(key=lambda Players: Players["TeamID"], reverse=True)
partyCount = 0
partyIcons = {}
lastTeamBoolean = False
lastTeam = "Red"
already_played_with = []
stats_data = stats.read_data()
for p in Players:
if p["Subject"] == Requests.puuid:
allyTeam = p["TeamID"]
for player in Players:
status.update(f"Loading status of players... [{playersLoaded}/{len(Players)}]")
playersLoaded += 1
if player["Subject"] in stats_data.keys():
if player["Subject"] != Requests.puuid and player["Subject"] not in partyMembersList:
curr_player_stat = stats_data[player["Subject"]][-1]
i = 1
while curr_player_stat["match_id"] == coregame.match_id and len(stats_data[player["Subject"]]) > i:
i+=1
curr_player_stat = stats_data[player["Subject"]][-i]
if curr_player_stat["match_id"] != coregame.match_id:
times = 0
m_set = ()
for m in stats_data[player["Subject"]]:
if m["match_id"] != coregame.match_id and m["match_id"] not in m_set:
times += 1
m_set += (m["match_id"],)
if player["PlayerIdentity"]["Incognito"] == False:
already_played_with.append(
{
"times": times,
"name": curr_player_stat["name"],
"agent": curr_player_stat["agent"],
"time_diff": time.time() - curr_player_stat["epoch"]
})
else:
if player["TeamID"] == allyTeam:
team_string = "your"
else:
team_string = "enemy"
already_played_with.append(
{
"times": times,
"name": agent_dict[player["CharacterID"].lower()] + " on " + team_string + " team",
"agent": curr_player_stat["agent"],
"time_diff": time.time() - curr_player_stat["epoch"]
})
party_icon = ''
for party in partyOBJ:
if player["Subject"] in partyOBJ[party]:
if party not in partyIcons:
partyIcons.update({party: PARTYICONLIST[partyCount]})
party_icon = PARTYICONLIST[partyCount]
partyCount += 1
else:
party_icon = partyIcons[party]
playerRank = rank.get_rank(player["Subject"], seasonID)
if player["Subject"] == Requests.puuid:
if cfg.get_feature_flag("discord_rpc"):
rpc.set_data({"rank": playerRank["rank"], "rank_name": colors.escape_ansi(NUMBERTORANKS[playerRank["rank"]]) + " | " + str(playerRank["rr"]) + "rr"})
ppstats = pstats.get_stats(player["Subject"])
hs = ppstats["hs"]
kd = ppstats["kd"]
player_level = player["PlayerIdentity"].get("AccountLevel")
if player["PlayerIdentity"]["Incognito"]:
Namecolor = colors.get_color_from_team(player["TeamID"],
names[player["Subject"]],
player["Subject"], Requests.puuid, agent=player["CharacterID"], party_members=partyMembersList)
else:
Namecolor = colors.get_color_from_team(player["TeamID"],
names[player["Subject"]],
player["Subject"], Requests.puuid, party_members=partyMembersList)
if lastTeam != player["TeamID"]:
if lastTeamBoolean:
table.add_empty_row()
lastTeam = player['TeamID']
lastTeamBoolean = True
if player["PlayerIdentity"]["HideAccountLevel"]:
if player["Subject"] == Requests.puuid or player["Subject"] in partyMembersList or hide_levels == False:
PLcolor = colors.level_to_color(player_level)
else:
PLcolor = ""
else:
PLcolor = colors.level_to_color(player_level)
agent = colors.get_agent_from_uuid(player["CharacterID"].lower())
if agent == "" and len(Players) == 1:
isRange = True
name = Namecolor
skin = loadouts[player["Subject"]]
rankName = NUMBERTORANKS[playerRank["rank"]]
rr = playerRank["rr"]
peakRankAct = f" (e{playerRank['peakrankep']}a{playerRank['peakrankact']})"
if not cfg.get_feature_flag("peak_rank_act"):
peakRankAct = ""
peakRank = NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
leaderboard = playerRank["leaderboard"]
hs = colors.get_hs_gradient(hs)
wr = colors.get_wr_gradient(playerRank["wr"]) + f" ({playerRank['numberofgames']})"
if(int(leaderboard)>0):
is_leaderboard_needed = True
level = PLcolor
table.add_row_table([party_icon,
agent,
name,
skin,
rankName,
rr,
peakRank,
leaderboard,
hs,
wr,
kd,
level
])
stats.save_data(
{
player["Subject"]: {
"name": names[player["Subject"]],
"agent": agent_dict[player["CharacterID"].lower()],
"map": map_dict.get(coregame_stats["MapID"].lower()),
"rank": playerRank["rank"],
"rr": rr,
"match_id": coregame.match_id,
"epoch": time.time(),
}
}
)
elif game_state == "PREGAME":
already_played_with = []
pregame_stats = pregame.get_pregame_stats()
if pregame_stats == None:
continue
try:
server = GAMEPODS[pregame_stats["GamePodID"]]
except KeyError:
server = "New server"
Players = pregame_stats["AllyTeam"]["Players"]
presences.wait_for_presence(namesClass.get_players_puuid(Players))
names = namesClass.get_names_from_puuids(Players)
playersLoaded = 1
with richConsole.status("Loading Players...") as status:
presence = presences.get_presence()
partyOBJ = menu.get_party_json(namesClass.get_players_puuid(Players), presence)
partyMembers = menu.get_party_members(Requests.puuid, presence)
partyMembersList = [a["Subject"] for a in partyMembers]
Players.sort(key=lambda Players: Players["PlayerIdentity"].get("AccountLevel"), reverse=True)
partyCount = 0
partyIcons = {}
for player in Players:
status.update(f"Loading status of players... [{playersLoaded}/{len(Players)}]")
playersLoaded += 1
party_icon = ''
for party in partyOBJ:
if player["Subject"] in partyOBJ[party]:
if party not in partyIcons:
partyIcons.update({party: PARTYICONLIST[partyCount]})
party_icon = PARTYICONLIST[partyCount]
else:
party_icon = partyIcons[party]
partyCount += 1
playerRank = rank.get_rank(player["Subject"], seasonID)
if player["Subject"] == Requests.puuid:
if cfg.get_feature_flag("discord_rpc"):
rpc.set_data({"rank": playerRank["rank"], "rank_name": colors.escape_ansi(NUMBERTORANKS[playerRank["rank"]]) + " | " + str(playerRank["rr"]) + "rr"})
ppstats = pstats.get_stats(player["Subject"])
hs = ppstats["hs"]
kd = ppstats["kd"]
player_level = player["PlayerIdentity"].get("AccountLevel")
if player["PlayerIdentity"]["Incognito"]:
NameColor = colors.get_color_from_team(pregame_stats['Teams'][0]['TeamID'],
names[player["Subject"]],
player["Subject"], Requests.puuid, agent=player["CharacterID"], party_members=partyMembersList)
else:
NameColor = colors.get_color_from_team(pregame_stats['Teams'][0]['TeamID'],
names[player["Subject"]],
player["Subject"], Requests.puuid, party_members=partyMembersList)
if player["PlayerIdentity"]["HideAccountLevel"]:
if player["Subject"] == Requests.puuid or player["Subject"] in partyMembersList or hide_levels == False:
PLcolor = colors.level_to_color(player_level)
else:
PLcolor = ""
else:
PLcolor = colors.level_to_color(player_level)
if player["CharacterSelectionState"] == "locked":
agent_color = color(str(agent_dict.get(player["CharacterID"].lower())),
fore=(255, 255, 255))
elif player["CharacterSelectionState"] == "selected":
agent_color = color(str(agent_dict.get(player["CharacterID"].lower())),
fore=(128, 128, 128))
else:
agent_color = color(str(agent_dict.get(player["CharacterID"].lower())), fore=(54, 53, 51))
agent = agent_color
name = NameColor
rankName = NUMBERTORANKS[playerRank["rank"]]
rr = playerRank["rr"]
peakRankAct = f" (e{playerRank['peakrankep']}a{playerRank['peakrankact']})"
if not cfg.get_feature_flag("peak_rank_act"):
peakRankAct = ""
peakRank = NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
leaderboard = playerRank["leaderboard"]
hs = colors.get_hs_gradient(hs)
wr = colors.get_wr_gradient(playerRank["wr"]) + f" ({playerRank['numberofgames']})"
if(int(leaderboard)>0):
is_leaderboard_needed = True
level = PLcolor
table.add_row_table([party_icon,
agent,
name,
"",
rankName,
rr,
peakRank,
leaderboard,
hs,
wr,
kd,
level,
])
if game_state == "MENUS":
already_played_with = []
Players = menu.get_party_members(Requests.puuid, presence)
names = namesClass.get_names_from_puuids(Players)
playersLoaded = 1
with richConsole.status("Loading Players...") as status:
Players.sort(key=lambda Players: Players["PlayerIdentity"].get("AccountLevel"), reverse=True)
seen = []
for player in Players:
if player not in seen:
status.update(f"Loading status of players... [{playersLoaded}/{len(Players)}]")
playersLoaded += 1
party_icon = PARTYICONLIST[0]
playerRank = rank.get_rank(player["Subject"], seasonID)
if player["Subject"] == Requests.puuid:
if cfg.get_feature_flag("discord_rpc"):
rpc.set_data({"rank": playerRank["rank"], "rank_name": colors.escape_ansi(NUMBERTORANKS[playerRank["rank"]]) + " | " + str(playerRank["rr"]) + "rr"})
ppstats = pstats.get_stats(player["Subject"])
hs = ppstats["hs"]
kd = ppstats["kd"]
player_level = player["PlayerIdentity"].get("AccountLevel")
PLcolor = colors.level_to_color(player_level)
agent = ""
name = color(names[player["Subject"]], fore=(76, 151, 237))
rankName = NUMBERTORANKS[playerRank["rank"]]
rr = playerRank["rr"]
peakRankAct = f" (e{playerRank['peakrankep']}a{playerRank['peakrankact']})"
if not cfg.get_feature_flag("peak_rank_act"):
peakRankAct = ""
peakRank = NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
leaderboard = playerRank["leaderboard"]
hs = colors.get_hs_gradient(hs)
wr = colors.get_wr_gradient(playerRank["wr"]) + f" ({playerRank['numberofgames']})"
if(int(leaderboard)>0):
is_leaderboard_needed = True
level = PLcolor
table.add_row_table([party_icon,
agent,
name,
"",
rankName,
rr,
peakRank,
leaderboard,
hs,
wr,
kd,
level
])
seen.append(player["Subject"])
if (title := game_state_dict.get(game_state)) is None:
time.sleep(9)
if server != "":
table.set_title(f"VALORANT status: {title} {colr('- ' + server, fore=(200, 200, 200))}")
else:
table.set_title(f"VALORANT status: {title}")
server = ""
if title is not None:
if cfg.get_feature_flag("auto_hide_leaderboard") and (not is_leaderboard_needed):
table.set_runtime_col_flag('Pos.', False)
if game_state == "MENUS":
table.set_runtime_col_flag('Party', False)
table.set_runtime_col_flag('Agent',False)
table.set_runtime_col_flag('Skin',False)
if game_state == "INGAME":
if isRange:
table.set_runtime_col_flag('Party', False)
table.set_runtime_col_flag('Agent',False)
table.set_caption(f"VALINFO API STATUS v{version}")
table.display()
firstPrint = False
if cfg.get_feature_flag("last_played"):
if len(already_played_with) > 0:
print("\n")
for played in already_played_with:
print(f"Already played with {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)")
chatlog(f"Already played with {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)")
already_played_with = []
if cfg.cooldown == 0:
input("Press enter to fetch again...")
else:
pass
except KeyboardInterrupt:
os._exit(0)
except:
log(traceback.format_exc())
print(color(
"Make sure valorant it work, The program has encountered an error."
f" with the logs found in {os.getcwd()}\logs", fore=(255, 0, 0)))
chatlog(color(
"Make sure valorant it work, The program has encountered an error."
f" with the logs found in {os.getcwd()}\logs", fore=(255, 0, 0)))
input("press enter to exit...\n")
os._exit(1)