Skip to content

Commit

Permalink
fix errs n stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Niceygy committed Nov 5, 2023
1 parent 677a78c commit 005cefc
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 14 deletions.
9 changes: 9 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Elite:Dangerous Discord Presence
## Installation
1. Download the latest release from [here]()
2. Extract the zip file
3. Navigate to the folder in the terminal. (You can do this by right clicking in the folder and clicking `Open in Terminal`)
3. In the terminal run `pip install -r requirements.txt` & `python ./install.py`
4. Reboot your PC!
It will now run when elite dangerous is running!
## Uninstallation
3 changes: 3 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def load(logDir):

def getCMDR(logs):
print("Parsing log data")
cmdr_name = "CMDR"
for log in logs:
if "event" in log:
try:
Expand Down Expand Up @@ -77,6 +78,8 @@ def getStation(logs):

def eventHandler(event):
print("Parsing log data - looking for events")
if event == "Shutdown":
return "0"
if event in eventAssociationsMain:
if eventAssociationsMain[event] == "Fileheader":
print("Fileheader found, skipping")
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getpass
from time import sleep
import os
USER_NAME = getpass.getuser()


def add_to_startup(file_path=""):
if file_path == "":
file_path = os.path.dirname(os.path.realpath(__file__))
bat_path = r'C:/Users/%s\AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup' % USER_NAME
with open(bat_path + '/' + "open.bat", "w+") as bat_file:
bat_file.write(r'start "" "%s"' % file_path)


fp = input("Where is main.py? To find the path, right click on main.py and click 'Copy As Path'")
add_to_startup(file_path=fp)
print("Done!")
sleep(2)
75 changes: 61 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
from discordrp import Presence
import time
import getpass
import os
import pystray
from PIL import Image
import threading

from game import getCMDR, load, getSystem, eventHandler
global username
username = getpass.getuser()

def create_icon():
# Create an image for the icon
image = Image.open('D:\github\EDDP\EDDP\icon.png')
icon = pystray.Icon("EDDP", image)

# Define the action to be taken when the icon is clicked
def action(icon, item):
icon.stop()

# Add a menu item to the icon
icon.menu = pystray.Menu(pystray.MenuItem('Quit', action))

# Run the icon
icon.run()


def awaitGame():
print("Awaiting game")
while True:
#list logs dir
listOne = os.listdir("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
time.sleep(15)
listTwo = os.listdir("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
if listOne != listTwo:
print("Game found")
mainGameLoop()
else:
print("Game not found")
pass

def updatePrecense(presence, state, start_time, cmdr):
presence.set(
Expand All @@ -25,19 +58,33 @@ def updatePrecense(presence, state, start_time, cmdr):
)

client_id = "1170388114498392095"
start_time = int(time.time())

with Presence(client_id) as presence:
logFileLoaded = load("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
print("Connected")
cmdr = getCMDR(logFileLoaded)
updatePrecense(presence, "In the main menu", start_time, cmdr)
print("Presence updated")
def mainGameLoop():
print("Starting game loop")
start_time = int(time.time())

while True:
time.sleep(15)
logs = load("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
for log in logs:
if "event" in log:
currently = eventHandler(log["event"])
updatePrecense(presence, currently, start_time, cmdr)
with Presence(client_id) as presence:
logFileLoaded = load("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
print("Connected")
cmdr = getCMDR(logFileLoaded)
updatePrecense(presence, "In the main menu", start_time, cmdr)
print("Presence updated")

while True:
time.sleep(15)
logs = load("C:/Users/"+username+"/Saved Games/Frontier Developments/Elite Dangerous")
for log in logs:
if "event" in log:
currently = eventHandler(log["event"])
if currently == "0":
print("Shutting down...")
break
else:
updatePrecense(presence, currently, start_time, cmdr)

if __name__ == "__main__":
icon_thread = threading.Thread(target=create_icon)

# Start the thread
icon_thread.start()
awaitGame()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pypresence==4.3.0
18 changes: 18 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import pystray
from PIL import Image

image = Image.open("D:\github\EDDP\EDDP\icon.png")


def after_click(icon, query):
if str(query) == "Exit":
icon.stop()


icon = pystray.Icon("GFG", image, "GeeksforGeeks",
menu=pystray.Menu(
pystray.MenuItem("Exit", after_click)))

icon.run()
print("test")

0 comments on commit 005cefc

Please sign in to comment.