Added timouts and ready to ship ver 1.1.1 :party:

This commit is contained in:
confestim 2023-05-16 21:10:07 +02:00
parent d66becf13a
commit cee70ab57d
7 changed files with 45 additions and 27 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ dist/
.vscode/ .vscode/
src/client/riotgames.pem src/client/riotgames.pem
src/client/main.spec

View File

@ -2,7 +2,7 @@
<p align="center"> <p align="center">
<img src="images/logo.png"/> <img src="images/logo.png"/>
</p> </p>
![PyVer >= 3.11](https://img.shields.io/badge/Python-%3E%3D3.11-green)![Ver = 1.1.1](https://img.shields.io/badge/Version-1.1.1-blueviolet)
## What is this? ## What is this?
This is a project inspired by a heavy loss while playing customs in league of legends. The idea is to create fair teams, without taking rank into account(cuz that's boring and we're antiestablishmentarians 🗿♿🥶). This is a project inspired by a heavy loss while playing customs in league of legends. The idea is to create fair teams, without taking rank into account(cuz that's boring and we're antiestablishmentarians 🗿♿🥶).

View File

@ -59,9 +59,11 @@ class Game:
# Starts champ select # Starts champ select
return self.connection.post("/lol-lobby/v1/lobby/custom/start-champ-select", data={}) return self.connection.post("/lol-lobby/v1/lobby/custom/start-champ-select", data={})
def move(self, team:str): def move(self):
return self.connection.post("/lol-lobby/v1/lobby/custom/switch-teams", data={}) return self.connection.post("/lol-lobby/v1/lobby/custom/switch-teams", data={})
def leave(self):
return self.connection.delete("/lol-lobby/v2/lobby")
def get_teams(self): def get_teams(self):
# Gets team # Gets team
cfg = self.connection.get("/lol-lobby/v2/lobby").json()["gameConfig"] cfg = self.connection.get("/lol-lobby/v2/lobby").json()["gameConfig"]

View File

@ -1,16 +1,23 @@
from time import sleep from time import sleep
from threading import Thread from threading import Thread
from .Scraper import Scraper from .Scraper import Scraper
import logging
class PeriodicScraper(Thread): class PeriodicScraper(Thread):
def __init__(self): def __init__(self):
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
self.connector:Scraper = Scraper() self.connector:Scraper = Scraper()
self.start() self.closed = False
def run(self): def run(self):
self.connector.check_for_game()
while True: while True:
if self.closed:
self.connector.connection.stop()
break
game_state = self.connector.check_for_game()
logging.info("Scraping...")
self.connector.scrape() self.connector.scrape()
sleep(5 * 60) sleep(5)

View File

@ -1,6 +1,6 @@
from lcu_connector import Connector from lcu_connector import Connector
from lcu_connector.exceptions import ClientProcessError from lcu_connector.exceptions import ClientProcessError
import asyncio import logging
import requests import requests
import time, sys import time, sys
import json import json
@ -20,7 +20,8 @@ class Scraper:
while not self.connection: while not self.connection:
try: try:
self.connection = Connector(start=True) self.connection = Connector()
self.connection.start()
except ClientProcessError: except ClientProcessError:
print("League client not open, sleeping...") print("League client not open, sleeping...")
time.sleep(90) time.sleep(90)
@ -127,7 +128,7 @@ class Scraper:
# Case 2: It belongs to somebody # Case 2: It belongs to somebody
if claimed['lol_id'] and claimed['lol']: if claimed['lol_id'] and claimed['lol']:
# Notify them (if that is the case) that we will do nothing about their new name (slight TODO). # Change name in db if different in-game
if claimed['lol'] != self.summoner['displayName']: if claimed['lol'] != self.summoner['displayName']:
self.register_summoner(True, claimed) self.register_summoner(True, claimed)
@ -148,23 +149,31 @@ class Scraper:
# This is buggy, try to find a better way to do this. # This is buggy, try to find a better way to do this.
# Like for example, letting team 1 pass first, and then team 2. # Like for example, letting team 1 pass first, and then team 2.
local_teams = game.get_teams() local_teams = game.get_teams()
print(local_teams[0], local_teams[1], checker["teams"][0], checker["teams"][1])
if name in local_teams[0] and not name in checker["teams"][0]: if name in local_teams[0] and not name in checker["teams"][0]:
game.move("blue") game.move()
print("blue") logging.info("Moving to Team 2")
elif name in local_teams[1] and not name in checker["teams"][1]: elif name in local_teams[1] and not name in checker["teams"][1]:
game.move("red") game.move()
print("red") logging.info("Moving to Team 1")
def start(self, checker, game): def start(self, checker, game):
self.move_needed(checker, game, self.name) self.move_needed(checker, game, self.name)
time.sleep(5) time.sleep(5)
# Wait until there are 10 players(confirmed) in the lobby # Wait until there are 10 players(confirmed) in the lobby
while requests.get(f"{self.URL}/current/{self.name}").json()["players"] != 10: timeout_counter = 0
print("Waiting for players...") while response := requests.get(f"{self.URL}/current/{self.name}").json()["players"] != 10:
logging.info("Waiting for players...")
timeout_counter += 5
if timeout_counter == 60:
logging.info("Timeout, aborting...")
break
time.sleep(5) time.sleep(5)
game.start() if response == 10:
logging.info("Starting game...")
game.start()
else:
game.leave()
requests.delete(f"{self.URL}/current/{self.name}") requests.delete(f"{self.URL}/current/{self.name}")
def check_for_game(self): def check_for_game(self):
@ -246,5 +255,4 @@ class Scraper:
if req.status_code == 500: if req.status_code == 500:
print("Serverside error! Contact maintainer!") print("Serverside error! Contact maintainer!")
self.connection.stop()
return len(games) return len(games)

View File

@ -4,12 +4,11 @@ from .Scraper import Scraper
image = Image.open("assets/icon.png") image = Image.open("assets/icon.png")
import pyautogui import pyautogui
from time import sleep from time import sleep
import logging
class UI(): class UI():
def __init__(self,scraper): def __init__(self,scraper, periodic):
self.periodic = periodic
self.menu = pystray.Menu( self.menu = pystray.Menu(
pystray.MenuItem( pystray.MenuItem(
"Check registration", self.check_registration, default=True "Check registration", self.check_registration, default=True
@ -30,6 +29,7 @@ class UI():
self.check_registration() self.check_registration()
self.icon.run_detached() self.icon.run_detached()
def check(self): 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...")
game = self.scraper.check_for_game() game = self.scraper.check_for_game()
@ -42,7 +42,6 @@ class UI():
def report(self): def report(self):
self.icon.notify("Game report initiated.") self.icon.notify("Game report initiated.")
logging.warning(self.icon)
self.scraper.scrape() 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.")
@ -65,4 +64,5 @@ class UI():
def quit(self, icon, query): def quit(self, icon, query):
icon.stop() icon.stop()
self.periodic.closed = True

View File

@ -4,7 +4,7 @@ import requests
import sys import sys
import configparser import configparser
from time import sleep from time import sleep
import threading import logging
# Custom imports # Custom imports
from classes.Util import WhatTheFuckDidYouDo from classes.Util import WhatTheFuckDidYouDo
@ -16,6 +16,7 @@ from classes.Scraper import Scraper
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("../config.ini") config.read("../config.ini")
URL = config["DEFAULT"]["URL"] URL = config["DEFAULT"]["URL"]
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
# Test connection to server # Test connection to server
try: try:
@ -31,12 +32,11 @@ except Exception:
def main(): def main():
# Match scraping # Match scraping
# Running the UI # Running the UI
ui = UI(scraper=Scraper())
scraper = Scraper(ui=ui)
periodic = PeriodicScraper() periodic = PeriodicScraper()
ui = UI(scraper=periodic.connector, periodic=periodic)
periodic.start()
periodic.join()
# Loop until close, let stuff kill itself
while threading.active_count() >= 3:
sleep(10)
if __name__ == "__main__": if __name__ == "__main__":
main() main()