'Halo MCC Discord Rich Prescence application spits out multiple errors
I have been using this Halo MCC Discord Rich Prescence application: https://github.com/Gurrman375/HaloMCC-DiscordRPC for awhile and for about a year now it's been spitting out a series of errors:
Traceback (most recent call last):
File "ui.py", line 97, in <module>
File "ui.py", line 8, in main
File "ui.py", line 28, in option
File "richpresence.py", line 191, in richpresence
KeyError: 'Heroic'
[23328] Failed to execute script ui
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001D0CCCEA9D8>
Traceback (most recent call last):
File "asyncio\proactor_events.py", line 93, in __del__
File "asyncio\proactor_events.py", line 57, in __repr__
File "asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001D0CCCEA9D8>
Traceback (most recent call last):
File "asyncio\proactor_events.py", line 93, in __del__
File "asyncio\proactor_events.py", line 57, in __repr__
File "asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe
I have tried downloading the code from their GitHub and debugging it myself, but I honestly can't figure out what the issue is, I put in an issue request on GitHub over a year ago and the creators seem to have just abandoned the project. I'd like to fix this issue myself but I have very limited coding knowledge.
here is the code I have been tinkering with since these are the two files it referrs to in the error message:
ui.py:
import json, ctypes, auth, shutil, richpresence
from time import sleep
from os import system, name, sys, path
from additional import application_path, clear
def main():
splashScreen()
option(UI())
def optionUI():
while True:
option(UI())
def option(selection):
"""Selction based on the number you chose. Look at list to modify.
Args:
selection (int): Runs lines of code based on a conditional
Returns:
[void]: Doesn't return anything. Just here in case errors.
"""
if(selection == 1):
clear()
auth.main()
optionUI()
elif(selection == 2):
print("Run the command 'Ctrl C' to exit the program.")
print("Loading Code ...")
sleep(2)
clear()
richpresence.richpresence()
elif(selection == 3):
if(path.isdir(application_path() + "\\tokens") == True):
shutil.rmtree(application_path() + "\\tokens")
with open(richpresence.application_path() + "\\rpc.json", 'w') as j:
rpc = {
"details": "",
"state": "",
"device": "",
"game": ""
}
json.dump(rpc, j, indent=2)
sleep(2)
clear()
optionUI()
elif(selection == 4):
sys.exit()
else:
print("WIP")
sleep(2)
clear()
optionUI()
def UI():
"""Main graphics ui. Currently it is a terminal UI.
Returns:
[void]: Doesn't return anything. Here in case errors.
"""
system('color 2')
print("------------------------------------------------------------------------------------------------------------------------")
print("Halo: MCC Rich Presence")
print("------------------------------------------------------------------------------------------------------------------------")
print("List: ")
print('1. Sign in using Oauth 2.0 (Requires you to save a link that looks like "https://localhost/oauth_success?code=M.R3_BAY.<code>")')
print("2. Launch the Rich Presence (Requires /tokens folder)")
print("3. Delete your Credentials")
print("4. Exit")
print("------------------------------------------------------------------------------------------------------------------------")
print("Current Build: 0.3.3")
print("------------------------------------------------------------------------------------------------------------------------")
selection = int(input("Select from list: "))
return selection
def splashScreen():
"""Creates a Screen to show the devs and other program info.
"""
clear()
print("------------------------------------------------------------------------------------------------------------------------")
print("Halo: MCC Rich Presence")
print("------------------------------------------------------------------------------------------------------------------------")
print("Created by kay-el-zed, Gurrman375D.")
print("Maintained by Gurrman375D.")
print("------------------------------------------------------------------------------------------------------------------------")
print("Current Build: 0.3.3")
print("------------------------------------------------------------------------------------------------------------------------")
sleep(5)
clear()
if __name__ == "__main__":
system('color 2')
try:
ctypes.windll.kernel32.SetConsoleTitleW("Halo Master Chief Collection Rich Presence")
main()
except KeyboardInterrupt as e:
print(e)
sleep(1)
clear()
print("Manually Close the App")
optionUI()
richprescence.py:
import json, auth, dictionary, math, requests
from os import curdir, path, system
from time import time, sleep
from pypresence import Presence
from additional import application_path, clear
def request(application_path):
"""Generates a request in a terminal to receive the presence data
Args:
application_path (str): The path of where the .exe or script is located.
"""
system(application_path + "\\node-v14.17.0-win-x64\\node.exe " + application_path + "\\richpresence.js")
return
def richpresence():
"""The main code need for the presence app to run
"""
if(path.exists(application_path() + '\\rpc.json') != True):
writejsonfile()
client_id = {
"main": "700853075023233024",
"Halo R": "725163293240590386",
"Halo CE": "725898626290942053",
"Halo 2": "730097982523047936",
"Halo 3": "748408159479005294",
"Halo 4": "748413810548801587"
}
changedRPC = {
"Else": "700853075023233024",
"Halo R": False,
"Halo CE": False,
"Halo 2": False,
"Halo 3": False,
"Halo 4": False
}
currentRPC = startRPC(client_id['main'])
currentRPC.connect()
browsingStamp = timestamp()
# Creating steam invite link
presence = readPresence()
if(presence['steamid'] != ""):
headers = {'Content-type': 'application/x-www-form-urlencoded'}
try:
print("Getting steam url code:")
r = requests.get("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=80EC429274AF252714363656B71562C0&format=json&steamids=" + presence['steamid'], headers=headers)
response = json.loads(r.text)
lobbysteamid = response['response']['players'][0]['lobbysteamid']
gameid = response['response']['players'][0]['gameid']
steam_invite_url = "steam://joinlobby/" + gameid + "/" + lobbysteamid + "/" + presence['steamid']
pass
except Exception as e:
print("Unable to get steam id. Check to make sure Halo is running.")
sleep(5)
steam_invite_url = None
pass
else:
print("Steam url is None.")
steam_invite_url = None
pass
while True:
auth.main()
try:
request(application_path())
presence = readPresence()
if(presence != False and presence['game'] != ""):
if(presence['device'] == "Win32" or presence['device'] == "WindowsOneCore"):
if(presence['device'] == "Win32"):
deviceTitle = "Steam"
device = "steam"
elif(presence['device'] == "WindowsOneCore"):
deviceTitle = "Windows Store/Gamepass"
device = "small"
else:
deviceTitle = "Windows"
device = "small"
else:
device = "xbox"
deviceTitle = "Xbox"
## Halo 3
if(presence['state'].find("H3:") != -1):
if(changedRPC['Halo 3'] == False):
if((changedRPC['Else'] or changedRPC['Halo CE'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 2'] = False
changedRPC['Halo R'] = False
changedRPC['Halo 4'] = False
currentRPC = startRPC(client_id['Halo 3'])
currentRPC.connect()
changedRPC['Else'] = False
changedRPC['Halo 3'] = client_id['Halo 3']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(3)[presence['details']], presence['details'], dictionary.jsonDictionary(3)['Halo3'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(3)[presence['details']], presence['details'], dictionary.jsonDictionary(3)['Halo3'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(3)[presence['details']], presence['details'], dictionary.jsonDictionary(3)['Halo3'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(3)[presence['details']], presence['details'], dictionary.jsonDictionary(3)['Halo3'], presence['state'], presence['state'], presence['details'], browsingStamp)
elif(presence['state'].find("H4:") != -1):
if(changedRPC['Halo 4'] == False):
if((changedRPC['Else'] or changedRPC['Halo CE'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 2'] = False
changedRPC['Halo R'] = False
changedRPC['Halo 3'] = False
currentRPC = startRPC(client_id['Halo 4'])
currentRPC.connect()
changedRPC['Else'] = False
changedRPC['Halo 4'] = client_id['Halo 4']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(4)[presence['details']], presence['details'], dictionary.jsonDictionary(4)['Halo4'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(4)[presence['details']], presence['details'], dictionary.jsonDictionary(4)['Halo4'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(4)[presence['details']], presence['details'], dictionary.jsonDictionary(4)['Halo4'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(4)[presence['details']], presence['details'], dictionary.jsonDictionary(4)['Halo4'], presence['state'], presence['state'], presence['details'], browsingStamp)
elif(presence['state'].find("H: CE:") != -1):
if(changedRPC['Halo CE'] == False):
if((changedRPC['Else'] or changedRPC['Halo 4'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo 4'] = False
changedRPC['Halo 2'] = False
changedRPC['Halo 3'] = False
changedRPC['Halo R'] = False
changedRPC['Else'] = False
currentRPC = startRPC(client_id['Halo CE'])
currentRPC.connect()
changedRPC['Halo CE'] = client_id['Halo CE']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(1)[presence['details']], presence['details'], dictionary.jsonDictionary(1)['HaloCE'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(1)[presence['details']], presence['details'], dictionary.jsonDictionary(1)['HaloCE'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(1)[presence['details']], presence['details'], dictionary.jsonDictionary(1)['HaloCE'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(1)[presence['details']], presence['details'], dictionary.jsonDictionary(1)['HaloCE'], presence['state'], presence['state'], presence['details'], browsingStamp)
elif(presence['state'].find("H2A: ") != -1):
if(changedRPC['Halo 2'] == False):
if((changedRPC['Else'] or changedRPC['Halo 4'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 4'] = False
changedRPC['Halo 3'] = False
changedRPC['Halo R'] = False
changedRPC['Else'] = False
currentRPC = startRPC(client_id['Halo 2'])
currentRPC.connect()
changedRPC['Halo 2'] = client_id['Halo 2']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Aniversary'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Aniversary']['Halo2A'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Aniversary'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Aniversary']['Halo2A'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Aniversary'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Aniversary']['Halo2A'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Aniversary'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Aniversary']['Halo2A'], presence['state'], presence['state'], presence['details'], browsingStamp)
elif(presence['state'].find("H2: ") != -1):
if(changedRPC['Halo 2'] == False):
if((changedRPC['Else'] or changedRPC['Halo 4'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 4'] = False
changedRPC['Halo R'] = False
changedRPC['Halo 3'] = False
changedRPC['Else'] = False
currentRPC = startRPC(client_id['Halo 2'])
currentRPC.connect()
changedRPC['Halo 2'] = client_id['Halo 2']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Classic'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Classic']['Halo2'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Classic'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Classic']['Halo2'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Classic'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Classic']['Halo2'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(2)['Halo2Classic'][presence['details']], presence['details'], dictionary.jsonDictionary(2)['Halo2Classic']['Halo2'], presence['state'], presence['state'], presence['details'], browsingStamp)
elif(presence['state'].find("H: R:") != -1):
if(changedRPC['Halo R'] == False):
if((changedRPC['Else'] or changedRPC['Halo 4'] or changedRPC['Halo 2'] or changedRPC['Halo 4']) != False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 4'] = False
changedRPC['Halo 3'] = False
changedRPC['Else'] = False
currentRPC = startRPC(client_id['Halo R'])
currentRPC.connect()
changedRPC['Halo R'] = client_id['Halo R']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(0)[presence['details']], presence['details'], dictionary.jsonDictionary(0)['HaloReach'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(0)[presence['details']], presence['details'], dictionary.jsonDictionary(0)['HaloReach'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, dictionary.jsonDictionary(0)[presence['details']], presence['details'], dictionary.jsonDictionary(0)['HaloReach'], presence['state'], presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, dictionary.jsonDictionary(0)[presence['details']], presence['details'], dictionary.jsonDictionary(0)['HaloReach'], presence['state'], presence['state'], presence['details'], browsingStamp)
else:
if(changedRPC['Else'] == False):
currentRPC.close()
changedRPC['Halo CE'] = False
changedRPC['Halo 2'] = False
changedRPC['Halo 3'] = False
changedRPC['Halo 4'] = False
currentRPC = startRPC(client_id['main'])
currentRPC.connect()
changedRPC['Else'] = client_id['main']
browsingStamp = timestamp()
if(steam_invite_url):
rpc(currentRPC, "large", presence['game'], device, deviceTitle, presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, "large", presence['game'], device, deviceTitle, presence['state'], presence['details'], browsingStamp)
else:
if(steam_invite_url):
rpc(currentRPC, "large", presence['game'], device, deviceTitle, presence['state'], presence['details'], browsingStamp, steam_invite_url)
else:
rpc(currentRPC, "large", presence['game'], device, deviceTitle, presence['state'], presence['details'], browsingStamp)
else:
print("Waiting for Halo Master Chief Collection to start.")
if(steam_invite_url):
print(steam_invite_url)
sleep(7)
clear()
except KeyboardInterrupt or ValueError as e:
print(e)
currentRPC.close()
pass
def readPresence():
"""Reads current presence data from rpc.json.
Returns:
JSON: Returns json from rpc.json or False.
"""
if(path.exists(application_path() + '\\rpc.json')):
with open(application_path() + '\\rpc.json') as f:
data = json.load(f)
if(data != None):
return data
else:
return None
else:
return False
def timestamp():
browsingStamp = time()
return browsingStamp
def startRPC(client_id):
RPC = Presence(client_id)
RPC.connect()
return RPC
def closeRPC(RPC):
Presence(RPC).close()
def rpc(rpc:object, li:str, lt:str, si:str, st:str, state:str, details:str, startTimestamp:float, buttonUrl = None):
"""Creates a rich presence setting. Will continuously go on till an error occurs
Args:
rpc (object): Presence(client_id).connect()
li (str): Large Image Key
lt (str): Large Image Text
si (str): Small Image Key
st (str): Small Image Text
state (str): Current state the user is in.
details (str): Ussually the game details
startTimestamp (float): A timer that starts when a new rpc is set.
"""
try:
if(buttonUrl != None):
rpc.update(
large_image=li,
large_text=lt,
small_image=si,
small_text=st,
state=state,
details=details,
start=startTimestamp,
buttons=[{
"label": "Join Game",
"url": buttonUrl
}]
)
else:
rpc.update(
large_image=li,
large_text=lt,
small_image=si,
small_text=st,
state=state,
details=details,
start=startTimestamp,
)
except KeyboardInterrupt or Exception as e:
print(e)
rpc.close()
def writejsonfile():
print("No rpc.json. Writting new file ...")
if(path.isfile(application_path() + '\\rpc.json') != True):
open("rpc.json", "x")
print("You can get your steam id here: https://store.steampowered.com/account/ \nYou can also just hit enter to skip this prompt.")
steamid = str(input("Enter steam id:"))
with open("rpc.json", "w") as f:
activity = {
"details": "",
"state": "",
"device": "",
"game": "",
"steamid": steamid
}
f.write(json.dumps(activity))
return
if __name__ == '__main__':
try:
richpresence()
except Exception as e:
print(e)
print("Check to make sure discord and Halo Master Chief Collection are running.")
sleep(5)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
