diff --git a/main.py b/main.py index 2e4b95a7..b2da2ad0 100644 --- a/main.py +++ b/main.py @@ -111,7 +111,10 @@ def program_exit(status: int): # so we don't need to import the entire sys modu stats = Stats() - rpc = Rpc(map_dict, gamemodes, colors) + if cfg.get_feature_flag("discord_rpc"): + rpc = Rpc(map_dict, gamemodes, colors) + else: + rpc = None Wss = Ws(Requests.lockfile, Requests, cfg, colors, hide_names, chatlog, rpc) # loop = asyncio.new_event_loop() @@ -161,7 +164,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu if presences.get_private_presence(presence) != None: break time.sleep(2) - rpc.set_rpc(presences.get_private_presence(presence)) + 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 @@ -206,7 +210,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu players_data.update({"ignore": partyMembersList}) for player in Players: if player["Subject"] == Requests.puuid: - rpc.set_data({"agent": player["CharacterID"]}) + 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) @@ -429,7 +434,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu playerRank = rank.get_rank(player["Subject"], seasonID) if player["Subject"] == Requests.puuid: - rpc.set_data({"rank": playerRank["rank"], "rank_name": colors.escape_ansi(NUMBERTORANKS[playerRank["rank"]]) + " | " + str(playerRank["rr"]) + "rr"}) + 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"}) # rankStatus = playerRank[1] #useless code since rate limit is handled in the requestsV # while not rankStatus: @@ -537,7 +543,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu playerRank = rank.get_rank(player["Subject"], seasonID) if player["Subject"] == Requests.puuid: - rpc.set_data({"rank": playerRank["rank"], "rank_name": colors.escape_ansi(NUMBERTORANKS[playerRank["rank"]]) + " | " + str(playerRank["rr"]) + "rr"}) + 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"}) # rankStatus = playerRank[1] #useless code since rate limit is handled in the requestsV @@ -619,6 +626,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu table.set_runtime_col_flag('Agent',False) table.set_runtime_col_flag('Skin',False) + print("\n") table.display() firstPrint = False diff --git a/src/constants.py b/src/constants.py index 7cdbf737..38c95cd1 100644 --- a/src/constants.py +++ b/src/constants.py @@ -167,6 +167,7 @@ "auto_hide_leaderboard": True, "pre_cls": False, "game_chat": False, - "peak_rank_act": True + "peak_rank_act": True, + "discord_rpc": True } } diff --git a/src/questions.py b/src/questions.py index 1c11b449..b9de11e2 100644 --- a/src/questions.py +++ b/src/questions.py @@ -16,7 +16,8 @@ "auto_hide_leaderboard": "Auto Hide Leaderboard Column", "pre_cls": "Pre-Clear Screen", "game_chat": "Print Game Chat", - "peak_rank_act": "Peak Rank Act" + "peak_rank_act": "Peak Rank Act", + "discord_rpc": "Discord Rich Presence" } weapon_question = lambda config: { diff --git a/src/rpc.py b/src/rpc.py index 530623bb..f9d1398c 100644 --- a/src/rpc.py +++ b/src/rpc.py @@ -1,7 +1,6 @@ from pypresence import Presence from pypresence.exceptions import DiscordNotFound, InvalidID import nest_asyncio -import time class Rpc(): def __init__(self, map_dict, gamemodes, colors): diff --git a/src/websocket.py b/src/websocket.py index 4b0f21ad..fbbeea10 100644 --- a/src/websocket.py +++ b/src/websocket.py @@ -8,7 +8,7 @@ class Ws: - def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, rpc): + def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, rpc=None): self.lockfile = lockfile self.Requests = Requests @@ -26,7 +26,8 @@ def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, rpc): self.up = "\033[A" self.chat_limit = 5 self.chatlog = chatlog - self.rpc = rpc + if self.cfg.get_feature_flag("discord_rpc"): + self.rpc = rpc def set_player_data(self, player_data): self.player_data = player_data @@ -77,7 +78,8 @@ def handle(self, m, initial_game_state): state = json.loads(base64.b64decode(presence['private']))["sessionLoopState"] if state is not None: - self.rpc.set_rpc(json.loads(base64.b64decode(presence['private']))) + if self.cfg.get_feature_flag("discord_rpc"): + self.rpc.set_rpc(json.loads(base64.b64decode(presence['private']))) if state != initial_game_state: self.messages = 0 self.message_history = []