From 1c5b8a29172fad6d3765a5207c682a6ffd0202a6 Mon Sep 17 00:00:00 2001 From: Martin Miglio Date: Sat, 26 Nov 2022 20:52:14 -0500 Subject: [PATCH] run pre-commit --- .../bot/battlepass_rewards_collection.py | 33 ++--- pyclashbot/bot/free_offer_collection.py | 124 ++++++++++-------- pyclashbot/bot/level_up_reward_collection.py | 43 +++--- pyclashbot/bot/request.py | 2 - pyclashbot/bot/war.py | 7 +- pyclashbot/interface/dummy.py | 1 - pyclashbot/interface/stats.py | 1 - pyclashbot/interface/tab_demo.py | 5 +- pyclashbot/utils/logger.py | 5 +- 9 files changed, 113 insertions(+), 108 deletions(-) diff --git a/pyclashbot/bot/battlepass_rewards_collection.py b/pyclashbot/bot/battlepass_rewards_collection.py index 01f82dea7..05f78b631 100644 --- a/pyclashbot/bot/battlepass_rewards_collection.py +++ b/pyclashbot/bot/battlepass_rewards_collection.py @@ -2,8 +2,8 @@ import numpy from ahk import AHK -from pyclashbot.bot.clashmain import check_if_on_clash_main_menu +from pyclashbot.bot.clashmain import check_if_on_clash_main_menu from pyclashbot.detection import pixel_is_equal from pyclashbot.memu import click, screenshot @@ -38,11 +38,12 @@ def check_if_has_battlepass_rewards(): def collect_battlepass_rewards(logger): logger.change_status("Collecting battlepass rewards.") - - #should be on clash main at this point - if not check_if_on_clash_main_menu():return "restart" - - #declare locations of reward coords + + # should be on clash main at this point + if not check_if_on_clash_main_menu(): + return "restart" + + # declare locations of reward coords chest_locations = [ [300, 280], [300, 340], @@ -52,10 +53,10 @@ def collect_battlepass_rewards(logger): [300, 540], ] - #loop until the battlepass rewards icon on the main menu indicates there are no more rewards + # loop until the battlepass rewards icon on the main menu indicates there are no more rewards loops = 0 while check_if_has_battlepass_rewards(): - #if too many loops + # if too many loops if loops > 15: logger.change_status("looped through collect battlepass too many times.") return "restart" @@ -67,25 +68,25 @@ def collect_battlepass_rewards(logger): # click every chest locations in the chest_locations list for coord in chest_locations: - click(coord[0], coord[1],duration=0.1) + click(coord[0], coord[1], duration=0.1) time.sleep(0.33) # click deadspace for _ in range(15): - click(20, 440,duration=0.1) + click(20, 440, duration=0.1) time.sleep(0.1) # close battlepass to reset UI and return to clash main click(210, 630) time.sleep(1) - #increment the battlepass reward collection counter + # increment the battlepass reward collection counter logger.add_battlepass_reward_collection() logger.change_status("Done collecting battlepass rewards.") - - #should be on clash main at this point - if not check_if_on_clash_main_menu():return "restart" - else: return "clashmain" - + # should be on clash main at this point + if not check_if_on_clash_main_menu(): + return "restart" + else: + return "clashmain" diff --git a/pyclashbot/bot/free_offer_collection.py b/pyclashbot/bot/free_offer_collection.py index 89973238e..06dbc92c0 100644 --- a/pyclashbot/bot/free_offer_collection.py +++ b/pyclashbot/bot/free_offer_collection.py @@ -1,51 +1,69 @@ import time + import numpy -from pyclashbot.bot.clashmain import check_if_on_clash_main_menu -from pyclashbot.detection.image_rec import find_references, get_first_location, pixel_is_equal -from pyclashbot.memu.client import click, get_file_count, make_reference_image_list, print_pix_list, screenshot, scroll_down_super_fast +from pyclashbot.bot.clashmain import check_if_on_clash_main_menu +from pyclashbot.detection.image_rec import ( + find_references, + get_first_location, + pixel_is_equal, +) +from pyclashbot.memu.client import ( + click, + get_file_count, + make_reference_image_list, + print_pix_list, + screenshot, + scroll_down_super_fast, +) def collect_free_offer_from_shop(logger): logger.change_status("Collecting free offer from shop.") - if not check_if_on_clash_main_menu():return"restart" + if not check_if_on_clash_main_menu(): + return "restart" - #get to shop + # get to shop get_to_shop_page_from_main(logger) - #scroll a few times, each time looking for the free offer + # scroll a few times, each time looking for the free offer logger.change_status("Looking for free offer") - free_offer_coords=None - loops=0 + free_offer_coords = None + loops = 0 while free_offer_coords is None: scroll_down_super_fast() time.sleep(2) - free_offer_coords=find_free_offer_icon() + free_offer_coords = find_free_offer_icon() + + loops += 1 + if loops > 10: + break - loops+=1 - if loops>10:break - if free_offer_coords is None: logger.change_status("Failed to find free offer icon.") - #get to clash main from shop - if get_to_clash_main_from_shop(logger)=="restart":return "restart" - else: return + # get to clash main from shop + if get_to_clash_main_from_shop(logger) == "restart": + return "restart" + else: + return - #click free offer + # click free offer logger.change_status("Found free offer icon. Collecting it.") - click(free_offer_coords[0],free_offer_coords[1]) + click(free_offer_coords[0], free_offer_coords[1]) time.sleep(2) - click(200,425) + click(200, 425) logger.add_free_offer_collection() - #click deadspace + # click deadspace for _ in range(4): - click(18,379) + click(18, 379) + + # get to clash main from shop + if get_to_clash_main_from_shop(logger) == "restart": + return "restart" - #get to clash main from shop - if get_to_clash_main_from_shop(logger)=="restart":return "restart" def find_free_offer_icon(): current_image = screenshot() @@ -70,15 +88,16 @@ def find_free_offer_icon(): def get_to_clash_main_from_shop(logger): logger.change_status("Getting to clash main from shop.") - #click main - click(240,630) + # click main + click(240, 630) time.sleep(2) - loops=0 + loops = 0 while not check_if_on_clash_main_menu(): - loops+=1 - if loops>20:return"restart" - click(200,620) + loops += 1 + if loops > 20: + return "restart" + click(200, 620) time.sleep(2) logger.change_status("Made it to clash main from shop.") @@ -87,16 +106,18 @@ def get_to_clash_main_from_shop(logger): def get_to_shop_page_from_main(logger): logger.change_status("Getting to shop from main.") - #check if on main + # check if on main if not check_if_on_clash_main_menu(): - logger.change_status("Not on clash main so cant start collect free offer stuff.") + logger.change_status( + "Not on clash main so cant start collect free offer stuff." + ) return "restart" - #click shop icon - click(35,636) + # click shop icon + click(35, 636) time.sleep(1) - #check if on shop + # check if on shop if not check_if_on_shop_page_with_delay(): logger.change_status("Failed to get to shop page.") return "restart" @@ -105,43 +126,34 @@ def get_to_shop_page_from_main(logger): def check_if_on_shop_page(): - iar=numpy.asarray(screenshot()) - - pix_list=[ + iar = numpy.asarray(screenshot()) + + pix_list = [ iar[624][71], iar[636][55], iar[623][85], iar[625][71], ] - color_list=[ - [103,234,56], - [56,85,101], - [247,194,75], - [103,236,56], - + color_list = [ + [103, 234, 56], + [56, 85, 101], + [247, 194, 75], + [103, 236, 56], ] for n in range(4): - this_pixel=pix_list[n] - this_color=color_list[n] - if not pixel_is_equal(this_pixel,this_color,tol=35): + this_pixel = pix_list[n] + this_color = color_list[n] + if not pixel_is_equal(this_pixel, this_color, tol=35): return False return True - + def check_if_on_shop_page_with_delay(): - start_time=time.time() - while time.time()-start_time<3: + start_time = time.time() + while time.time() - start_time < 3: print("looping thru") if check_if_on_shop_page(): print("made it") return True time.sleep(0.5) return False - - - - - - - - diff --git a/pyclashbot/bot/level_up_reward_collection.py b/pyclashbot/bot/level_up_reward_collection.py index c0f728712..ba72b340a 100644 --- a/pyclashbot/bot/level_up_reward_collection.py +++ b/pyclashbot/bot/level_up_reward_collection.py @@ -61,43 +61,40 @@ def collect_level_up_rewards(logger): # starts and ends on clash main logger.change_status("Collecting level up rewards.") loops = 0 - - #should be on clash main at this point - if not check_if_on_clash_main_menu():return "restart" - #loop until the level up rewards icon on the main menu indicates there are no more rewards + # should be on clash main at this point + if not check_if_on_clash_main_menu(): + return "restart" + + # loop until the level up rewards icon on the main menu indicates there are no more rewards while check_if_has_level_up_rewards(): - #loop counter + # loop counter loops += 1 - if loops>20: - return"restart" + if loops > 20: + return "restart" - #click logo in top left + # click logo in top left click(17, 48) time.sleep(1) - - #click chest + + # click chest click(135, 160) time.sleep(1) - - #click dead space to skip through rewards + + # click dead space to skip through rewards for _ in range(20): click(20, 450) time.sleep(0.33) - - #increment counter + + # increment counter logger.add_level_up_chest_collection() - #should be on clash main at this point, if not click deadspace a little, then check again. + # should be on clash main at this point, if not click deadspace a little, then check again. if not check_if_on_clash_main_menu(): - #try to get to main by clicking deadspace more + # try to get to main by clicking deadspace more for _ in range(20): click(20, 450) time.sleep(0.33) - #if this didnt help getting to main then return restart - if not check_if_on_clash_main_menu():return"restart" - - - - - + # if this didnt help getting to main then return restart + if not check_if_on_clash_main_menu(): + return "restart" diff --git a/pyclashbot/bot/request.py b/pyclashbot/bot/request.py index f318013f2..d3e1d1177 100644 --- a/pyclashbot/bot/request.py +++ b/pyclashbot/bot/request.py @@ -76,8 +76,6 @@ def request_random_card_from_clash_main(logger): return None - - def request_random_card(logger, maximum_scrolls=10): # method to request a random card # starts on the request screen (the one with a bunch of pictures of the cards) diff --git a/pyclashbot/bot/war.py b/pyclashbot/bot/war.py index 7d0f0dcc3..f1b485362 100644 --- a/pyclashbot/bot/war.py +++ b/pyclashbot/bot/war.py @@ -54,7 +54,9 @@ def handle_war_attacks(logger): # sometimes the player lacks the cards to make a complete deck at this point # if you STILL done have a deck, return to main if not check_if_has_a_deck_for_this_war_battle(): - logger.change_status("Fight not avialable yet/Not enough cards to complete deck. Skipping war attack this time.") + logger.change_status( + "Fight not avialable yet/Not enough cards to complete deck. Skipping war attack this time." + ) for _ in range(5): click(20, 440) get_to_clash_main_from_clan_page(logger) @@ -112,7 +114,8 @@ def fight_war_battle(logger): click(random.randint(70, 355), random.randint(320, 490)) time.sleep(1) - for n in range(15): logger.change_status("Manual wait for end battle..."+str(n)) + for n in range(15): + logger.change_status("Manual wait for end battle..." + str(n)) def make_a_random_deck_for_this_war_battle(): diff --git a/pyclashbot/interface/dummy.py b/pyclashbot/interface/dummy.py index c32418d35..f4a550ff6 100644 --- a/pyclashbot/interface/dummy.py +++ b/pyclashbot/interface/dummy.py @@ -83,7 +83,6 @@ statistics["war_battles_fought"] += 1 statistics["requests"] += 1 statistics["free_offer_collections"] += 1 - # update the statistics window["current_status"].update(statistics["current_status"]) # type: ignore diff --git a/pyclashbot/interface/stats.py b/pyclashbot/interface/stats.py index 8f7ba79a4..a33c0874b 100644 --- a/pyclashbot/interface/stats.py +++ b/pyclashbot/interface/stats.py @@ -116,7 +116,6 @@ def stat_box(stat_name: str, size=(5, 1)) -> sg.Text: [ sg.Text("Free Offer Collections: "), ], - ] collections_stats_values = [ diff --git a/pyclashbot/interface/tab_demo.py b/pyclashbot/interface/tab_demo.py index 170688c00..18e93c916 100644 --- a/pyclashbot/interface/tab_demo.py +++ b/pyclashbot/interface/tab_demo.py @@ -1,7 +1,6 @@ import PySimpleGUI as sg -from pyclashbot.interface.stats import ( - stat_box, -) + +from pyclashbot.interface.stats import stat_box from pyclashbot.interface.theme import THEME sg.theme(THEME) diff --git a/pyclashbot/utils/logger.py b/pyclashbot/utils/logger.py index a478ca132..13717ad97 100644 --- a/pyclashbot/utils/logger.py +++ b/pyclashbot/utils/logger.py @@ -63,7 +63,7 @@ def __init__( self.battlepass_rewards_collections = 0 self.level_up_chest_collections = 0 self.war_battles_fought = 0 - self.free_offer_collections=0 + self.free_offer_collections = 0 self.current_status = "Idle" # track errored logger @@ -246,12 +246,10 @@ def add_free_offer_collection(self): """add level up chest collection to log""" self.free_offer_collections += 1 - def add_battlepass_reward_collection(self): """add battlepass collection to log""" self.battlepass_rewards_collections += 1 - @_updates_log def error(self, message: str): """log error message @@ -262,7 +260,6 @@ def error(self, message: str): self.errored = True self.current_status = f"Error: {message}" - @_updates_log def add_level_up_chest_collection(self): """add level up chest collection to log"""