Skip to content

Commit

Permalink
Merge pull request #4 from renatofmmaia/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
renatofmmaia authored Jan 26, 2022
2 parents 629d1b7 + 6b924e1 commit 8cee020
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 76 deletions.
Binary file added assets/images/targets/identify_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/targets/popup_erro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 25 additions & 8 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# DONT CHANGE THIS CONFIGS
threshold:
default: 0.7
hero_to_work: 0.9
# -------------------------

generals:
# Save all logs in file logs/logger.txt
# 0: Don't save log
# 1: Save log
save_log_file: 1

# Reset log file on start
# 0: false
# 1: true
reset_log_file: 1

# Which hotkey is used to refresh the browser
Expand All @@ -25,12 +23,19 @@ hero:
screen:
# Number of login attempts
number_login_attempts: 3

# Time to update hero positions on farm screen
refresh_hunt: 7

# Timer to check who needs to go back to work
refresh_heroes: 25
# Timer to force browser refresh

# Timer to force browser refresh, prevent indestructible blocks and other possibles errors
refresh_login: 60

# Timer to check popup screen errors, if it's in error, restarts with login again
refresh_check_error: 5

# Chest photo type, for sending via Telegram
# true: The entire screen where the browser tab will be
# false: Just chest screen with your coins
Expand All @@ -39,17 +44,29 @@ screen:
scroll_heroes:
# total number of times the screen scrolls down
repeat: 5

# distance when scrolling down
distance: -200

# duration of scrolling
duration: 1

# time waiting when scrolling down
wait: 1.5

telegram:
# Settings for telegram integration
token: ""
chat_id: 0

# Timer when your chest image is sent to telegram
refresh_print_chest: 60



# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# DONT CHANGE THIS CONFIGS
# ------------------------
threshold:
default: 0.7
hero_to_work: 0.9
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
26 changes: 21 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from packaging import version

from module.bombScreen import BombScreen, BombScreenEnum
from module.config import Config
from module.image import Image
from module.logger import logger, reset_log_file
Expand All @@ -31,26 +32,41 @@ def main(config_file):
data = r.json()

start_message = data["files"]["start_message"]["content"]
logger(start_message)
logger(start_message, color="cyan", datetime=False)

last_version = data["files"]["version"]["content"].strip()
version_installed = version.parse(__version__)
logger(f"Current version: {version_installed}", "blue")
logger(f"-> Current version: {version_installed}", color="cyan", datetime=False)

if version.parse(last_version) > version.parse(__version__):
logger(f"New version available: {last_version}.", "green")
logger("-----------------------------------------------", color="green", datetime=False)
logger(f"New version available: {last_version}.", color="green", datetime=False)
update_message = data["files"]["update_message"]["content"]
logger(update_message)
logger(update_message, color="green", datetime=False)
logger("-----------------------------------------------", color="green", datetime=False)
else:
logger("Unable to check for updates.")

bomb_crypto_managers = create_bombcrypto_managers()
logger(f"{len(bomb_crypto_managers)} Bombcrypto window (s) found")
bomb_browser_count = 1
show_initial_screen_message = True
while True:
try:
for manager in bomb_crypto_managers:
current_screen = BombScreen.get_current_screen()

if show_initial_screen_message:
logger(f"💫 Bombcrypto window[{bomb_browser_count}] inicializado em: {BombScreenEnum(current_screen).name}")

with manager:
manager.do_what_needs_to_be_done()
manager.do_what_needs_to_be_done(current_screen)

