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/
src/client/riotgames.pem
src/client/main.spec

View File

@ -2,7 +2,7 @@
<p align="center">
<img src="images/logo.png"/>
</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?
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
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={})
def leave(self):
return self.connection.delete("/lol-lobby/v2/lobby")
def get_teams(self):
# Gets team
cfg = self.connection.get("/lol-lobby/v2/lobby").json()["gameConfig"]

View File

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

View File

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

View File

@ -4,12 +4,11 @@ from .Scraper import Scraper
image = Image.open("assets/icon.png")
import pyautogui
from time import sleep
import logging
class UI():
def __init__(self,scraper):
def __init__(self,scraper, periodic):
self.periodic = periodic
self.menu = pystray.Menu(
pystray.MenuItem(
"Check registration", self.check_registration, default=True
@ -30,6 +29,7 @@ class UI():
self.check_registration()
self.icon.run_detached()
def check(self):
self.icon.notify("This is discouraged, as it is done automatically anyway.", "Checking for game...")
game = self.scraper.check_for_game()
@ -42,7 +42,6 @@ class UI():
def report(self):
self.icon.notify("Game report initiated.")
logging.warning(self.icon)
self.scraper.scrape()
self.icon.notify("Game reported", "Your game has been reported to the server.")
@ -65,4 +64,5 @@ class UI():
def quit(self, icon, query):
icon.stop()
self.periodic.closed = True

View File

@ -4,7 +4,7 @@ import requests
import sys
import configparser
from time import sleep
import threading
import logging
# Custom imports
from classes.Util import WhatTheFuckDidYouDo
@ -16,6 +16,7 @@ from classes.Scraper import Scraper
config = configparser.ConfigParser()
config.read("../config.ini")
URL = config["DEFAULT"]["URL"]
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
# Test connection to server
try:
@ -31,12 +32,11 @@ except Exception:
def main():
# Match scraping
# Running the UI
ui = UI(scraper=Scraper())
scraper = Scraper(ui=ui)
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__":
main()