Skip to content

Commit

Permalink
Revert "feat: Added Drop and 2FA Notifications and Toasts [BREAKING] (#…
Browse files Browse the repository at this point in the history
…110)" (#119)

This reverts commit 97b7e14.
  • Loading branch information
LeagueOfPoro committed Feb 10, 2023
1 parent 0b35ed2 commit 7a7ddd7
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 208 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ chromedriver
.DS_Store

# Sensitive configs
**/config.dev.yaml
sessions/
logs/
config.dev.yaml
*.exe
*.log

Expand Down Expand Up @@ -171,6 +169,3 @@ cython_debug
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea

# Visual Studio
.vscode/
2 changes: 0 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ beautifulsoup4 = "*"
pyyaml = "*"
rich = "*"
pyjwt = "*"
notify-py = "*"
simpleaudio = "*"

[dev-packages]
autopep8 = "*"
Expand Down
7 changes: 2 additions & 5 deletions src/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pickle
from pathlib import Path
import jwt
from NotificationManager import NotificationManager

from SharedData import SharedData

Expand All @@ -22,14 +21,13 @@ class Browser:
SESSION_REFRESH_INTERVAL = 1800.0
STREAM_WATCH_INTERVAL = 60.0

def __init__(self, log, config: Config, account: str, notificationManager: NotificationManager, sharedData: SharedData):
def __init__(self, log, config: Config, account: str, sharedData: SharedData):
"""
Initialize the Browser class
:param log: log variable
:param config: Config class object
:param account: account string
:param notificationManager: Notification manager
"""
self.client = cloudscraper.create_scraper(
browser={
Expand All @@ -40,8 +38,8 @@ def __init__(self, log, config: Config, account: str, notificationManager: Notif
debug=False)
self.log = log
self.config = config
self.currentlyWatching = {}
self.account = account
self.notificationManager = notificationManager
self.sharedData = sharedData

def login(self, username: str, password: str, refreshLock) -> bool:
Expand Down Expand Up @@ -69,7 +67,6 @@ def login(self, username: str, password: str, refreshLock) -> bool:

resJson = res.json()
if "multifactor" in resJson.get("type", ""):
self.notificationManager.makeNotificationOn2FA(username, "New 2FA code required")
twoFactorCode = input(f"Enter 2FA code for {self.account}:\n")
print("Code sent")
data = {"type": "multifactor", "code": twoFactorCode, "rememberDevice": True}
Expand Down
130 changes: 11 additions & 119 deletions src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path

from Exceptions.InvalidCredentialsException import InvalidCredentialsException
from Exceptions.AssetNotFoundException import AssetNotFoundException


class Config:
Expand Down Expand Up @@ -35,46 +34,14 @@ def __init__(self, configPath: str) -> None:
"password": accs[account]["password"]
}
if not self.accounts:
raise InvalidCredentialsException

if config.get("notificationAll", False):
self.notificationOnStart = True
self.notificationOn2FA = True
self.notificationOnDrop = True
self.notificationOnFault = True
else:
self.notificationOnStart = config.get("notificationOnStart", False)
self.notificationOn2FA = config.get("notificationOn2FA", False)
self.notificationOnDrop = config.get("notificationOnDrop", False)
self.notificationOnFault = config.get("notificationOnFault", False)

if config.get("soundAll", False):
self.soundOnStart = True
self.soundOn2FA = True
self.soundOnDrop = True
self.soundOnFault = True
else:
self.soundOnStart = config.get("soundOnStart", False)
self.soundOn2FA = config.get("soundOn2FA", False)
self.soundOnDrop = config.get("soundOnDrop", False)
self.soundOnFault = config.get("soundOnFault", False)

self.soundPath = config.get("soundPath","./assets/defaultNotificationSound.wav")
if (self.soundOnStart or self.soundOn2FA or self.soundOnDrop or self.soundOnFault) and not Path(self.soundPath).exists():
raise AssetNotFoundException(self.soundPath)

raise InvalidCredentialsException
self.debug = config.get("debug", False)
self.connectorDrops = config.get("connectorDropsUrl", "")
except FileNotFoundError as ex:
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 AssetNotFoundException as ex:
print(f"[red]CRITICAL ERROR: The notification sound file cannot be found at {self.soundPath}\nYou can specify a different file by 'soundPath: \"/path/to/file.wav\"' in config.")
print("Press any key to exit...")
input()
raise AssetNotFoundException(self.soundPath)
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...")
Expand All @@ -97,6 +64,16 @@ def __init__(self, configPath: str) -> None:
input()
raise ex


def getAccount(self, account: str) -> dict:
"""
Get account information
:param account: string, name of the account
:return: dictionary, account information
"""
return self.accounts[account]

def __findConfig(self, configPath):
"""
Try to find configuartion file in alternative locations.
Expand All @@ -112,88 +89,3 @@ def __findConfig(self, configPath):
if Path("config/config.yaml").exists():
return Path("config/config.yaml")
return configPath

## Getters

def getAccount(self, account: str) -> dict:
"""
Get account information
:param account: string, name of the account
:return: dictionary, account information
"""
return self.accounts[account]

def getSoundPath(self) -> str:
"""
Get custom sound path
:return: soundPath
"""
return self.soundPath

def getNotificationOnStart(self) -> bool:
"""
Get account notificationOnStart Flag
:return: notificationOnStart
"""
return self.notificationOnStart

def getNotificationOn2FA(self) -> bool:
"""
Get account notificationOn2FA Flag
:return: notificationOn2FA
"""
return self.notificationOn2FA

def getNotificationOnDrop(self) -> bool:
"""
Get account notificationOnDrop Flag
:return: notificationOnDrop
"""
return self.notificationOnDrop

def getNotificationOnFault(self) -> bool:
"""
Get account notificationOnFault Flag
:return: notificationOnFault
"""
return self.notificationOnFault

def getSoundOnStart(self) -> bool:
"""
Get account SoundOnStart Flag
:return: SoundOnStart
"""
return self.soundOnStart

def getSoundOn2FA(self) -> bool:
"""
Get account soundOn2FA Flag
:return: soundOn2FA
"""
return self.soundOn2FA

def getSoundOnDrop(self) -> bool:
"""
Get account soundOnDrop Flag
:return: soundOnDrop
"""
return self.soundOnDrop

def getSoundOnFault(self) -> bool:
"""
Get account soundOnFault Flag
:return: soundOnFault
"""
return self.soundOnFault


5 changes: 0 additions & 5 deletions src/Exceptions/AssetNotFoundException.py

This file was deleted.

10 changes: 2 additions & 8 deletions src/FarmThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from threading import Thread
from time import sleep
from Browser import Browser
from Config import Config
import requests
from NotificationManager import NotificationManager


from SharedData import SharedData

Expand All @@ -14,7 +11,7 @@ class FarmThread(Thread):
A thread that creates a capsule farm for a given account
"""

def __init__(self, log, config, account, stats, locks, notificationManager: NotificationManager, sharedData: SharedData):
def __init__(self, log, config, account, stats, locks, sharedData: SharedData):
"""
Initializes the FarmThread
Expand All @@ -27,9 +24,8 @@ def __init__(self, log, config, account, stats, locks, notificationManager: Noti
self.log = log
self.config = config
self.account = account
self.notificationManager = notificationManager
self.stats = stats
self.browser = Browser(self.log, self.config, self.account, self.notificationManager, sharedData)
self.browser = Browser(self.log, self.config, self.account, sharedData)
self.locks = locks
self.sharedData = sharedData

Expand All @@ -40,7 +36,6 @@ def run(self):
try:
self.stats.updateStatus(self.account, "[green]LOGIN")
if self.browser.login(self.config.getAccount(self.account)["username"], self.config.getAccount(self.account)["password"], self.locks["refreshLock"]):
self.notificationManager.makeNotificationOnStart(self.account, "Account login success")
self.stats.updateStatus(self.account, "[green]LIVE")
self.stats.resetLoginFailed(self.account)
while True:
Expand Down Expand Up @@ -72,7 +67,6 @@ def run(self):
self.__notifyConnectorDrops(newDrops)
sleep(Browser.STREAM_WATCH_INTERVAL)
else:
self.notificationManager.makeNotificationOnFault(self.account, "Account login failed")
self.log.error(f"Login for {self.account} FAILED!")
self.stats.addLoginFailed(self.account)
if self.stats.getFailedLogins(self.account) < 3:
Expand Down
55 changes: 0 additions & 55 deletions src/NotificationManager.py

This file was deleted.

5 changes: 1 addition & 4 deletions src/Stats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from datetime import datetime
from NotificationManager import NotificationManager

class Stats:
def __init__(self, farmThreads, notificationManager: NotificationManager) -> None:
def __init__(self, farmThreads) -> None:
self.farmThreads = farmThreads
self.accountData = {}
self.notificationManager = notificationManager

def initNewAccount(self, accountName: str):
self.accountData[accountName] = {
Expand All @@ -22,7 +20,6 @@ def update(self, accountName: str, newDrops: int = 0, liveMatches: str = "", las
self.accountData[accountName]["lastCheck"] = datetime.now().strftime("%H:%M:%S %d/%m")
self.accountData[accountName]["liveMatches"] = liveMatches
if newDrops > 0:
self.notificationManager.makeNotificationDrop((accountName),"{} New Drop(s) received".format(newDrops))
self.accountData[accountName]["totalDrops"] += newDrops
if lastDropleague:
self.accountData[accountName]["lastDrop"] = datetime.now().strftime("%H:%M:%S %d/%m") + f' ({lastDropleague})'
Expand Down
Binary file removed src/assets/defaultNotificationSound.wav
Binary file not shown.
Binary file removed src/assets/poro.ico
Binary file not shown.
7 changes: 3 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from Stats import Stats
from VersionManager import VersionManager
from NotificationManager import NotificationManager

CURRENT_VERSION = 1.2

Expand Down Expand Up @@ -46,13 +45,13 @@ def init() -> tuple[logging.Logger, Config]:

return log, config


def main(log: logging.Logger, config: Config):
notificationManager = NotificationManager(config)
farmThreads = {}
refreshLock = Lock()
locks = {"refreshLock": refreshLock}
sharedData = SharedData()
stats = Stats(farmThreads, notificationManager)
stats = Stats(farmThreads)
for account in config.accounts:
stats.initNewAccount(account)
restarter = Restarter(stats)
Expand All @@ -70,7 +69,7 @@ def main(log: logging.Logger, config: Config):
for account in config.accounts:
if account not in farmThreads and restarter.canRestart(account):
log.info(f"Starting a thread for {account}.")
thread = FarmThread(log, config, account, stats, locks, notificationManager, sharedData)
thread = FarmThread(log, config, account, stats, locks, sharedData)
thread.daemon = True
thread.start()
farmThreads[account] = thread
Expand Down

0 comments on commit 7a7ddd7

Please sign in to comment.