From 603a169c39494770348bf1c8f16d8b9ec832b5fc Mon Sep 17 00:00:00 2001 From: confestim Date: Tue, 16 May 2023 21:33:25 +0200 Subject: [PATCH 1/2] Windows folders :( --- .gitignore | 16 ++++++++++++++-- src/client/README.md | 23 ++++++++++++++++++----- src/client/classes/UI.py | 5 +++-- src/client/main.py | 7 +++++-- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index af997ef..187fc99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,22 @@ +# Config config.ini + +# Environment .env/ + +# Database db.sqlite3 + +# Build garbage __pycache__/ migrations/ build/ dist/ -.vscode/ -riotgames.pem main.spec + +# VSCode garbage +.vscode/ + +# LCU_connector leftover +riotgames.pem +test.py diff --git a/src/client/README.md b/src/client/README.md index a9a99bd..921c29b 100644 --- a/src/client/README.md +++ b/src/client/README.md @@ -13,12 +13,25 @@ SITE_URL = "your-server.com" ``` ## Releases -Check out the releases for pre-compiled binaries of the client and server. +Check out the releases for pre-compiled binaries/installers of the client. Remember to edit the config.ini file before running. That will be done in the setup, but still. -## TODOs +## Manual compilationn +Compile the client like so. -1. [x] Make the server and client talk to each other - * [x] Based on MMR - * [x] Based on cached IDs +Firstly, check if your Python version is => 3.11 +``` +$ python --version +> Python 3.11.3 +``` +Then, clone the repository. +`$ git clone https://github.com/confestim/custoMM` +`$ cd custoMM/src/client` +If you don't have pyinstaller installed, do: +`$ pip install pyinstaller` +Once that's ready, you're ready to compile! +`$ python -m PyInstaller --onefile main.py` +The exe file will reside in the newly created dist/ folder. Don't forget to copy the assets and the config to the same folder that your EXE resides(that means you will have to send them over to your friends along with the EXE file): +`cp assets ../config.ini dist` + diff --git a/src/client/classes/UI.py b/src/client/classes/UI.py index 8e85df8..17177b7 100644 --- a/src/client/classes/UI.py +++ b/src/client/classes/UI.py @@ -1,13 +1,14 @@ import pystray from PIL import Image from .Scraper import Scraper -image = Image.open("assets/icon.png") import pyautogui from time import sleep class UI(): - def __init__(self,scraper, periodic): + def __init__(self,scraper, periodic, parent): + image = Image.open(parent + "\\assets\\icon.png") + self.periodic = periodic self.menu = pystray.Menu( pystray.MenuItem( diff --git a/src/client/main.py b/src/client/main.py index bb63dce..a62995f 100644 --- a/src/client/main.py +++ b/src/client/main.py @@ -2,6 +2,7 @@ import requests # Edit config.ini when running for the first time import sys +import os import configparser from time import sleep import logging @@ -13,8 +14,10 @@ from classes.PeriodicScraper import PeriodicScraper from classes.Scraper import Scraper # Config section +parent = os.path.dirname(os.path.abspath(__file__)) config = configparser.ConfigParser() -config.read("../config.ini") +logging.info(parent + "\\config.ini") +print(parent + "\\config.ini") URL = config["DEFAULT"]["URL"] logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO) @@ -33,7 +36,7 @@ def main(): # Match scraping # Running the UI periodic = PeriodicScraper() - ui = UI(scraper=periodic.connector, periodic=periodic) + ui = UI(scraper=periodic.connector, periodic=periodic, parent=parent) periodic.start() periodic.join() From 41012f11c355e43fa8393d87a465335ef53c826e Mon Sep 17 00:00:00 2001 From: confestim Date: Tue, 16 May 2023 22:55:08 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Fixed=20README=20and=20file=20paths,=20time?= =?UTF-8?q?=20to=20merge!=F0=9F=98=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- LICENSE | 2 +- src/client/README.md | 4 +++- src/client/classes/Game.py | 7 ++----- src/client/classes/PeriodicScraper.py | 4 ++-- src/client/classes/Scraper.py | 7 +++---- src/client/classes/UI.py | 28 ++++++++++++++------------- src/client/config.ini | 7 +++++++ src/client/main.py | 24 ++++++++++++++--------- 9 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 src/client/config.ini diff --git a/.gitignore b/.gitignore index 187fc99..a028d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Config -config.ini +src/config.ini # Environment .env/ diff --git a/LICENSE b/LICENSE index 2071b23..6af6580 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2023 Boyan Karakostov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/client/README.md b/src/client/README.md index 921c29b..a1469b0 100644 --- a/src/client/README.md +++ b/src/client/README.md @@ -29,9 +29,11 @@ Then, clone the repository. If you don't have pyinstaller installed, do: `$ pip install pyinstaller` Once that's ready, you're ready to compile! -`$ python -m PyInstaller --onefile main.py` +`$ python -m PyInstaller --onefile main.py --noconsole` The exe file will reside in the newly created dist/ folder. Don't forget to copy the assets and the config to the same folder that your EXE resides(that means you will have to send them over to your friends along with the EXE file): `cp assets ../config.ini dist` + +From here, do whatever with the dist folder, I would recommend zipping it. diff --git a/src/client/classes/Game.py b/src/client/classes/Game.py index fa6c28f..110601d 100644 --- a/src/client/classes/Game.py +++ b/src/client/classes/Game.py @@ -4,11 +4,8 @@ import configparser from .Util import WhatTheFuckDidYouDo class Game: - def __init__(self, *, loop=None, connection): - # Config - self.config = configparser.ConfigParser() - # Relative paths bad, fix this - self.config.read ("../config.ini") + def __init__(self, *, loop=None, connection,config): + self.config = config self.URL = self.config["DEFAULT"]["URL"] self.password = self.config["LEAGUE"]["LOBBY_PASS"] # Loop until we get connection diff --git a/src/client/classes/PeriodicScraper.py b/src/client/classes/PeriodicScraper.py index db33a3f..2547798 100644 --- a/src/client/classes/PeriodicScraper.py +++ b/src/client/classes/PeriodicScraper.py @@ -4,10 +4,10 @@ from .Scraper import Scraper import logging class PeriodicScraper(Thread): - def __init__(self): + def __init__(self, config): Thread.__init__(self) self.daemon = True - self.connector:Scraper = Scraper() + self.connector:Scraper = Scraper(config=config) self.closed = False def run(self): diff --git a/src/client/classes/Scraper.py b/src/client/classes/Scraper.py index f6d19fe..1d7fcca 100644 --- a/src/client/classes/Scraper.py +++ b/src/client/classes/Scraper.py @@ -9,11 +9,10 @@ from .Util import WhatTheFuckDidYouDo from .Game import Game class Scraper: - def __init__(self, *, loop=None, ui=None): + def __init__(self, *, loop=None, ui=None, config): self.ui = ui - self.config = configparser.ConfigParser() + self.config = config # Relative paths bad, fix this - self.config.read ("../config.ini") self.URL = self.config["DEFAULT"]["URL"] # Loop until we get connection self.connection = None @@ -184,7 +183,7 @@ class Scraper: checker = requests.get(f"{self.URL}/current").json()[0] except IndexError: return "NO_GAME" - game = Game(connection=self.connection) + game = Game(connection=self.connection, config=self.config) # If you are indeed the creator, create the game and disclose its name to the server if checker["creator"] == self.name: diff --git a/src/client/classes/UI.py b/src/client/classes/UI.py index 17177b7..20fdd29 100644 --- a/src/client/classes/UI.py +++ b/src/client/classes/UI.py @@ -3,12 +3,14 @@ from PIL import Image from .Scraper import Scraper import pyautogui from time import sleep +import sys, os class UI(): - def __init__(self,scraper, periodic, parent): - image = Image.open(parent + "\\assets\\icon.png") - + def __init__(self,scraper, periodic, base_dir): + + image = Image.open(os.path.join(base_dir, os.path.join("assets", "icon.png"))) + self.periodic = periodic self.menu = pystray.Menu( pystray.MenuItem( @@ -27,32 +29,32 @@ class UI(): self.icon = pystray.Icon( "name", image, "CustoMM", self.menu) self.scraper = scraper - self.check_registration() self.icon.run_detached() - + self.icon.notify("CustoMM is running in the background.", title="CustoMM") + self.check_registration() def check(self): - self.icon.notify("This is discouraged, as it is done automatically anyway.", "Checking for game...") + self.icon.notify("This is discouraged, as it is done automatically anyway.", "Checking for game...", title="CustoMM") game = self.scraper.check_for_game() if game == "NO_GAME": - self.icon.notify("Please create a game on discord.", "No game found.") + self.icon.notify("Please create a game on discord.", "No game found.", title="CustoMM") elif game == "CREATED": - self.icon.notify("GLHF!", "You are the host of a new game!",) + self.icon.notify("GLHF!", "You are the host of a new game!", title="CustoMM") elif game == "JOINED": - self.icon.notify("Waiting for players...", "Game joined!") + self.icon.notify("Waiting for players...", "Game joined!", title="CustoMM") def report(self): self.icon.notify("Game report initiated.") self.scraper.scrape() - self.icon.notify("Game reported", "Your game has been reported to the server.") + self.icon.notify("Game reported", "Your game has been reported to the server.", title="CustoMM") def check_registration(self): check = self.scraper.check_summoner() if check == "USER_DOES_NOT_EXIST": - self.icon.notify("You are not registered, please register on the website.") + self.icon.notify("You are not registered, please register on the website.", title="CustoMM") elif check == "UNCLAIMED": - self.icon.notify("You have not claimed your account yet, please claim it on discord -> !registed .") + self.icon.notify("You have not claimed your account yet, please claim it on discord -> !registed .", title="CustoMM") elif check[0] == "REGISTRATION_IN_PROGRESS": prompt = pyautogui.confirm(f"Your account is currently being registered by {check[1]}, do you want to proceed?") if prompt: @@ -60,7 +62,7 @@ class UI(): else: self.scraper.register_summoner(False, check[1]) else: - self.icon.notify(f"Your account is registered to {check[0]} and your account name is {check[1]}.") + self.icon.notify(f"Your account is registered to {check[0]} and your account name is {check[1]}.", title="CustoMM") def quit(self, icon, query): diff --git a/src/client/config.ini b/src/client/config.ini new file mode 100644 index 0000000..1eb0d48 --- /dev/null +++ b/src/client/config.ini @@ -0,0 +1,7 @@ +[DEFAULT] +; Your URL here (with no slash at the end) +URL = http://change.me + +[LEAGUE] +; Password for the generated league lobbies +LOBBY_PASS = password123 \ No newline at end of file diff --git a/src/client/main.py b/src/client/main.py index a62995f..ac863bc 100644 --- a/src/client/main.py +++ b/src/client/main.py @@ -1,8 +1,7 @@ import requests # Edit config.ini when running for the first time -import sys -import os +import sys, os import configparser from time import sleep import logging @@ -14,13 +13,20 @@ from classes.PeriodicScraper import PeriodicScraper from classes.Scraper import Scraper # Config section -parent = os.path.dirname(os.path.abspath(__file__)) -config = configparser.ConfigParser() -logging.info(parent + "\\config.ini") -print(parent + "\\config.ini") -URL = config["DEFAULT"]["URL"] logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO) +# Check if bundled +if getattr(sys, 'frozen', False): + base_dir = os.path.dirname(sys.executable) +elif __file__: + base_dir = os.path.dirname(__file__) + +logging.info(base_dir) +config = configparser.ConfigParser() +conf_path = os.path.join(base_dir, "config.ini") +logging.info(conf_path) +config.read(conf_path) +URL = config["DEFAULT"]["URL"] # Test connection to server try: test = requests.get(URL).json() @@ -35,8 +41,8 @@ except Exception: def main(): # Match scraping # Running the UI - periodic = PeriodicScraper() - ui = UI(scraper=periodic.connector, periodic=periodic, parent=parent) + periodic = PeriodicScraper(config=config) + ui = UI(scraper=periodic.connector, periodic=periodic, base_dir=base_dir) periodic.start() periodic.join()