if bomb_browser_count == len(bomb_crypto_managers):
bomb_browser_count = 1
show_initial_screen_message = False
else:
bomb_browser_count += 1
except Exception as e:
logger(
traceback.format_exc(),
Expand Down
115 changes: 72 additions & 43 deletions module/bombScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BombScreenEnum(Enum):
HEROES = 2
TREASURE_HUNT = 3
CHEST = 4
POPUP_ERROR = 5
SETTINGS = 6


class BombScreen:
Expand All @@ -34,9 +36,11 @@ def check_screen():
res = do_with_timeout(
check_screen, time_beteween=time_beteween, timeout=timeout
)

if res is None:
raise Exception(f'Timeout waiting for screen {BombScreenEnum(bombScreenEnum).name}.')
return

return res

def wait_for_leave_screen(
bombScreenEnum, time_beteween: float = 0.5, timeout: float = 60
Expand All @@ -60,6 +64,8 @@ def get_current_screen(time_beteween: float = 0.5, timeout: float = 20):
BombScreenEnum.LOGIN.value: Image.TARGETS["identify_login"],
BombScreenEnum.TREASURE_HUNT.value: Image.TARGETS["identify_treasure_hunt"],
BombScreenEnum.CHEST.value: Image.TARGETS["identify_hunt_chest"],
BombScreenEnum.POPUP_ERROR.value: Image.TARGETS["popup_erro"],
BombScreenEnum.SETTINGS.value: Image.TARGETS["identify_settings"],
}
max_value = 0
img = Image.screen()
Expand Down Expand Up @@ -93,16 +99,23 @@ def go_to_home(manager):

def go_to_heroes(manager):
current_screen = BombScreen.get_current_screen()
if current_screen == BombScreenEnum.HEROES.value:

if current_screen == BombScreenEnum.HOME.value:
click_when_target_appears("button_heroes")
BombScreen.wait_for_screen(BombScreenEnum.HEROES.value)

elif current_screen == BombScreenEnum.HEROES.value:
return
elif current_screen == BombScreenEnum.CHEST.value:

elif current_screen == BombScreenEnum.CHEST.value or current_screen == BombScreenEnum.SETTINGS.value:
click_when_target_appears("buttun_x_close")
BombScreen.wait_for_leave_screen(BombScreenEnum.CHEST.value)
BombScreen.go_to_home(manager)
return BombScreen.go_to_heroes(manager)

else:
BombScreen.go_to_home(manager)
click_when_target_appears("button_heroes")
BombScreen.wait_for_screen(BombScreenEnum.HOME.value)
Login.do_login(manager)
BombScreen.go_to_heroes(manager)

def go_to_treasure_hunt(manager):
if BombScreen.get_current_screen() == BombScreenEnum.TREASURE_HUNT.value:
Expand Down Expand Up @@ -140,54 +153,58 @@ def do_print_chest(manager):
logger(str(e))
logger("😬 Ohh no! We couldn't send your farm report to Telegram.", color="yellow", force_log_file=True)

manager.set_print_chest_refreshed()
BombScreen.go_to_treasure_hunt(manager)
manager.set_refresh_timer("refresh_print_chest")



class Login:
def do_login(manager):
logger_translated("login", LoggerEnum.ACTION)

login_attepmts = Config.PROPERTIES["screen"]["number_login_attempts"]

current_screen = BombScreen.get_current_screen()
logged = False
for i in range(login_attepmts):
current_screen = BombScreen.get_current_screen()
logger(f"💫 Bot inicializado em: {BombScreenEnum(current_screen).name}")

if BombScreen.get_current_screen() != BombScreenEnum.LOGIN.value:
refresh_page()
BombScreen.wait_for_screen(BombScreenEnum.LOGIN.value)

logger_translated("Login", LoggerEnum.PAGE_FOUND)

logger_translated("wallet", LoggerEnum.BUTTON_CLICK)
if not click_when_target_appears("button_connect_wallet"):
refresh_page()
continue

logger_translated("sigin wallet", LoggerEnum.BUTTON_CLICK)
if not click_when_target_appears("button_connect_wallet_sign"):
refresh_page()
continue

if current_screen != BombScreenEnum.LOGIN.value and current_screen != BombScreenEnum.NOT_FOUND.value and current_screen != BombScreenEnum.POPUP_ERROR.value:
logged = True

if (BombScreen.wait_for_screen(BombScreenEnum.HOME.value)!= BombScreenEnum.HOME.value):
logger("🚫 Failed to login, restart proccess...")
continue
else:
logger("🎉 Login successfully!")
logged = True
break
if not logged:
logger_translated("login", LoggerEnum.ACTION)

manager.set_logged()
login_attepmts = Config.PROPERTIES["screen"]["number_login_attempts"]

for i in range(login_attepmts):

if BombScreen.get_current_screen() != BombScreenEnum.LOGIN.value:
refresh_page()
BombScreen.wait_for_screen(BombScreenEnum.LOGIN.value)

logger_translated("Login", LoggerEnum.PAGE_FOUND)

logger_translated("wallet", LoggerEnum.BUTTON_CLICK)
if not click_when_target_appears("button_connect_wallet"):
refresh_page()
continue

logger_translated("sigin wallet", LoggerEnum.BUTTON_CLICK)
if not click_when_target_appears("button_connect_wallet_sign"):
refresh_page()
continue

if (BombScreen.wait_for_screen(BombScreenEnum.HOME.value) != BombScreenEnum.HOME.value):
logger("🚫 Failed to login, restart proccess...")
continue
else:
logger("🎉 Login successfully!")
logged = True
break

manager.set_refresh_timer("refresh_login")
return logged


class Hero:
def who_needs_work(manager):
logger_translated(f"heroes to work(config: {Config.get('hero','work_mod')})", LoggerEnum.ACTION)

logger_translated(f"Heroes to work(config: {Config.get('hero','work_mod')}%)", LoggerEnum.ACTION)
heroes_bar = ["hero_bar_0", "hero_bar_20", "hero_bar_40", "hero_bar_60", "hero_bar_80", "hero_bar_100"]
scale_factor = 20

Expand Down Expand Up @@ -225,16 +242,28 @@ def click_available_heroes():
wait=Config.get('screen','scroll_heroes', 'wait'),
function_between=click_available_heroes
)

