Skip to content

Commit

Permalink
Merge pull request #98 from iholston/feat/gui
Browse files Browse the repository at this point in the history
feat/gui merge
  • Loading branch information
iholston committed Oct 4, 2023
2 parents afb53ce + 455acc4 commit e1ce07f
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 224 deletions.
1 change: 1 addition & 0 deletions installer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ py -m pip install pywin32
py -m pip install pyautogui
py -m pip install requests
py -m pip install urllib3
py -m pip install dearpygui

5 changes: 0 additions & 5 deletions launcher.bat

This file was deleted.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mouse
pywin32
pyautogui
requests
urllib3
urllib3
dearpygui
File renamed without changes.
File renamed without changes.
35 changes: 0 additions & 35 deletions resources/account.py

This file was deleted.

Binary file added resources/images/a.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions resources/lolbot.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Paths]
leaguepath = D:/Riot Games/League of Legends

[Game]
maxlevel = 300
gamemode = 840

[Graphical]
textcolor = [0.0, 255.0, 0.0, 255.0]

67 changes: 0 additions & 67 deletions resources/notes.txt

This file was deleted.

48 changes: 37 additions & 11 deletions scripts/account.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
"""
Gets an account username and password for leveling
Implement this file to connect to your database of league accounts.
There is an example file in resources that can drop-in replace this for
those who want a quick and simple option.
A simple implementation of account.py using a json file
"""

import json
import os
import constants

accounts_path = os.path.dirname(os.getcwd()) + "/resources/accounts.json"
with open(accounts_path, 'r') as f:
data = json.load(f)

def get_username() -> str:
"""Gets username from database"""
return 'account_username'
"""Gets an available account username from JSON file"""
for account in data['accounts']:
if not account['leveled']:
return account['username']

def get_password() -> str:
"""Gets password from database"""
return 'account_password'
"""Gets an available account password from JSON file"""
for account in data['accounts']:
if not account['leveled']:
return account['password']

def set_account_as_leveled() -> None:
"""Sets account as leveled in database"""
pass
"""Sets account as leveled in the JSON file"""
for account in data['accounts']:
if not account['leveled']:
account['leveled'] = True
with open(accounts_path, 'w') as json_file:
json.dump(data, json_file)
return

def add_account(account) -> None:
"""Writes account to JSON"""
data.append(account)
with open(constants.LOCAL_ACCOUNTS_PATH, 'w') as outfile:
outfile.write(json.dumps(data, indent=4))

def get_all_accounts() -> dict:
"""Returns all account information"""
global data
with open(accounts_path, 'r') as f:
data = json.load(f)
return data
79 changes: 53 additions & 26 deletions scripts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,58 @@ def __init__(self) -> None:
self.log = logging.getLogger(__name__)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def set_rc_headers(self) -> None:
"""Sets header info for Riot Client"""
self.log.debug("Initializing Riot Client session")
self.host = RCU_HOST
self.client_username = RCU_USERNAME

# lockfile
lockfile = open(RIOT_CLIENT_LOCKFILE_PATH, 'r')
data = lockfile.read()
self.log.debug(data)
lockfile.close()
data = data.split(':')
self.procname = data[0]
self.pid = data[1]
self.port = data[2]
self.client_password = data[3]
self.protocol = data[4]

# headers
userpass = b64encode(bytes('{}:{}'.format(self.client_username, self.client_password), 'utf-8')).decode('ascii')
self.headers = {'Authorization': 'Basic {}'.format(userpass), "Content-Type": "application/json"}
self.log.debug(self.headers['Authorization'])


def set_lcu_headers(self, verbose: bool = True) -> None:
"""Sets header info for League Client"""
if verbose:
self.log.info("Connecting to LCU API")
else:
self.log.debug("Connecting to LCU API")
self.host = LCU_HOST
self.client_username = LCU_USERNAME

# lockfile
lockfile = open(LEAGUE_CLIENT_LOCKFILE_PATH, 'r')
data = lockfile.read()
self.log.debug(data)
lockfile.close()
data = data.split(':')
self.procname = data[0]
self.pid = data[1]
self.port = data[2]
self.client_password = data[3]
self.protocol = data[4]

# headers
userpass = b64encode(bytes('{}:{}'.format(self.client_username, self.client_password), 'utf-8')).decode('ascii')
self.headers = {'Authorization': 'Basic {}'.format(userpass)}
self.log.debug(self.headers['Authorization'])

def connect_lcu(self, verbose: bool = True) -> None:
"""Sets header infor and connects to League Client"""
"""Tries to connect to league client"""
if verbose:
self.log.info("Connecting to LCU API")
else:
Expand All @@ -54,11 +104,11 @@ def connect_lcu(self, verbose: bool = True) -> None:
self.log.debug(self.headers['Authorization'])

# connect
for i in range(15):
for i in range(30):
sleep(1)
try:
r = self.request('get', '/lol-login/v1/session')
except ConnectionError:
except:
continue
if r.json()['state'] == 'SUCCEEDED':
self.log.debug(r.json())
Expand All @@ -71,29 +121,6 @@ def connect_lcu(self, verbose: bool = True) -> None:
return
raise Exception("Could not connect to League Client")

def connect_rc(self) -> None:
"""Sets header info for Riot Client"""
self.log.debug("Initializing Riot Client session")
self.host = RCU_HOST
self.client_username = RCU_USERNAME

# lockfile
lockfile = open(RIOT_CLIENT_LOCKFILE_PATH, 'r')
data = lockfile.read()
self.log.debug(data)
lockfile.close()
data = data.split(':')
self.procname = data[0]
self.pid = data[1]
self.port = data[2]
self.client_password = data[3]
self.protocol = data[4]

# headers
userpass = b64encode(bytes('{}:{}'.format(self.client_username, self.client_password), 'utf-8')).decode('ascii')
self.headers = {'Authorization': 'Basic {}'.format(userpass), "Content-Type": "application/json"}
self.log.debug(self.headers['Authorization'])

def request(self, method: str, path: str, query: str = '', data: dict = None) -> requests.models.Response:
"""Handles HTTP requests to Riot Client or League Client server"""
if data is None:
Expand Down
12 changes: 9 additions & 3 deletions scripts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import pyautogui
import utils
import api
import account
import launcher
import account
from time import sleep
from datetime import datetime, timedelta
from constants import *
from game import Game
from handler import MultiProcessLogHandler


class ClientError(Exception):
Expand All @@ -29,18 +30,21 @@ def __str__(self):
class Client:
"""Client class that handles the League Client and all tasks needed to start a new game"""

def __init__(self) -> None:
def __init__(self, message_queue) -> None:
self.connection = api.Connection()
self.log = logging.getLogger(__name__)
self.launcher = launcher.Launcher()
self.log = logging.getLogger(__name__)
self.handler = MultiProcessLogHandler(message_queue)
self.username = ""
self.password = ""
self.account_level = 0
self.phase = ""
self.prev_phase = None
self.client_errors = 0
self.phase_errors = 0
self.handler.set_logs()
utils.print_ascii()
self.account_loop()

def account_loop(self) -> None:
"""Main loop, gets an account, launches league, levels the account, and repeats"""
Expand All @@ -58,10 +62,12 @@ def account_loop(self) -> None:
raise ClientError("Max errors reached.Exiting")
utils.close_processes()
except launcher.LauncherError as le:
pyautogui.alert(le)
self.log.error(le.__str__())
self.log.error(traceback.print_exc())
return
except Exception as e:
pyautogui.alert(e)
self.log.error(e)
self.log.error(traceback.print_exc())
return
Expand Down
Loading

0 comments on commit e1ce07f

Please sign in to comment.