Skip to content

Commit

Permalink
added an option to disable discord rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
OwOHamper committed Aug 25, 2022
1 parent 390acfa commit 722e431
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
18 changes: 13 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 2 additions & 1 deletion src/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 0 additions & 1 deletion src/rpc.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 5 additions & 3 deletions src/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 722e431

Please sign in to comment.