logger(f"🏃 {sum(n_clicks_per_scrool)} new heros sent to explode everything 💣💣💣.")
Hero.refresh_hunt(manager)
manager.set_heroes_refreshed()
manager.set_refresh_timer("refresh_heroes")
return True

def refresh_hunt(manager):
logger_translated("huting positions", LoggerEnum.TIMER_REFRESH)
logger_translated("hunting positions", LoggerEnum.TIMER_REFRESH)

BombScreen.go_to_home(manager)
BombScreen.go_to_treasure_hunt(manager)

manager.set_positions_refreshed()
manager.set_refresh_timer("refresh_hunt")
return True

def do_check_error(manager):
current_screen = BombScreen.get_current_screen()

if current_screen == BombScreenEnum.POPUP_ERROR.value or current_screen == BombScreenEnum.NOT_FOUND.value:
logger_translated("Check screen error found, restarting...", LoggerEnum.ERROR)
Login.do_login(manager)
BombScreen.go_to_heroes(manager)
BombScreen.go_to_treasure_hunt(manager)

manager.set_refresh_timer("refresh_check_error")
14 changes: 11 additions & 3 deletions module/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LoggerEnum(Enum):
BUTTON_CLICK = 1
PAGE_FOUND = 2
TIMER_REFRESH = 3
ERROR = 4


COLOR = {
Expand All @@ -24,14 +25,19 @@ class LoggerEnum(Enum):
}


def logger(message, color="default", force_log_file=False, terminal=True):
def logger(message, color="default", force_log_file=False, terminal=True, datetime=True):
color_formatted = COLOR.get(color.lower(), COLOR["default"])
formatted_datetime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
formatted_message = "[{}] => {}".format(formatted_datetime, message)

if datetime:
formatted_message = "[{}] => {}".format(formatted_datetime, message)
else:
formatted_message = message

formatted_message_colored = color_formatted + formatted_message + "\033[0m"

if terminal:
sys.stdout.write(color_formatted + ".")
sys.stdout.write(color_formatted)
sys.stdout.flush()
print(formatted_message_colored)

Expand All @@ -48,6 +54,8 @@ def logger_translated(text: str, loggerEnum: LoggerEnum):
logger(f"🚩 {text} page detected.")
elif loggerEnum.value == LoggerEnum.TIMER_REFRESH.value:
logger(f"🍺 Refresh {text}.")
elif loggerEnum.value == LoggerEnum.ERROR.value:
logger(f"🆘 {text}.")

def reset_log_file():
file = open("./logs/logger.log","w")
Expand Down
Loading

0 comments on commit 8cee020

Please sign in to comment.