Skip to content

Commit

Permalink
Merge pull request #61 from LeagueOfPoro/configerror
Browse files Browse the repository at this point in the history
feat: User must ack config file error
  • Loading branch information
LeagueOfPoro committed Feb 5, 2023
2 parents 57ce997 + eb68de6 commit 0f281c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import yaml
from yaml.parser import ParserError
from rich import print

from Exceptions.InvalidCredentialsException import InvalidCredentialsException


class Config:
Expand All @@ -18,16 +22,33 @@ def __init__(self, configPath: str) -> None:
with open(configPath, "r", encoding='utf-8') as f:
config = yaml.safe_load(f)
accs = config.get("accounts")
onlyDefaultUsername = True
for account in accs:
self.accounts[account] = {
"username": accs[account]["username"],
"password": accs[account]["password"],

}
if "username" != accs[account]["username"]:
onlyDefaultUsername = False
if onlyDefaultUsername:
raise InvalidCredentialsException
self.debug = config.get("debug", False)
self.connectorDrops = config.get("connectorDropsUrl", "")
except FileNotFoundError as ex:
print(f"ERROR: The configuration file cannot be found at {configPath}")
print(f"[red]CRITICAL ERROR: The configuration file cannot be found at {configPath}\nHave you extacted the ZIP archive and edited the configuration file?")
print("Press any key to exit...")
input()
raise ex
except (ParserError, KeyError) as ex:
print(f"[red]CRITICAL ERROR: The configuration file does not have a valid format.\nPlease, check it for extra spaces and other characters.\nAlternatively, use confighelper.html to generate a new one.")
print("Press any key to exit...")
input()
raise ex
except InvalidCredentialsException as ex:
print(f"[red]CRITICAL ERROR: There are only default credentials in the configuration file.\nYou need to add you Riot account login to config.yaml to receive drops.")
print("Press any key to exit...")
input()
raise ex

with open("bestStreams.txt", "r", encoding='utf-8') as f:
Expand Down
5 changes: 5 additions & 0 deletions Exceptions/InvalidCredentialsException.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from Exceptions.CapsuleFarmerEvolvedException import CapsuleFarmerEvolvedException

class InvalidCredentialsException(CapsuleFarmerEvolvedException):
def __init__(self):
super().__init__(f"Invalid account credentials.")

0 comments on commit 0f281c5

Please sign in to comment.