Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Menu Fix, Old GUI, Exit Fix #472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
457 changes: 230 additions & 227 deletions src/poetry.lock

Large diffs are not rendered by default.

81 changes: 52 additions & 29 deletions src/pyclashbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from pyclashbot.interface import disable_keys, user_config_keys
from pyclashbot.interface.joblist import no_jobs_popup
from pyclashbot.interface.layout import create_window
from pyclashbot.memu.memu_closer import close_everything_memu
from pyclashbot.memu.launcher import reset_clashbot_emulator
from pyclashbot.memu.memu_closer import close_memuc_processes
from pyclashbot.utils.caching import USER_SETTINGS_CACHE
from pyclashbot.utils.cli_config import arg_parser
from pyclashbot.utils.logger import Logger, initalize_pylogging
Expand All @@ -22,14 +23,8 @@
initalize_pylogging()


TODO = """
-fix donate image rec (its slow and stupid)
"""


def read_window(
window: sg.Window,
timeout: int = 10,
window: sg.Window, timeout: int = 10,
) -> tuple[str, dict[str, str | int]]:
"""Method for reading the attributes of the window
args:
Expand Down Expand Up @@ -74,6 +69,7 @@ def make_job_dictionary(values: dict[str, str | int]) -> dict[str, str | int]:
"donate_toggle": values["donate_toggle"],
"free_donate_toggle": values["free_donate_toggle"],
"card_mastery_user_toggle": values["card_mastery_user_toggle"],
"memu_attach_mode_toggle": values["memu_attach_mode_toggle"],
"free_offer_user_toggle": values["free_offer_user_toggle"],
"gold_offer_user_toggle": values["gold_offer_user_toggle"],
"trophy_road_1v1_battle_user_toggle": values["trophy_road_1v1_user_toggle"],
Expand All @@ -97,16 +93,46 @@ def make_job_dictionary(values: dict[str, str | int]) -> dict[str, str | int]:
"disable_win_track_toggle": values["disable_win_track_toggle"],
"level_up_chest_user_toggle": values["level_up_chest_user_toggle"],
"trophy_road_rewards_user_toggle": values["trophy_road_rewards_user_toggle"],
'magic_items_user_toggle':values['magic_items_user_toggle'],
# "upgrade_all_cards_user_toggle": values["upgrade_all_cards_user_toggle"],
"upgrade_all_cards_user_toggle": values["upgrade_all_cards_user_toggle"],
"season_shop_buys_user_toggle": values["season_shop_buys_user_toggle"],
# job increments
"trophy_road_reward_increment_user_input": values[
"trophy_road_reward_increment_user_input"
],
"season_shop_buys_increment_user_input": values[
"season_shop_buys_increment_user_input"
],
"card_upgrade_increment_user_input": values[
"card_upgrade_increment_user_input"
],
"shop_buy_increment_user_input": values["shop_buy_increment_user_input"],
"request_increment_user_input": values["request_increment_user_input"],
"donate_increment_user_input": values["donate_increment_user_input"],
"daily_reward_increment_user_input": values[
"daily_reward_increment_user_input"
],
"card_mastery_collect_increment_user_input": values[
"card_mastery_collect_increment_user_input"
],
"open_chests_increment_user_input": values["open_chests_increment_user_input"],
"deck_randomization_increment_user_input": values[
"deck_randomization_increment_user_input"
],
"war_attack_increment_user_input": values["war_attack_increment_user_input"],
"battlepass_collect_increment_user_input": values[
"battlepass_collect_increment_user_input"
],
"level_up_chest_increment_user_input": values[
"level_up_chest_increment_user_input"
],
# account switching input info
"account_switching_increment_user_input": values[
"account_switching_increment_user_input"
],
"account_switching_toggle": values["account_switching_toggle"],
"account_switch_count": int(values["account_switching_slider"]),
# memu settings
"memu_attach_mode_toggle": values["memu_attach_mode_toggle"],
"opengl_toggle": values["opengl_toggle"],
"directx_toggle": values["directx_toggle"],
"account_switching_slider": int(values["account_switching_slider"]),
"next_account": 0,
"random_account_switch_list": random_account_switch_list,
}

return jobs_dictionary
Expand Down Expand Up @@ -212,13 +238,8 @@ def load_settings(settings: None | dict[str, str], window: sg.Window) -> None:
if settings is not None:
for key in user_config_keys:
if key in settings:
if key in list(window.key_dict.keys()):
window[key].update(settings[key]) # type: ignore
else:
print(
f"This key {key} appears in saved settings, but not the active window."
)
window.refresh()
window[key].update(settings[key]) # type: ignore
window.refresh() # refresh the window to update the layout


def show_invalid_job_increment_input_popup(key) -> None:
Expand Down Expand Up @@ -288,6 +309,8 @@ def start_button_event(logger: Logger, window: Window, values) -> WorkerThread |
logger.log("No jobs are selected!")
return None

# updaet logger's update_account_order_var
logger.update_account_order_var(job_dictionary["random_account_switch_list"])

logger.log("Start Button Event")
logger.change_status(status="Starting the bot!")
Expand All @@ -296,12 +319,10 @@ def start_button_event(logger: Logger, window: Window, values) -> WorkerThread |
logger.log_job_dictionary(job_dictionary)

for key in disable_keys:
if key in list(window.key_dict.keys()):
window[key].update(disabled=True)
window[key].update(disabled=True)

# close existing memuc processes
print("Closing everything memu related...")
close_everything_memu()
close_memuc_processes()

# setup the main thread and start it
print("Starting main thread")
Expand Down Expand Up @@ -363,9 +384,7 @@ def exit_button_event(thread) -> None:


def handle_thread_finished(
window: sg.Window,
thread: WorkerThread | None,
logger: Logger,
window: sg.Window, thread: WorkerThread | None, logger: Logger,
):
"""Method for handling when the worker thread is finished"""
# enable the start button and configuration after the thread is stopped
Expand Down Expand Up @@ -437,6 +456,10 @@ def main_gui(start_on_run=False, settings: None | dict[str, str] = None) -> None
if url is not None:
webbrowser.open(url)

# refresh emulator button
elif event == "refresh_emualtor_key":
reset_clashbot_emulator(logger)

# on Help button event, open the help gui
elif event == "discord":
webbrowser.open("https://discord.gg/eXdVuHuaZv")
Expand Down
40 changes: 33 additions & 7 deletions src/pyclashbot/bot/account_switching.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,71 @@
from pyclashbot.utils.logger import Logger

SSID_COORDS = [
(48, 376), # 1st account, index 0
(48, 472), # 2nd account, index 1
(48, 567), # 3rd account, index 2
(48, 305), # 1st account, index 0
(48, 387), # 2nd account, index 1
(48, 471), # 3rd account, index 2
(48, 553), # 4th account, index 3
(48, 631), # 5th account, index 4
(48, 631), # 6th account, index 5
(48, 631), # 7th account, index 6
(48, 631), # 8th account, index 7
]


def switch_accounts(vm_index: int, logger: Logger, account_index_to_switch_to):
logger.add_switch_account_attempt()

# if not on clash main, return False
if check_if_on_clash_main_menu(vm_index) is not True:
logger.change_status("293587 Not on clash main to do account switching")
return False

# click options burger
logger.log("Opening clash main options menu")
logger.change_status("Opening clash main options menu")
click(vm_index, 386, 66)
time.sleep(3)

# click switch SSID button
logger.log("Clicking switch SSID button")
logger.change_status("Clicking switch SSID button")
click(vm_index, 221, 368)
time.sleep(4)

# wait for switch ssid page
# wait_for_switch_ssid_page(vm_index, logger)
# time.sleep(10)

# Perform the scrolling
if account_index_to_switch_to in [5, 6, 7]:
logger.change_status(
f"Scrolling down to reach account #{account_index_to_switch_to}",
)
if account_index_to_switch_to == 5: # 6th account
custom_swipe(vm_index, 215, 400, 215, 350, 2, 1)
elif account_index_to_switch_to == 6: # 7th account
custom_swipe(vm_index, 215, 400, 215, 350, 4, 1)
elif account_index_to_switch_to == 7: # 8th account
custom_swipe(vm_index, 215, 400, 215, 350, 6, 1)

# click the account index in question
account_coord = SSID_COORDS[account_index_to_switch_to]
logger.log(f"Clicking account index #{account_index_to_switch_to}")
logger.change_status(f"Clicking account index #{account_index_to_switch_to}")
click(vm_index, account_coord[0], account_coord[1], clicks=3, interval=0.33)
logger.change_status(f"Selected account #{account_index_to_switch_to}")

time.sleep(6)

#wait for main page
logger.change_status("Waiting for clash main on new account...")
if wait_for_clash_main_menu(vm_index, logger) is False:
return False
time.sleep(4)

if check_for_trophy_reward_menu(vm_index):
handle_trophy_reward_menu(vm_index, logger, printmode=False)
time.sleep(2)

logger.change_status(f"Switched to account #{account_index_to_switch_to}")
# Reset logger's in_a_clan value
logger.update_in_a_clan_value(False)
logger.increment_account_switches()
return True

Expand Down
8 changes: 3 additions & 5 deletions src/pyclashbot/bot/bannerbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
BANNERBOX_ICON_ON_CLASH_MAIN_PAGE = (350, 195)
FIRST_100_TICKETS_PURCHASE_BUTTON = (303, 576)
SECOND_100_TICKETS_PURCHASE_BUTTON = (209, 466)
CLASH_MAIN_DEADSPACE_COORD = (20, 520)


def check_if_bannerbox_icon_have_a_star(vm_index):
Expand All @@ -26,7 +25,7 @@ def check_if_bannerbox_icon_have_a_star(vm_index):
]

for i, p in enumerate(pixels):

# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False

Expand Down Expand Up @@ -121,13 +120,12 @@ def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool:
return False

# click deadspace
click(vm_index, CLASH_MAIN_DEADSPACE_COORD[0], CLASH_MAIN_DEADSPACE_COORD[1], clicks=5, interval=0.33)
click(vm_index, 10, 450, clicks=5, interval=0.33)

# return true if everything went well
return True



def check_for_collected_all_bannerbox_rewards_icon(vm_index):
iar = numpy.asarray(screenshot(vm_index))

Expand Down Expand Up @@ -173,7 +171,7 @@ def check_if_bannerbox_icon_exists_on_clashmain(vm_index):
]

for i, p in enumerate(pixels):

# print(p)
if not pixel_is_equal(p, colors[i], tol=35):
return True

Expand Down
29 changes: 8 additions & 21 deletions src/pyclashbot/bot/battlepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def check_for_battlepass_reward_icon(vm_index):
]

for i, p in enumerate(pixels):

# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False

Expand All @@ -83,7 +83,7 @@ def check_if_on_battlepass_page(vm_index):
]

for i, p in enumerate(pixels):

# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False

Expand Down Expand Up @@ -135,8 +135,7 @@ def collect_1_battlepass_reward(vm_index, logger):
start_time = time.time()
while time.time() - start_time < timeout:
claim_rewards_coord = find_claim_battlepass_rewards_button_with_delay(
vm_index,
delay=3,
vm_index, delay=3,
)

if claim_rewards_coord is None:
Expand All @@ -155,32 +154,20 @@ def collect_1_battlepass_reward(vm_index, logger):

# find the claim rewards button again
claim_rewards_coord = find_claim_battlepass_rewards_button_with_delay(
vm_index,
delay=3,
vm_index, delay=3,
)

if claim_rewards_coord is None:
logger.change_status(
"""This part needs attention. This logic was written forever ago
and I cant tell if claim_rewards_coord is supposed to be None at
this point, because it CAN be. Should it return False here? Or
should it continue and try again? Can't tell. Returning False for
safety."""
)
return False

# claim the reward
logger.change_status('Clicking "Claim Rewards" button')
click(vm_index, claim_rewards_coord[0], claim_rewards_coord[1],clicks = 3,interval = 0.5)
click(vm_index, claim_rewards_coord[0], claim_rewards_coord[1])
time.sleep(3)

# click deadspace until back to battlepass page + a little extra ;)
# click deadspace until back to battlepass page
logger.log("Skipping thru this battlepass reward")
while not check_if_on_battlepass_page(vm_index):
logger.log("Skipping thru this battlepass reward")
if random.randint(1, 5):
logger.log("Skipping thru this battlepass reward")
click(vm_index, 404, 33)
click(vm_index, 404, 33,clicks = 5,interval = 0.5)


logger.log("Collected 1 battlepass reward")
logger.increment_battlepass_collects()
Expand Down
16 changes: 8 additions & 8 deletions src/pyclashbot/bot/buy_shop_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from pyclashbot.memu.client import (
click,
screenshot,scroll_up_in_shop_page,
screenshot,
scroll_down_slowly_in_shop_page,
)
from pyclashbot.utils.logger import Logger
Expand All @@ -34,6 +34,7 @@ def buy_shop_offers_state(
print(f"gold_buy_toggle: {gold_buy_toggle}")
print(f"free_offers_toggle: {free_offers_toggle}")

logger.add_shop_buy_attempt()

# if not on clash main, return False
if check_if_on_clash_main_menu(vm_index) is not True:
Expand Down Expand Up @@ -76,11 +77,10 @@ def buy_shop_offers_main(
logger.change_status("Failed to get to shop page to buy offers")
return False

#scroll all the way to the top
scroll_up_in_shop_page(vm_index)

# scroll incrementally while searching for rewards, clicking and buying any rewards found

purchase_total = 0

start_time = time.time()
done_buying = False
logger.change_status("Starting to buy offers")
Expand Down Expand Up @@ -169,7 +169,7 @@ def search_for_gold_purchases(vm_index):


def buy_offers_from_this_shop_page(
vm_index, logger:Logger, gold_buy_toggle, free_offers_toggle,
vm_index, logger, gold_buy_toggle, free_offers_toggle,
):
coord = None

Expand Down Expand Up @@ -216,15 +216,15 @@ def check_if_on_shop_page(vm_index):
]

for i, p in enumerate(pixels):

# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False
return True


def shop_buy_tester():
vm_index = 1
logger = Logger(None, False)
vm_index = 12
logger = Logger(None, None)
gold_buy_toggle = True
free_offers_toggle = True

Expand Down
Loading