From 0c30a722546de0413a7846fe86c884daa4a5364c Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 4 Oct 2024 03:09:24 +0800 Subject: [PATCH 1/6] Upd: Add ALASBaseError. --- .../campaign_war_archives/campaign_base.py | 2 +- deploy/Windows/config.py | 3 +- deploy/config.py | 3 +- module/campaign/run.py | 2 +- module/coalition/ui.py | 6 ++-- module/combat/emotion.py | 2 +- module/config/config.py | 6 ++-- module/device/connection.py | 18 +++++------ module/device/connection_attr.py | 10 +++--- module/device/device.py | 8 ++--- module/device/method/adb.py | 2 +- module/device/method/ascreencap.py | 8 ++--- module/device/method/droidcast.py | 6 ++-- module/device/method/hermit.py | 10 +++--- module/device/method/ldopengl.py | 12 +++---- module/device/method/maatouch.py | 8 ++--- module/device/method/minitouch.py | 8 ++--- module/device/method/nemu_ipc.py | 18 +++++------ module/device/method/scrcpy/core.py | 6 ++-- module/device/method/scrcpy/scrcpy.py | 2 +- module/device/method/uiautomator_2.py | 4 +-- module/device/method/utils.py | 5 +-- module/device/method/wsa.py | 2 +- module/device/pkg_resources/__init__.py | 3 +- module/device/screenshot.py | 4 +-- module/event/campaign_abcd.py | 2 +- module/exception.py | 32 +++++++++++-------- module/handler/login.py | 2 +- module/map/map_fleet_preparation.py | 2 +- module/map/map_operation.py | 6 ++-- module/ocr/al_ocr.py | 2 +- module/os/globe_operation.py | 5 +-- module/os/map.py | 2 +- module/os/operation_siren.py | 2 +- module/os_ash/ash.py | 3 +- module/os_combat/combat.py | 3 +- module/os_handler/action_point.py | 3 +- module/os_handler/mission.py | 3 +- module/raid/raid.py | 4 +-- module/retire/retirement.py | 4 +-- module/statistics/utils.py | 3 +- module/storage/storage.py | 4 +-- module/ui/ui.py | 4 +-- module/webui/remote_access.py | 3 +- submodule/AlasMaaBridge/maa.py | 8 ++--- .../AlasMaaBridge/module/handler/handler.py | 16 +++++----- 46 files changed, 143 insertions(+), 128 deletions(-) diff --git a/campaign/campaign_war_archives/campaign_base.py b/campaign/campaign_war_archives/campaign_base.py index 26cdf43d5c..fdfece1d71 100644 --- a/campaign/campaign_war_archives/campaign_base.py +++ b/campaign/campaign_war_archives/campaign_base.py @@ -110,7 +110,7 @@ def ui_goto_archives_campaign(self, mode='ex'): else: logger.critical('Respective server may not yet support the chosen War Archives campaign, ' 'check back in the next app update') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Subsequent runs all set False if self.first_run: diff --git a/deploy/Windows/config.py b/deploy/Windows/config.py index 5c10ab0a8e..dc72e057d8 100644 --- a/deploy/Windows/config.py +++ b/deploy/Windows/config.py @@ -6,9 +6,10 @@ from deploy.Windows.logger import logger from deploy.Windows.utils import DEPLOY_CONFIG, DEPLOY_TEMPLATE, cached_property, poor_yaml_read, poor_yaml_write +from module.exception import ALASBaseError -class ExecutionError(Exception): +class ExecutionError(ALASBaseError): pass diff --git a/deploy/config.py b/deploy/config.py index 528a160780..6c4aec5b66 100644 --- a/deploy/config.py +++ b/deploy/config.py @@ -3,9 +3,10 @@ from deploy.logger import logger from deploy.utils import * +from module.exception import ALASBaseError -class ExecutionError(Exception): +class ExecutionError(ALASBaseError): pass diff --git a/module/campaign/run.py b/module/campaign/run.py index 0c3dca1316..14e660a265 100644 --- a/module/campaign/run.py +++ b/module/campaign/run.py @@ -59,7 +59,7 @@ def load_campaign(self, name, folder='campaign_main'): logger.critical(f'Possible reason #1: This event ({folder}) does not have {name}') logger.critical(f'Possible reason #2: You are using an old Alas, ' 'please check for update, or make map files yourself using dev_tools/map_extractor.py') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') config = copy.deepcopy(self.config).merge(self.module.Config()) device = self.device diff --git a/module/coalition/ui.py b/module/coalition/ui.py index 7fd2ee01a4..aa82514559 100644 --- a/module/coalition/ui.py +++ b/module/coalition/ui.py @@ -196,7 +196,7 @@ def enter_map(self, event, stage, mode, skip_first_screenshot=True): if campaign_click > 5: logger.critical(f"Failed to enter {button}, too many click on {button}") logger.critical("Possible reason #1: You haven't cleared previous stage to unlock the stage.") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if fleet_click > 5: logger.critical(f"Failed to enter {button}, too many click on FLEET_PREPARATION") logger.critical("Possible reason #1: " @@ -204,11 +204,11 @@ def enter_map(self, event, stage, mode, skip_first_screenshot=True): logger.critical("Possible reason #2: " "This stage can only be farmed once a day, " "but it's the second time that you are entering") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.appear(FLEET_NOT_PREPARED, offset=(20, 20)): logger.critical('FLEET_NOT_PREPARED') logger.critical('Please prepare you fleets before running coalition battles') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # End if self.appear(BATTLE_PREPARATION, offset=(20, 20)): diff --git a/module/combat/emotion.py b/module/combat/emotion.py index 325cb56d01..039e5b5c1e 100644 --- a/module/combat/emotion.py +++ b/module/combat/emotion.py @@ -132,7 +132,7 @@ def get_recovered(self, expected_reduce=0): logger.critical(f'Fleet {self.fleet} Emotion Control=\"Keep Happy Bonus\" and ' f'Fleet {self.fleet} Recover Location=\"Docks\" can not be used together, ' 'please check your emotion settings') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # In 14-4 with 2X book, expected emotion reduce is 32, can't keep happy bonus (>120), # otherwise will infinite task delay if self.control == 'keep_exp_bonus' and expected_reduce >= 29: diff --git a/module/config/config.py b/module/config/config.py index f57aa0be02..c3259da9df 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -11,12 +11,12 @@ from module.config.config_updater import ConfigUpdater from module.config.watcher import ConfigWatcher from module.config.utils import * -from module.exception import RequestHumanTakeover, ScriptError +from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError from module.logger import logger from module.map.map_grids import SelectedGrids -class TaskEnd(Exception): +class TaskEnd(ALASBaseError): pass @@ -257,7 +257,7 @@ def get_next(self): else: logger.critical("No task waiting or pending") logger.critical("Please enable at least one task") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def save(self, mod_name='alas'): if not self.modified: diff --git a/module/device/connection.py b/module/device/connection.py index 6610000d4c..4772200824 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -71,7 +71,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -174,7 +174,7 @@ def adb_command(self, cmd, timeout=10): f'Trying to execute {cmd}, ' f'but adb_command() is not available when connecting over http: {self.serial}, ' ) - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def adb_start_server(self): """ @@ -345,7 +345,7 @@ def check_mumu_app_keep_alive(self): elif res == 'true': # https://mumu.163.com/help/20230802/35047_1102450.html logger.critical('请在MuMu模拟器设置内关闭 "后台挂机时保活运行"') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') else: logger.warning(f'Invalid nemud.app_keep_alive value: {res}') return False @@ -482,7 +482,7 @@ def nc_command(self): return command logger.error('No `netcat` command available, please use screenshot methods without `_nc` suffix') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def adb_shell_nc(self, cmd, timeout=5, chunk_size=262144): """ @@ -686,7 +686,7 @@ def adb_connect(self): # bad port number '598265' in '127.0.0.1:598265' elif 'bad port' in msg: possible_reasons('Serial incorrect, might be a typo') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # cannot connect to 127.0.0.1:55555: # No connection could be made because the target machine actively refused it. (10061) elif '(10061)' in msg: @@ -957,7 +957,7 @@ def brute_force_connect(): if available.count == 0: logger.critical('No available device found, auto device detection cannot work, ' 'please set an exact serial in Alas.Emulator.Serial instead of using "auto"') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') elif available.count == 1: logger.info(f'Auto device detection found only one device, using it') self.config.Emulator_Serial = self.serial = available[0].serial @@ -974,7 +974,7 @@ def brute_force_connect(): else: logger.critical('Multiple devices found, auto device detection cannot decide which to choose, ' 'please copy one of the available devices listed above to Alas.Emulator.Serial') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Handle LDPlayer # LDPlayer serial jumps between `127.0.0.1:5555+{X}` and `emulator-5554+{X}` @@ -1113,7 +1113,7 @@ def detect_package(self, set_config=True): if len(packages) == 0: logger.critical(f'No AzurLane package found, ' f'please confirm AzurLane has been installed on device "{self.serial}"') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if len(packages) == 1: logger.info('Auto package detection found only one package, using it') self.package = packages[0] @@ -1127,4 +1127,4 @@ def detect_package(self, set_config=True): logger.critical( f'Multiple AzurLane packages found, auto package detection cannot decide which to choose, ' 'please copy one of the available devices listed above to Alas.Emulator.PackageName') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') diff --git a/module/device/connection_attr.py b/module/device/connection_attr.py index 0814b95248..88eae9e588 100644 --- a/module/device/connection_attr.py +++ b/module/device/connection_attr.py @@ -113,7 +113,7 @@ def serial_check(self): if "127.0.0.1:58526" in self.serial: logger.warning('Serial 127.0.0.1:58526 seems to be WSA, ' 'please use "wsa-0" or others instead') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.is_wsa: self.serial = '127.0.0.1:58526' if self.config.Emulator_ScreenshotMethod != 'uiautomator2' \ @@ -129,7 +129,7 @@ def serial_check(self): f'ScreenshotMethod can only use ["ADB", "uiautomator2", "aScreenCap"], ' f'ControlMethod can only use ["ADB", "uiautomator2", "minitouch"]' ) - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') @cached_property def is_bluestacks4_hyperv(self): @@ -234,7 +234,7 @@ def find_bluestacks4_hyperv(serial): logger.error('Please confirm that your are using BlueStack 4 hyper-v and not regular BlueStacks 4') logger.error(r'Please check if there is any other emulator instances under ' r'registry HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_bgp64_hyperv\Guests') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') logger.info(f"New adb port: {port}") return f"127.0.0.1:{port}" @@ -270,7 +270,7 @@ def find_bluestacks5_hyperv(serial): logger.error('Unable to find registry HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_nxt ' 'or HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_nxt_cn') logger.error('Please confirm that you are using BlueStacks 5 hyper-v and not regular BlueStacks 5') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') logger.info(f"Configuration file directory: {directory}") with open(os.path.join(directory, 'bluestacks.conf'), encoding='utf-8') as f: @@ -278,7 +278,7 @@ def find_bluestacks5_hyperv(serial): port = re.search(rf'{parameter_name}="(\d+)"', content) if port is None: logger.warning(f"Did not match the result: {serial}.") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') port = port.group(2) logger.info(f"Match to dynamic port: {port}") return f"127.0.0.1:{port}" diff --git a/module/device/device.py b/module/device/device.py index 11a10172a3..b39d6f2673 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -77,7 +77,7 @@ def __init__(self, *args, **kwargs): except EmulatorNotRunningError: if trial >= 3: logger.critical('Failed to start emulator after 3 trial') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Try to start emulator if self.emulator_instance is not None: self.emulator_start() @@ -86,7 +86,7 @@ def __init__(self, *args, **kwargs): f'No emulator with serial "{self.config.Emulator_Serial}" found, ' f'please set a correct serial' ) - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Auto-fill emulator info if IS_WINDOWS and self.config.EmulatorInfo_Emulator == 'auto': @@ -311,7 +311,7 @@ def app_start(self): if not self.config.Error_HandleError: logger.critical('No app stop/start, because HandleError disabled') logger.critical('Please enable Alas.Error.HandleError or manually login to AzurLane') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') super().app_start() self.stuck_record_clear() self.click_record_clear() @@ -320,7 +320,7 @@ def app_stop(self): if not self.config.Error_HandleError: logger.critical('No app stop/start, because HandleError disabled') logger.critical('Please enable Alas.Error.HandleError or manually login to AzurLane') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') super().app_stop() self.stuck_record_clear() self.click_record_clear() diff --git a/module/device/method/adb.py b/module/device/method/adb.py index f699b7309f..4b78243d3f 100644 --- a/module/device/method/adb.py +++ b/module/device/method/adb.py @@ -70,7 +70,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper diff --git a/module/device/method/ascreencap.py b/module/device/method/ascreencap.py index 24ba9902c0..16a4ef0d0c 100644 --- a/module/device/method/ascreencap.py +++ b/module/device/method/ascreencap.py @@ -8,11 +8,11 @@ from module.device.connection import Connection from module.device.method.utils import (ImageTruncated, RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep) -from module.exception import RequestHumanTakeover, ScriptError +from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError from module.logger import logger -class AscreencapError(Exception): +class AscreencapError(ALASBaseError): pass @@ -70,7 +70,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -103,7 +103,7 @@ def ascreencap_init(self): self.ascreencap_available = False logger.error('No suitable version of aScreenCap lib available for this device, ' 'please use other screenshot methods instead') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') logger.info(f'pushing {filepath}') self.adb_push(filepath, self.config.ASCREENCAP_FILEPATH_REMOTE) diff --git a/module/device/method/droidcast.py b/module/device/method/droidcast.py index 43dad33cc0..1a9214d311 100644 --- a/module/device/method/droidcast.py +++ b/module/device/method/droidcast.py @@ -11,11 +11,11 @@ from module.device.method.uiautomator_2 import ProcessInfo, Uiautomator2 from module.device.method.utils import ( ImageTruncated, PackageNotInstalled, RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep) -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger -class DroidCastVersionIncompatible(Exception): +class DroidCastVersionIncompatible(ALASBaseError): pass @@ -87,7 +87,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper diff --git a/module/device/method/hermit.py b/module/device/method/hermit.py index 8b1da67abc..78e5a65fea 100644 --- a/module/device/method/hermit.py +++ b/module/device/method/hermit.py @@ -10,11 +10,11 @@ from module.device.method.adb import Adb from module.device.method.utils import (RETRY_TRIES, handle_unknown_host_service, retry_sleep, HierarchyButton, handle_adb_error) -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger -class HermitError(Exception): +class HermitError(ALASBaseError): pass @@ -83,7 +83,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -193,7 +193,7 @@ def appear_then_click(xpath): '2. Turn it ON and click OK\n' '3. Switch back to AzurLane\n' ) - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') @cached_property def hermit_session(self): @@ -222,7 +222,7 @@ def hermit_send(self, url, **kwargs): if 'GestureDescription$Builder' in result: logger.error(e) logger.critical('Hermit cannot run on current device, hermit requires Android>=7.0') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if 'accessibilityservice' in result: # Attempt to invoke virtual method # 'boolean android.accessibilityservice.AccessibilityService.dispatchGesture( diff --git a/module/device/method/ldopengl.py b/module/device/method/ldopengl.py index 4e46871730..a910a733d1 100644 --- a/module/device/method/ldopengl.py +++ b/module/device/method/ldopengl.py @@ -11,15 +11,15 @@ from module.base.decorator import cached_property from module.device.method.utils import RETRY_TRIES, get_serial_pair, retry_sleep from module.device.platform import Platform -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger -class LDOpenGLIncompatible(Exception): +class LDOpenGLIncompatible(ALASBaseError): pass -class LDOpenGLError(Exception): +class LDOpenGLError(ALASBaseError): pass @@ -169,7 +169,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -300,7 +300,7 @@ def ldopengl(self): # installation path is E:/ProgramFiles/LDPlayer9 if self.emulator_instance is None: logger.error('Unable to use LDOpenGL because emulator instance not found') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') try: return LDOpenGLImpl( ld_folder=self.emulator_instance.emulator.abspath('./'), @@ -309,7 +309,7 @@ def ldopengl(self): except (LDOpenGLIncompatible, LDOpenGLError) as e: logger.error(e) logger.error('Unable to initialize LDOpenGL') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def ldopengl_available(self) -> bool: if not self.is_ldplayer_bluestacks_family: diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index 5e135fe399..99ca2fb965 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -11,7 +11,7 @@ from module.device.connection import Connection from module.device.method.minitouch import Command, CommandBuilder, insert_swipe from module.device.method.utils import RETRY_TRIES, handle_adb_error, retry_sleep -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger @@ -92,7 +92,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -121,11 +121,11 @@ def end(self): self.device.sleep(self.DEFAULT_DELAY) -class MaaTouchNotInstalledError(Exception): +class MaaTouchNotInstalledError(ALASBaseError): pass -class MaaTouchSyncTimeout(Exception): +class MaaTouchSyncTimeout(ALASBaseError): pass diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index 732cc1bdd3..ad5933b22d 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -15,7 +15,7 @@ from module.base.utils import * from module.device.connection import Connection from module.device.method.utils import RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep -from module.exception import RequestHumanTakeover, ScriptError +from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError from module.logger import logger @@ -357,11 +357,11 @@ def _check_empty(self, text=None): return empty -class MinitouchNotInstalledError(Exception): +class MinitouchNotInstalledError(ALASBaseError): pass -class MinitouchOccupiedError(Exception): +class MinitouchOccupiedError(ALASBaseError): pass @@ -455,7 +455,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper diff --git a/module/device/method/nemu_ipc.py b/module/device/method/nemu_ipc.py index 86948783ab..ff13d5dd2f 100644 --- a/module/device/method/nemu_ipc.py +++ b/module/device/method/nemu_ipc.py @@ -15,15 +15,15 @@ from module.device.method.minitouch import insert_swipe, random_rectangle_point from module.device.method.utils import RETRY_TRIES, retry_sleep from module.device.platform import Platform -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger -class NemuIpcIncompatible(Exception): +class NemuIpcIncompatible(ALASBaseError): pass -class NemuIpcError(Exception): +class NemuIpcError(ALASBaseError): pass @@ -195,7 +195,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -471,7 +471,7 @@ def nemu_ipc(self) -> NemuIpcImpl: if self.config.EmulatorInfo_path: if 'MuMuPlayerGlobal' in self.config.EmulatorInfo_path: logger.info(f'nemu_ipc is not available on MuMuPlayerGlobal, {self.config.EmulatorInfo_path}') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') folder = os.path.abspath(os.path.join(self.config.EmulatorInfo_path, '../../')) index = NemuIpcImpl.serial_to_id(self.serial) if index is not None: @@ -490,10 +490,10 @@ def nemu_ipc(self) -> NemuIpcImpl: # installation path is E:\ProgramFiles\MuMuPlayer-12.0 if self.emulator_instance is None: logger.error('Unable to use NemuIpc because emulator instance not found') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if 'MuMuPlayerGlobal' in self.emulator_instance.path: logger.info(f'nemu_ipc is not available on MuMuPlayerGlobal, {self.emulator_instance.path}') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') try: return NemuIpcImpl( nemu_folder=self.emulator_instance.emulator.abspath('../'), @@ -503,7 +503,7 @@ def nemu_ipc(self) -> NemuIpcImpl: except (NemuIpcIncompatible, NemuIpcError) as e: logger.error(e) logger.error('Unable to initialize NemuIpc') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def nemu_ipc_available(self) -> bool: if not self.is_mumu_family: @@ -544,7 +544,7 @@ def check_mumu_app_keep_alive_400(file): if str(value).lower() == 'true': # https://mumu.163.com/help/20230802/35047_1102450.html logger.critical('请在MuMu模拟器设置内关闭 "后台挂机时保活运行"') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return True def check_mumu_app_keep_alive(self): diff --git a/module/device/method/scrcpy/core.py b/module/device/method/scrcpy/core.py index 499338b360..f50a760a10 100644 --- a/module/device/method/scrcpy/core.py +++ b/module/device/method/scrcpy/core.py @@ -14,11 +14,11 @@ from module.device.method.scrcpy.control import ControlSender from module.device.method.scrcpy.options import ScrcpyOptions from module.device.method.utils import AdbConnection, recv_all -from module.exception import RequestHumanTakeover +from module.exception import RequestHumanTakeover, ALASBaseError from module.logger import logger -class ScrcpyError(Exception): +class ScrcpyError(ALASBaseError): pass @@ -205,7 +205,7 @@ def _scrcpy_stream_loop(self) -> None: except ImportError as e: logger.error(e) logger.error('You must have `av` installed to use scrcpy screenshot, please update dependencies') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') codec = CodecContext.create("h264", "r") while self._scrcpy_alive: diff --git a/module/device/method/scrcpy/scrcpy.py b/module/device/method/scrcpy/scrcpy.py index d666a11ae6..9df48bd45e 100644 --- a/module/device/method/scrcpy/scrcpy.py +++ b/module/device/method/scrcpy/scrcpy.py @@ -76,7 +76,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper diff --git a/module/device/method/uiautomator_2.py b/module/device/method/uiautomator_2.py index d5d4e951dd..c3d0fd1080 100644 --- a/module/device/method/uiautomator_2.py +++ b/module/device/method/uiautomator_2.py @@ -94,7 +94,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper @@ -426,7 +426,7 @@ def resolution_check_uiautomator2(self): logger.critical(f'Resolution not supported: {width}x{height}') logger.critical('Please set emulator resolution to 1280x720') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') @retry def proc_list_uiautomator2(self) -> t.List[ProcessInfo]: diff --git a/module/device/method/utils.py b/module/device/method/utils.py index dc8e7ae3be..7421b14988 100644 --- a/module/device/method/utils.py +++ b/module/device/method/utils.py @@ -49,6 +49,7 @@ def shell(self, from module.base.decorator import cached_property from module.logger import logger +from module.exception import ALASBaseError RETRY_TRIES = 5 RETRY_DELAY = 3 @@ -143,11 +144,11 @@ def possible_reasons(*args): logger.critical(f'Possible reason #{index}: {reason}') -class PackageNotInstalled(Exception): +class PackageNotInstalled(ALASBaseError): pass -class ImageTruncated(Exception): +class ImageTruncated(ALASBaseError): pass diff --git a/module/device/method/wsa.py b/module/device/method/wsa.py index 6ae1c60281..b49aa97c92 100644 --- a/module/device/method/wsa.py +++ b/module/device/method/wsa.py @@ -58,7 +58,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return retry_wrapper diff --git a/module/device/pkg_resources/__init__.py b/module/device/pkg_resources/__init__.py index b685a6d9aa..5a9614a64b 100644 --- a/module/device/pkg_resources/__init__.py +++ b/module/device/pkg_resources/__init__.py @@ -4,6 +4,7 @@ from module.base.decorator import cached_property from module.logger import logger +from module.exception import ALASBaseError """ Importing pkg_resources is so slow, like 0.4 ~ 1.0s, just google it you will find it indeed really slow. @@ -105,5 +106,5 @@ def get_distribution(dist): ) -class DistributionNotFound(Exception): +class DistributionNotFound(ALASBaseError): pass diff --git a/module/device/screenshot.py b/module/device/screenshot.py index 9940ee0556..7b639dfab5 100644 --- a/module/device/screenshot.py +++ b/module/device/screenshot.py @@ -115,7 +115,7 @@ def screenshot_deque(self): length = int(self.config.Error_ScreenshotLength) except ValueError: logger.error(f'Error_ScreenshotLength={self.config.Error_ScreenshotLength} is not an integer') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Limit in 1~300 length = max(1, min(length, 300)) return deque(maxlen=length) @@ -238,7 +238,7 @@ def check_screen_size(self): else: logger.critical(f'Resolution not supported: {width}x{height}') logger.critical('Please set emulator resolution to 1280x720') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def check_screen_black(self): if self._screen_black_checked: diff --git a/module/event/campaign_abcd.py b/module/event/campaign_abcd.py index a01cdfb1c1..2bd52e2cfa 100644 --- a/module/event/campaign_abcd.py +++ b/module/event/campaign_abcd.py @@ -54,7 +54,7 @@ def run(self, *args, **kwargs): f'Cannot find stage "{stage}". ' f'Task "{task}" is for 3X daily PT, if you have not unlock {stage}, ' f'you should use task "Event" to unlock it instead of using task "{task}"') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') else: raise diff --git a/module/exception.py b/module/exception.py index cd35216489..8af73815dc 100644 --- a/module/exception.py +++ b/module/exception.py @@ -1,59 +1,63 @@ -class CampaignEnd(Exception): +class ALASBaseError(Exception): pass -class MapDetectionError(Exception): +class CampaignEnd(ALASBaseError): pass -class MapWalkError(Exception): +class MapDetectionError(ALASBaseError): pass -class MapEnemyMoved(Exception): +class MapWalkError(ALASBaseError): pass -class CampaignNameError(Exception): +class MapEnemyMoved(ALASBaseError): pass -class ScriptError(Exception): +class CampaignNameError(ALASBaseError): + pass + + +class ScriptError(ALASBaseError): # This is likely to be a mistake of developers, but sometimes a random issue pass -class ScriptEnd(Exception): +class ScriptEnd(ALASBaseError): pass -class GameStuckError(Exception): +class GameStuckError(ALASBaseError): pass -class GameBugError(Exception): +class GameBugError(ALASBaseError): # An error has occurred in Azur Lane game client. Alas is unable to handle. # A restart should fix it. pass -class GameTooManyClickError(Exception): +class GameTooManyClickError(ALASBaseError): pass -class EmulatorNotRunningError(Exception): +class EmulatorNotRunningError(ALASBaseError): pass -class GameNotRunningError(Exception): +class GameNotRunningError(ALASBaseError): pass -class GamePageUnknownError(Exception): +class GamePageUnknownError(ALASBaseError): pass -class RequestHumanTakeover(Exception): +class RequestHumanTakeover(ALASBaseError): # Request human takeover # Alas is unable to handle such error, probably because of wrong settings. pass diff --git a/module/handler/login.py b/module/handler/login.py index bb4b0ed1c1..41b6aa9f45 100644 --- a/module/handler/login.py +++ b/module/handler/login.py @@ -140,7 +140,7 @@ def handle_app_login(self): logger.critical('Login failed more than 3') logger.critical('Azur Lane server may be under maintenance, or you may lost network connection') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def app_stop(self): logger.hr('App stop') diff --git a/module/map/map_fleet_preparation.py b/module/map/map_fleet_preparation.py index d8cfcae9b4..ef2904494d 100644 --- a/module/map/map_fleet_preparation.py +++ b/module/map/map_fleet_preparation.py @@ -127,7 +127,7 @@ def raise_hard_not_satisfied(self): stage = self.main.config.Campaign_Name logger.critical(f'Stage "{stage}" is a hard mode, ' f'please prepare your fleet "{str(self)}" in game before running Alas') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def clear(self, skip_first_screenshot=True): """ diff --git a/module/map/map_operation.py b/module/map/map_operation.py index e7fff3314f..fabdc4205e 100644 --- a/module/map/map_operation.py +++ b/module/map/map_operation.py @@ -131,7 +131,7 @@ def enter_map(self, button, mode='normal', skip_first_screenshot=True): if campaign_click > 5: logger.critical(f"Failed to enter {button}, too many click on {button}") logger.critical("Possible reason #1: You haven't reached the commander level to unlock this stage.") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if fleet_click > 5: logger.critical(f"Failed to enter {button}, too many click on FLEET_PREPARATION") logger.critical("Possible reason #1: " @@ -139,7 +139,7 @@ def enter_map(self, button, mode='normal', skip_first_screenshot=True): logger.critical("Possible reason #2: " "This stage can only be farmed once a day, " "but it's the second time that you are entering") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') # Already in map if not checked_in_map and self.is_in_map(): @@ -402,7 +402,7 @@ def handle_fleet_reverse(self): logger.warning(f"You shouldn't use a reversed fleet order ({self.config.Fleet_FleetOrder}) in normal mode.") logger.warning('Please reverse your Fleet 1 and Fleet 2, ' 'use "fleet1_mob_fleet2_boss" or "fleet1_all_fleet2_standby"') - # raise RequestHumanTakeover + # raise RequestHumanTakeover('Request human takeover') if not self.fleets_reversed: return False diff --git a/module/ocr/al_ocr.py b/module/ocr/al_ocr.py index 2827c5dc77..9d966ff406 100644 --- a/module/ocr/al_ocr.py +++ b/module/ocr/al_ocr.py @@ -168,7 +168,7 @@ def _assert_and_prepare_model_files(self): logger.warning(f'Ocr model not prepared: {model_dir}') logger.warning(f'Required files: {model_files}') logger.critical('Please check if required files of pre-trained OCR model exist') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') def _get_module(self, context): network, self._hp = gen_network(self._model_name, self._hp, self._net_prefix) diff --git a/module/os/globe_operation.py b/module/os/globe_operation.py index 22aa5e2591..fe85e6f19f 100644 --- a/module/os/globe_operation.py +++ b/module/os/globe_operation.py @@ -6,17 +6,18 @@ from module.os_handler.assets import AUTO_SEARCH_REWARD from module.os_handler.port import PORT_CHECK from module.ui.assets import BACK_ARROW +from module.exception import ALASBaseError ZONE_TYPES = [ZONE_DANGEROUS, ZONE_SAFE, ZONE_OBSCURE, ZONE_ABYSSAL, ZONE_STRONGHOLD, ZONE_ARCHIVE] ZONE_SELECT = [SELECT_DANGEROUS, SELECT_SAFE, SELECT_OBSCURE, SELECT_ABYSSAL, SELECT_STRONGHOLD, SELECT_ARCHIVE] ASSETS_PINNED_ZONE = ZONE_TYPES + [ZONE_ENTRANCE, ZONE_SWITCH, ZONE_PINNED] -class OSExploreError(Exception): +class OSExploreError(ALASBaseError): pass -class RewardUncollectedError(Exception): +class RewardUncollectedError(ALASBaseError): pass diff --git a/module/os/map.py b/module/os/map.py index a329a1ec85..5f79cb80dd 100644 --- a/module/os/map.py +++ b/module/os/map.py @@ -491,7 +491,7 @@ def os_auto_search_daemon(self, drop=None, strategic=False, skip_first_screensho logger.critical('Unable to use auto search in current zone') logger.critical('Please finish the story mode of OpSi to unlock auto search ' 'before using any OpSi functions') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.is_in_map(): self.device.stuck_record_clear() if not success: diff --git a/module/os/operation_siren.py b/module/os/operation_siren.py index 7c68f8c006..0b78f24a4a 100644 --- a/module/os/operation_siren.py +++ b/module/os/operation_siren.py @@ -633,7 +633,7 @@ def clear_abyssal(self): self.zone_init() result = self.run_abyssal() if not result: - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') self.fleet_repair(revert=False) self.delay_abyssal() diff --git a/module/os_ash/ash.py b/module/os_ash/ash.py index aeee4e621d..8a7afdf1a8 100644 --- a/module/os_ash/ash.py +++ b/module/os_ash/ash.py @@ -9,6 +9,7 @@ from module.os_handler.map_event import MapEventHandler from module.ui.assets import BACK_ARROW from module.ui.ui import UI +from module.exception import ALASBaseError class DailyDigitCounter(DigitCounter): @@ -18,7 +19,7 @@ def pre_process(self, image): return image -class AshBeaconFinished(Exception): +class AshBeaconFinished(ALASBaseError): pass diff --git a/module/os_combat/combat.py b/module/os_combat/combat.py index fdacdc751f..11aa002e94 100644 --- a/module/os_combat/combat.py +++ b/module/os_combat/combat.py @@ -4,9 +4,10 @@ from module.os_combat.assets import * from module.os_handler.assets import * from module.os_handler.map_event import MapEventHandler +from module.exception import ALASBaseError -class ContinuousCombat(Exception): +class ContinuousCombat(ALASBaseError): pass diff --git a/module/os_handler/action_point.py b/module/os_handler/action_point.py index 17084dd657..110ef1be20 100644 --- a/module/os_handler/action_point.py +++ b/module/os_handler/action_point.py @@ -12,6 +12,7 @@ from module.statistics.item import Item, ItemGrid from module.ui.assets import OS_CHECK from module.ui.ui import UI +from module.exception import ALASBaseError OCR_ACTION_POINT_REMAIN = Digit(ACTION_POINT_REMAIN, letter=(255, 219, 66), name='OCR_ACTION_POINT_REMAIN') OCR_ACTION_POINT_REMAIN_OS = Digit(ACTION_POINT_REMAIN_OS, letter=(239, 239, 239), @@ -93,7 +94,7 @@ def predict_valid(self): } -class ActionPointLimit(Exception): +class ActionPointLimit(ALASBaseError): pass diff --git a/module/os_handler/mission.py b/module/os_handler/mission.py index 51a0697f34..8201d7748b 100644 --- a/module/os_handler/mission.py +++ b/module/os_handler/mission.py @@ -10,9 +10,10 @@ from module.os.globe_operation import GlobeOperation from module.os.globe_zone import Zone, ZoneManager from module.os_handler.assets import * +from module.exception import ALASBaseError -class MissionAtCurrentZone(Exception): +class MissionAtCurrentZone(ALASBaseError): pass diff --git a/module/raid/raid.py b/module/raid/raid.py index bf9c18944d..0d4eac7fe5 100644 --- a/module/raid/raid.py +++ b/module/raid/raid.py @@ -6,7 +6,7 @@ from module.base.timer import Timer from module.campaign.campaign_event import CampaignEvent from module.combat.assets import * -from module.exception import ScriptError +from module.exception import ScriptError, ALASBaseError from module.logger import logger from module.map.map_operation import MapOperation from module.ocr.ocr import Digit, DigitCounter @@ -16,7 +16,7 @@ from module.ui.page import page_rpg_stage -class OilExhausted(Exception): +class OilExhausted(ALASBaseError): pass diff --git a/module/retire/retirement.py b/module/retire/retirement.py index 1bd429ac1c..242ab82bc9 100644 --- a/module/retire/retirement.py +++ b/module/retire/retirement.py @@ -427,7 +427,7 @@ def _retire_handler(self, mode=None): logger.critical('No ship retired') logger.critical('Please configure your "Quick Retire Options" in game, ' 'make sure it can select ships to retire') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') elif mode == 'old_retire': self.handle_dock_cards_loading() total = self.retire_ships_old() @@ -436,7 +436,7 @@ def _retire_handler(self, mode=None): logger.critical('No ship retired') logger.critical('Please configure your retirement settings in Alas, ' 'make sure it can select ships to retire') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') else: raise ScriptError( f'Unknown retire mode: {self.config.Retirement_RetireMode}') diff --git a/module/statistics/utils.py b/module/statistics/utils.py index da4aec4ad5..6936921029 100644 --- a/module/statistics/utils.py +++ b/module/statistics/utils.py @@ -4,9 +4,10 @@ import numpy as np from module.base.utils import crop, image_size +from module.exception import ALASBaseError -class ImageError(Exception): +class ImageError(ALASBaseError): """ Error when parsing images """ pass diff --git a/module/storage/storage.py b/module/storage/storage.py index b13d4c67df..ce28f67f87 100644 --- a/module/storage/storage.py +++ b/module/storage/storage.py @@ -4,7 +4,7 @@ from module.base.timer import Timer from module.base.utils import rgb2gray from module.combat.assets import GET_ITEMS_1, GET_ITEMS_2 -from module.exception import ScriptError +from module.exception import ScriptError, ALASBaseError from module.logger import logger from module.ocr.ocr import Digit from module.statistics.item import ItemGrid @@ -21,7 +21,7 @@ OCR_DISASSEMBLE_COUNT = Digit(DISASSEMBLE_COUNT_OCR, letter=(235, 235, 235)) -class StorageFull(Exception): +class StorageFull(ALASBaseError): pass diff --git a/module/ui/ui.py b/module/ui/ui.py index bfb8fe9ccc..b470221660 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -219,7 +219,7 @@ def rotation_check(): logger.warning(f"Supported page: {[str(page) for page in Page.iter_pages()]}") logger.warning('Supported page: Any page with a "HOME" button on the upper-right') logger.critical("Please switch to a supported page before starting Alas") - raise GamePageUnknownError + raise GamePageUnknownError('Game page unknown') def ui_goto(self, destination, offset=(30, 30), skip_first_screenshot=True): """ @@ -429,7 +429,7 @@ def ui_page_os_popups(self): logger.critical("Possible reason #1: You haven't set any fleets in operation siren") logger.critical( "Possible reason #2: Your fleets haven't satisfied the level restrictions in operation siren") - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.appear_then_click(RESET_TICKET_POPUP, offset=(30, 30), interval=3): return True if self.appear_then_click(RESET_FLEET_PREPARATION, offset=(30, 30), interval=3): diff --git a/module/webui/remote_access.py b/module/webui/remote_access.py index 1dd45b65f0..43b06908f9 100644 --- a/module/webui/remote_access.py +++ b/module/webui/remote_access.py @@ -19,6 +19,7 @@ from module.logger import logger from module.config.utils import random_id from module.webui.setting import State +from module.exception import ALASBaseError if TYPE_CHECKING: from module.webui.utils import TaskHandler @@ -143,7 +144,7 @@ def start_remote_access_service_(**kwargs): logger.info("Exit remote access service thread") -class ParseError(Exception): +class ParseError(ALASBaseError): pass diff --git a/submodule/AlasMaaBridge/maa.py b/submodule/AlasMaaBridge/maa.py index b8df787d19..a51350e193 100644 --- a/submodule/AlasMaaBridge/maa.py +++ b/submodule/AlasMaaBridge/maa.py @@ -59,7 +59,7 @@ def asst(self): logger.critical( f'未找到路径 {self.config.MaaEmulator_MaaPath},请确认MAA已安装在该路径。' f'如果你是第一次使用MAA插件,需要自选安装MAA,并在 "MAA设置" - "MAA安装路径" 中填入MAA的安装路径') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') try: incremental_path = [os.path.join(self.config.MaaEmulator_MaaPath, './cache')] if self.config.MaaEmulator_PackageName in ["YoStarEN", "YoStarJP", "YoStarKR", "txwy"]: @@ -74,7 +74,7 @@ def asst(self): AssistantHandler.load(self.config.MaaEmulator_MaaPath, incremental_path) except ModuleNotFoundError: logger.critical('找不到MAA,请检查安装路径是否正确') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') except OSError as e: # OSError: [WinError 126] 找不到指定的模块。 if '[WinError 126]' in str(e): @@ -82,7 +82,7 @@ def asst(self): logger.critical( f'无法导入MAA,请确认MAA已正确安装在 {self.config.MaaEmulator_MaaPath}' ) - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') else: raise @@ -113,7 +113,7 @@ def callback(msg, details, arg): asst.set_instance_option(AssistantHandler.InstanceOptionType.deployment_with_pause, '1') else: logger.critical('使用了不支持暂停下干员的触控方案') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') return asst diff --git a/submodule/AlasMaaBridge/module/handler/handler.py b/submodule/AlasMaaBridge/module/handler/handler.py index d5d0f443c7..cf1934de63 100644 --- a/submodule/AlasMaaBridge/module/handler/handler.py +++ b/submodule/AlasMaaBridge/module/handler/handler.py @@ -66,7 +66,7 @@ def maa_stop(self): while 1: if self.callback_timer.reached(): logger.critical('MAA no respond, probably stuck') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.signal in [ self.Message.AllTasksCompleted, @@ -88,11 +88,11 @@ def maa_start(self, task_name, params): while 1: if self.callback_timer.reached(): logger.critical('MAA no respond, probably stuck') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.signal is not None: if self.signal == self.Message.TaskChainError: - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') self.maa_stop() self.callback_list.clear() return @@ -204,7 +204,7 @@ def connect(self): self.callback_list = [] if not self.asst.connect(adb, self.serial): - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') self.callback_list = old_callback_list @@ -367,7 +367,7 @@ def infrast(self): if periods is None: if self.config.MaaCustomInfrast_CustomPeriod == 'null': logger.critical('无法找到配置文件中的排班周期,请检查文件是否有效') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') else: args['plan_index'] = self.config.MaaCustomInfrast_PlanIndex else: @@ -407,7 +407,7 @@ def infrast(self): else: if self.config.MaaInfrast_WorkThreshold <= self.config.MaaInfrast_ShiftThreshold: logger.warning('基建换班心情阈值必须小于基建工作心情阈值,请调整基建设置') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') self.maa_start('Infrast', args) # 根据心情阈值计算下次换班时间 @@ -504,7 +504,7 @@ def copilot(self): r = requests.get(f"https://prts.maa.plus/copilot/get/{filename.strip('maa://')}", timeout=30) if r.status_code != 200: logger.critical('作业文件下载失败,请检查神秘代码或网络状况') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') logger.info('作业下载完毕') r.encoding = 'utf-8' @@ -518,7 +518,7 @@ def copilot(self): stage = deep_get(homework, keys='stage_name') if not stage: logger.critical('作业文件不存在或已经损坏') - raise RequestHumanTakeover + raise RequestHumanTakeover('Request human takeover') if self.config.MaaCopilot_Identify: logger.info(deep_get(homework, keys='doc.title', default='标题:无') + '\n') From db6e397b58f86382420eddb814ab140be4a48621 Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 11 Oct 2024 00:32:54 +0800 Subject: [PATCH 2/6] Upd: Fix. --- .../campaign_war_archives/campaign_base.py | 2 +- deploy/Windows/config.py | 3 +-- deploy/config.py | 3 +-- module/campaign/run.py | 2 +- module/coalition/ui.py | 6 +++--- module/combat/emotion.py | 2 +- module/config/config.py | 2 +- module/device/connection.py | 18 +++++++++--------- module/device/connection_attr.py | 10 +++++----- module/device/device.py | 8 ++++---- module/device/method/adb.py | 2 +- module/device/method/ascreencap.py | 4 ++-- module/device/method/droidcast.py | 2 +- module/device/method/hermit.py | 6 +++--- module/device/method/ldopengl.py | 6 +++--- module/device/method/maatouch.py | 2 +- module/device/method/minitouch.py | 4 ++-- module/device/method/nemu_ipc.py | 12 ++++++------ module/device/method/scrcpy/core.py | 2 +- module/device/method/scrcpy/scrcpy.py | 2 +- module/device/method/uiautomator_2.py | 4 ++-- module/device/method/wsa.py | 2 +- module/device/pkg_resources/__init__.py | 3 +-- module/device/screenshot.py | 4 ++-- module/event/campaign_abcd.py | 2 +- module/handler/login.py | 2 +- module/map/map_fleet_preparation.py | 2 +- module/map/map_operation.py | 6 +++--- module/ocr/al_ocr.py | 2 +- module/os/map.py | 2 +- module/os/operation_siren.py | 2 +- module/retire/retirement.py | 4 ++-- module/ui/ui.py | 2 +- submodule/AlasMaaBridge/maa.py | 2 +- .../AlasMaaBridge/module/handler/handler.py | 16 ++++++++-------- 35 files changed, 75 insertions(+), 78 deletions(-) diff --git a/campaign/campaign_war_archives/campaign_base.py b/campaign/campaign_war_archives/campaign_base.py index fdfece1d71..26cdf43d5c 100644 --- a/campaign/campaign_war_archives/campaign_base.py +++ b/campaign/campaign_war_archives/campaign_base.py @@ -110,7 +110,7 @@ def ui_goto_archives_campaign(self, mode='ex'): else: logger.critical('Respective server may not yet support the chosen War Archives campaign, ' 'check back in the next app update') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Subsequent runs all set False if self.first_run: diff --git a/deploy/Windows/config.py b/deploy/Windows/config.py index dc72e057d8..5c10ab0a8e 100644 --- a/deploy/Windows/config.py +++ b/deploy/Windows/config.py @@ -6,10 +6,9 @@ from deploy.Windows.logger import logger from deploy.Windows.utils import DEPLOY_CONFIG, DEPLOY_TEMPLATE, cached_property, poor_yaml_read, poor_yaml_write -from module.exception import ALASBaseError -class ExecutionError(ALASBaseError): +class ExecutionError(Exception): pass diff --git a/deploy/config.py b/deploy/config.py index 6c4aec5b66..528a160780 100644 --- a/deploy/config.py +++ b/deploy/config.py @@ -3,10 +3,9 @@ from deploy.logger import logger from deploy.utils import * -from module.exception import ALASBaseError -class ExecutionError(ALASBaseError): +class ExecutionError(Exception): pass diff --git a/module/campaign/run.py b/module/campaign/run.py index 14e660a265..0c3dca1316 100644 --- a/module/campaign/run.py +++ b/module/campaign/run.py @@ -59,7 +59,7 @@ def load_campaign(self, name, folder='campaign_main'): logger.critical(f'Possible reason #1: This event ({folder}) does not have {name}') logger.critical(f'Possible reason #2: You are using an old Alas, ' 'please check for update, or make map files yourself using dev_tools/map_extractor.py') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover config = copy.deepcopy(self.config).merge(self.module.Config()) device = self.device diff --git a/module/coalition/ui.py b/module/coalition/ui.py index aa82514559..7fd2ee01a4 100644 --- a/module/coalition/ui.py +++ b/module/coalition/ui.py @@ -196,7 +196,7 @@ def enter_map(self, event, stage, mode, skip_first_screenshot=True): if campaign_click > 5: logger.critical(f"Failed to enter {button}, too many click on {button}") logger.critical("Possible reason #1: You haven't cleared previous stage to unlock the stage.") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if fleet_click > 5: logger.critical(f"Failed to enter {button}, too many click on FLEET_PREPARATION") logger.critical("Possible reason #1: " @@ -204,11 +204,11 @@ def enter_map(self, event, stage, mode, skip_first_screenshot=True): logger.critical("Possible reason #2: " "This stage can only be farmed once a day, " "but it's the second time that you are entering") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.appear(FLEET_NOT_PREPARED, offset=(20, 20)): logger.critical('FLEET_NOT_PREPARED') logger.critical('Please prepare you fleets before running coalition battles') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # End if self.appear(BATTLE_PREPARATION, offset=(20, 20)): diff --git a/module/combat/emotion.py b/module/combat/emotion.py index 039e5b5c1e..325cb56d01 100644 --- a/module/combat/emotion.py +++ b/module/combat/emotion.py @@ -132,7 +132,7 @@ def get_recovered(self, expected_reduce=0): logger.critical(f'Fleet {self.fleet} Emotion Control=\"Keep Happy Bonus\" and ' f'Fleet {self.fleet} Recover Location=\"Docks\" can not be used together, ' 'please check your emotion settings') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # In 14-4 with 2X book, expected emotion reduce is 32, can't keep happy bonus (>120), # otherwise will infinite task delay if self.control == 'keep_exp_bonus' and expected_reduce >= 29: diff --git a/module/config/config.py b/module/config/config.py index c3259da9df..25087912e9 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -257,7 +257,7 @@ def get_next(self): else: logger.critical("No task waiting or pending") logger.critical("Please enable at least one task") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def save(self, mod_name='alas'): if not self.modified: diff --git a/module/device/connection.py b/module/device/connection.py index 4772200824..6610000d4c 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -71,7 +71,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -174,7 +174,7 @@ def adb_command(self, cmd, timeout=10): f'Trying to execute {cmd}, ' f'but adb_command() is not available when connecting over http: {self.serial}, ' ) - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def adb_start_server(self): """ @@ -345,7 +345,7 @@ def check_mumu_app_keep_alive(self): elif res == 'true': # https://mumu.163.com/help/20230802/35047_1102450.html logger.critical('请在MuMu模拟器设置内关闭 "后台挂机时保活运行"') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover else: logger.warning(f'Invalid nemud.app_keep_alive value: {res}') return False @@ -482,7 +482,7 @@ def nc_command(self): return command logger.error('No `netcat` command available, please use screenshot methods without `_nc` suffix') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def adb_shell_nc(self, cmd, timeout=5, chunk_size=262144): """ @@ -686,7 +686,7 @@ def adb_connect(self): # bad port number '598265' in '127.0.0.1:598265' elif 'bad port' in msg: possible_reasons('Serial incorrect, might be a typo') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # cannot connect to 127.0.0.1:55555: # No connection could be made because the target machine actively refused it. (10061) elif '(10061)' in msg: @@ -957,7 +957,7 @@ def brute_force_connect(): if available.count == 0: logger.critical('No available device found, auto device detection cannot work, ' 'please set an exact serial in Alas.Emulator.Serial instead of using "auto"') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover elif available.count == 1: logger.info(f'Auto device detection found only one device, using it') self.config.Emulator_Serial = self.serial = available[0].serial @@ -974,7 +974,7 @@ def brute_force_connect(): else: logger.critical('Multiple devices found, auto device detection cannot decide which to choose, ' 'please copy one of the available devices listed above to Alas.Emulator.Serial') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Handle LDPlayer # LDPlayer serial jumps between `127.0.0.1:5555+{X}` and `emulator-5554+{X}` @@ -1113,7 +1113,7 @@ def detect_package(self, set_config=True): if len(packages) == 0: logger.critical(f'No AzurLane package found, ' f'please confirm AzurLane has been installed on device "{self.serial}"') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if len(packages) == 1: logger.info('Auto package detection found only one package, using it') self.package = packages[0] @@ -1127,4 +1127,4 @@ def detect_package(self, set_config=True): logger.critical( f'Multiple AzurLane packages found, auto package detection cannot decide which to choose, ' 'please copy one of the available devices listed above to Alas.Emulator.PackageName') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover diff --git a/module/device/connection_attr.py b/module/device/connection_attr.py index 88eae9e588..0814b95248 100644 --- a/module/device/connection_attr.py +++ b/module/device/connection_attr.py @@ -113,7 +113,7 @@ def serial_check(self): if "127.0.0.1:58526" in self.serial: logger.warning('Serial 127.0.0.1:58526 seems to be WSA, ' 'please use "wsa-0" or others instead') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.is_wsa: self.serial = '127.0.0.1:58526' if self.config.Emulator_ScreenshotMethod != 'uiautomator2' \ @@ -129,7 +129,7 @@ def serial_check(self): f'ScreenshotMethod can only use ["ADB", "uiautomator2", "aScreenCap"], ' f'ControlMethod can only use ["ADB", "uiautomator2", "minitouch"]' ) - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover @cached_property def is_bluestacks4_hyperv(self): @@ -234,7 +234,7 @@ def find_bluestacks4_hyperv(serial): logger.error('Please confirm that your are using BlueStack 4 hyper-v and not regular BlueStacks 4') logger.error(r'Please check if there is any other emulator instances under ' r'registry HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_bgp64_hyperv\Guests') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover logger.info(f"New adb port: {port}") return f"127.0.0.1:{port}" @@ -270,7 +270,7 @@ def find_bluestacks5_hyperv(serial): logger.error('Unable to find registry HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_nxt ' 'or HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks_nxt_cn') logger.error('Please confirm that you are using BlueStacks 5 hyper-v and not regular BlueStacks 5') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover logger.info(f"Configuration file directory: {directory}") with open(os.path.join(directory, 'bluestacks.conf'), encoding='utf-8') as f: @@ -278,7 +278,7 @@ def find_bluestacks5_hyperv(serial): port = re.search(rf'{parameter_name}="(\d+)"', content) if port is None: logger.warning(f"Did not match the result: {serial}.") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover port = port.group(2) logger.info(f"Match to dynamic port: {port}") return f"127.0.0.1:{port}" diff --git a/module/device/device.py b/module/device/device.py index b39d6f2673..11a10172a3 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -77,7 +77,7 @@ def __init__(self, *args, **kwargs): except EmulatorNotRunningError: if trial >= 3: logger.critical('Failed to start emulator after 3 trial') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Try to start emulator if self.emulator_instance is not None: self.emulator_start() @@ -86,7 +86,7 @@ def __init__(self, *args, **kwargs): f'No emulator with serial "{self.config.Emulator_Serial}" found, ' f'please set a correct serial' ) - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Auto-fill emulator info if IS_WINDOWS and self.config.EmulatorInfo_Emulator == 'auto': @@ -311,7 +311,7 @@ def app_start(self): if not self.config.Error_HandleError: logger.critical('No app stop/start, because HandleError disabled') logger.critical('Please enable Alas.Error.HandleError or manually login to AzurLane') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover super().app_start() self.stuck_record_clear() self.click_record_clear() @@ -320,7 +320,7 @@ def app_stop(self): if not self.config.Error_HandleError: logger.critical('No app stop/start, because HandleError disabled') logger.critical('Please enable Alas.Error.HandleError or manually login to AzurLane') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover super().app_stop() self.stuck_record_clear() self.click_record_clear() diff --git a/module/device/method/adb.py b/module/device/method/adb.py index 4b78243d3f..f699b7309f 100644 --- a/module/device/method/adb.py +++ b/module/device/method/adb.py @@ -70,7 +70,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/method/ascreencap.py b/module/device/method/ascreencap.py index 16a4ef0d0c..f0f3fb1264 100644 --- a/module/device/method/ascreencap.py +++ b/module/device/method/ascreencap.py @@ -70,7 +70,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -103,7 +103,7 @@ def ascreencap_init(self): self.ascreencap_available = False logger.error('No suitable version of aScreenCap lib available for this device, ' 'please use other screenshot methods instead') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover logger.info(f'pushing {filepath}') self.adb_push(filepath, self.config.ASCREENCAP_FILEPATH_REMOTE) diff --git a/module/device/method/droidcast.py b/module/device/method/droidcast.py index 1a9214d311..57e3405347 100644 --- a/module/device/method/droidcast.py +++ b/module/device/method/droidcast.py @@ -87,7 +87,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/method/hermit.py b/module/device/method/hermit.py index 78e5a65fea..9ed994a4c1 100644 --- a/module/device/method/hermit.py +++ b/module/device/method/hermit.py @@ -83,7 +83,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -193,7 +193,7 @@ def appear_then_click(xpath): '2. Turn it ON and click OK\n' '3. Switch back to AzurLane\n' ) - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover @cached_property def hermit_session(self): @@ -222,7 +222,7 @@ def hermit_send(self, url, **kwargs): if 'GestureDescription$Builder' in result: logger.error(e) logger.critical('Hermit cannot run on current device, hermit requires Android>=7.0') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if 'accessibilityservice' in result: # Attempt to invoke virtual method # 'boolean android.accessibilityservice.AccessibilityService.dispatchGesture( diff --git a/module/device/method/ldopengl.py b/module/device/method/ldopengl.py index a910a733d1..e99800b825 100644 --- a/module/device/method/ldopengl.py +++ b/module/device/method/ldopengl.py @@ -169,7 +169,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -300,7 +300,7 @@ def ldopengl(self): # installation path is E:/ProgramFiles/LDPlayer9 if self.emulator_instance is None: logger.error('Unable to use LDOpenGL because emulator instance not found') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover try: return LDOpenGLImpl( ld_folder=self.emulator_instance.emulator.abspath('./'), @@ -309,7 +309,7 @@ def ldopengl(self): except (LDOpenGLIncompatible, LDOpenGLError) as e: logger.error(e) logger.error('Unable to initialize LDOpenGL') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def ldopengl_available(self) -> bool: if not self.is_ldplayer_bluestacks_family: diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index 99ca2fb965..1357431b60 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -92,7 +92,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index ad5933b22d..73e52e03d3 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -15,7 +15,7 @@ from module.base.utils import * from module.device.connection import Connection from module.device.method.utils import RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep -from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError +from module.exception import RequestHumanTakeover, ScriptError from module.logger import logger @@ -455,7 +455,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/method/nemu_ipc.py b/module/device/method/nemu_ipc.py index ff13d5dd2f..7b4eca9c30 100644 --- a/module/device/method/nemu_ipc.py +++ b/module/device/method/nemu_ipc.py @@ -195,7 +195,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -471,7 +471,7 @@ def nemu_ipc(self) -> NemuIpcImpl: if self.config.EmulatorInfo_path: if 'MuMuPlayerGlobal' in self.config.EmulatorInfo_path: logger.info(f'nemu_ipc is not available on MuMuPlayerGlobal, {self.config.EmulatorInfo_path}') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover folder = os.path.abspath(os.path.join(self.config.EmulatorInfo_path, '../../')) index = NemuIpcImpl.serial_to_id(self.serial) if index is not None: @@ -490,10 +490,10 @@ def nemu_ipc(self) -> NemuIpcImpl: # installation path is E:\ProgramFiles\MuMuPlayer-12.0 if self.emulator_instance is None: logger.error('Unable to use NemuIpc because emulator instance not found') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if 'MuMuPlayerGlobal' in self.emulator_instance.path: logger.info(f'nemu_ipc is not available on MuMuPlayerGlobal, {self.emulator_instance.path}') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover try: return NemuIpcImpl( nemu_folder=self.emulator_instance.emulator.abspath('../'), @@ -503,7 +503,7 @@ def nemu_ipc(self) -> NemuIpcImpl: except (NemuIpcIncompatible, NemuIpcError) as e: logger.error(e) logger.error('Unable to initialize NemuIpc') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def nemu_ipc_available(self) -> bool: if not self.is_mumu_family: @@ -544,7 +544,7 @@ def check_mumu_app_keep_alive_400(file): if str(value).lower() == 'true': # https://mumu.163.com/help/20230802/35047_1102450.html logger.critical('请在MuMu模拟器设置内关闭 "后台挂机时保活运行"') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return True def check_mumu_app_keep_alive(self): diff --git a/module/device/method/scrcpy/core.py b/module/device/method/scrcpy/core.py index f50a760a10..4bc65dfca9 100644 --- a/module/device/method/scrcpy/core.py +++ b/module/device/method/scrcpy/core.py @@ -205,7 +205,7 @@ def _scrcpy_stream_loop(self) -> None: except ImportError as e: logger.error(e) logger.error('You must have `av` installed to use scrcpy screenshot, please update dependencies') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover codec = CodecContext.create("h264", "r") while self._scrcpy_alive: diff --git a/module/device/method/scrcpy/scrcpy.py b/module/device/method/scrcpy/scrcpy.py index 9df48bd45e..d666a11ae6 100644 --- a/module/device/method/scrcpy/scrcpy.py +++ b/module/device/method/scrcpy/scrcpy.py @@ -76,7 +76,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/method/uiautomator_2.py b/module/device/method/uiautomator_2.py index c3d0fd1080..d5d4e951dd 100644 --- a/module/device/method/uiautomator_2.py +++ b/module/device/method/uiautomator_2.py @@ -94,7 +94,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper @@ -426,7 +426,7 @@ def resolution_check_uiautomator2(self): logger.critical(f'Resolution not supported: {width}x{height}') logger.critical('Please set emulator resolution to 1280x720') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover @retry def proc_list_uiautomator2(self) -> t.List[ProcessInfo]: diff --git a/module/device/method/wsa.py b/module/device/method/wsa.py index b49aa97c92..6ae1c60281 100644 --- a/module/device/method/wsa.py +++ b/module/device/method/wsa.py @@ -58,7 +58,7 @@ def init(): pass logger.critical(f'Retry {func.__name__}() failed') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return retry_wrapper diff --git a/module/device/pkg_resources/__init__.py b/module/device/pkg_resources/__init__.py index 5a9614a64b..b685a6d9aa 100644 --- a/module/device/pkg_resources/__init__.py +++ b/module/device/pkg_resources/__init__.py @@ -4,7 +4,6 @@ from module.base.decorator import cached_property from module.logger import logger -from module.exception import ALASBaseError """ Importing pkg_resources is so slow, like 0.4 ~ 1.0s, just google it you will find it indeed really slow. @@ -106,5 +105,5 @@ def get_distribution(dist): ) -class DistributionNotFound(ALASBaseError): +class DistributionNotFound(Exception): pass diff --git a/module/device/screenshot.py b/module/device/screenshot.py index 7b639dfab5..9940ee0556 100644 --- a/module/device/screenshot.py +++ b/module/device/screenshot.py @@ -115,7 +115,7 @@ def screenshot_deque(self): length = int(self.config.Error_ScreenshotLength) except ValueError: logger.error(f'Error_ScreenshotLength={self.config.Error_ScreenshotLength} is not an integer') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Limit in 1~300 length = max(1, min(length, 300)) return deque(maxlen=length) @@ -238,7 +238,7 @@ def check_screen_size(self): else: logger.critical(f'Resolution not supported: {width}x{height}') logger.critical('Please set emulator resolution to 1280x720') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def check_screen_black(self): if self._screen_black_checked: diff --git a/module/event/campaign_abcd.py b/module/event/campaign_abcd.py index 2bd52e2cfa..a01cdfb1c1 100644 --- a/module/event/campaign_abcd.py +++ b/module/event/campaign_abcd.py @@ -54,7 +54,7 @@ def run(self, *args, **kwargs): f'Cannot find stage "{stage}". ' f'Task "{task}" is for 3X daily PT, if you have not unlock {stage}, ' f'you should use task "Event" to unlock it instead of using task "{task}"') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover else: raise diff --git a/module/handler/login.py b/module/handler/login.py index 41b6aa9f45..bb4b0ed1c1 100644 --- a/module/handler/login.py +++ b/module/handler/login.py @@ -140,7 +140,7 @@ def handle_app_login(self): logger.critical('Login failed more than 3') logger.critical('Azur Lane server may be under maintenance, or you may lost network connection') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def app_stop(self): logger.hr('App stop') diff --git a/module/map/map_fleet_preparation.py b/module/map/map_fleet_preparation.py index ef2904494d..d8cfcae9b4 100644 --- a/module/map/map_fleet_preparation.py +++ b/module/map/map_fleet_preparation.py @@ -127,7 +127,7 @@ def raise_hard_not_satisfied(self): stage = self.main.config.Campaign_Name logger.critical(f'Stage "{stage}" is a hard mode, ' f'please prepare your fleet "{str(self)}" in game before running Alas') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def clear(self, skip_first_screenshot=True): """ diff --git a/module/map/map_operation.py b/module/map/map_operation.py index fabdc4205e..e7fff3314f 100644 --- a/module/map/map_operation.py +++ b/module/map/map_operation.py @@ -131,7 +131,7 @@ def enter_map(self, button, mode='normal', skip_first_screenshot=True): if campaign_click > 5: logger.critical(f"Failed to enter {button}, too many click on {button}") logger.critical("Possible reason #1: You haven't reached the commander level to unlock this stage.") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if fleet_click > 5: logger.critical(f"Failed to enter {button}, too many click on FLEET_PREPARATION") logger.critical("Possible reason #1: " @@ -139,7 +139,7 @@ def enter_map(self, button, mode='normal', skip_first_screenshot=True): logger.critical("Possible reason #2: " "This stage can only be farmed once a day, " "but it's the second time that you are entering") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover # Already in map if not checked_in_map and self.is_in_map(): @@ -402,7 +402,7 @@ def handle_fleet_reverse(self): logger.warning(f"You shouldn't use a reversed fleet order ({self.config.Fleet_FleetOrder}) in normal mode.") logger.warning('Please reverse your Fleet 1 and Fleet 2, ' 'use "fleet1_mob_fleet2_boss" or "fleet1_all_fleet2_standby"') - # raise RequestHumanTakeover('Request human takeover') + # raise RequestHumanTakeover if not self.fleets_reversed: return False diff --git a/module/ocr/al_ocr.py b/module/ocr/al_ocr.py index 9d966ff406..2827c5dc77 100644 --- a/module/ocr/al_ocr.py +++ b/module/ocr/al_ocr.py @@ -168,7 +168,7 @@ def _assert_and_prepare_model_files(self): logger.warning(f'Ocr model not prepared: {model_dir}') logger.warning(f'Required files: {model_files}') logger.critical('Please check if required files of pre-trained OCR model exist') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover def _get_module(self, context): network, self._hp = gen_network(self._model_name, self._hp, self._net_prefix) diff --git a/module/os/map.py b/module/os/map.py index 5f79cb80dd..a329a1ec85 100644 --- a/module/os/map.py +++ b/module/os/map.py @@ -491,7 +491,7 @@ def os_auto_search_daemon(self, drop=None, strategic=False, skip_first_screensho logger.critical('Unable to use auto search in current zone') logger.critical('Please finish the story mode of OpSi to unlock auto search ' 'before using any OpSi functions') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.is_in_map(): self.device.stuck_record_clear() if not success: diff --git a/module/os/operation_siren.py b/module/os/operation_siren.py index 0b78f24a4a..7c68f8c006 100644 --- a/module/os/operation_siren.py +++ b/module/os/operation_siren.py @@ -633,7 +633,7 @@ def clear_abyssal(self): self.zone_init() result = self.run_abyssal() if not result: - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover self.fleet_repair(revert=False) self.delay_abyssal() diff --git a/module/retire/retirement.py b/module/retire/retirement.py index 242ab82bc9..1bd429ac1c 100644 --- a/module/retire/retirement.py +++ b/module/retire/retirement.py @@ -427,7 +427,7 @@ def _retire_handler(self, mode=None): logger.critical('No ship retired') logger.critical('Please configure your "Quick Retire Options" in game, ' 'make sure it can select ships to retire') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover elif mode == 'old_retire': self.handle_dock_cards_loading() total = self.retire_ships_old() @@ -436,7 +436,7 @@ def _retire_handler(self, mode=None): logger.critical('No ship retired') logger.critical('Please configure your retirement settings in Alas, ' 'make sure it can select ships to retire') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover else: raise ScriptError( f'Unknown retire mode: {self.config.Retirement_RetireMode}') diff --git a/module/ui/ui.py b/module/ui/ui.py index b470221660..8865513fbd 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -429,7 +429,7 @@ def ui_page_os_popups(self): logger.critical("Possible reason #1: You haven't set any fleets in operation siren") logger.critical( "Possible reason #2: Your fleets haven't satisfied the level restrictions in operation siren") - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.appear_then_click(RESET_TICKET_POPUP, offset=(30, 30), interval=3): return True if self.appear_then_click(RESET_FLEET_PREPARATION, offset=(30, 30), interval=3): diff --git a/submodule/AlasMaaBridge/maa.py b/submodule/AlasMaaBridge/maa.py index a51350e193..1d2c33845f 100644 --- a/submodule/AlasMaaBridge/maa.py +++ b/submodule/AlasMaaBridge/maa.py @@ -59,7 +59,7 @@ def asst(self): logger.critical( f'未找到路径 {self.config.MaaEmulator_MaaPath},请确认MAA已安装在该路径。' f'如果你是第一次使用MAA插件,需要自选安装MAA,并在 "MAA设置" - "MAA安装路径" 中填入MAA的安装路径') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover try: incremental_path = [os.path.join(self.config.MaaEmulator_MaaPath, './cache')] if self.config.MaaEmulator_PackageName in ["YoStarEN", "YoStarJP", "YoStarKR", "txwy"]: diff --git a/submodule/AlasMaaBridge/module/handler/handler.py b/submodule/AlasMaaBridge/module/handler/handler.py index cf1934de63..d5d0f443c7 100644 --- a/submodule/AlasMaaBridge/module/handler/handler.py +++ b/submodule/AlasMaaBridge/module/handler/handler.py @@ -66,7 +66,7 @@ def maa_stop(self): while 1: if self.callback_timer.reached(): logger.critical('MAA no respond, probably stuck') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.signal in [ self.Message.AllTasksCompleted, @@ -88,11 +88,11 @@ def maa_start(self, task_name, params): while 1: if self.callback_timer.reached(): logger.critical('MAA no respond, probably stuck') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.signal is not None: if self.signal == self.Message.TaskChainError: - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover self.maa_stop() self.callback_list.clear() return @@ -204,7 +204,7 @@ def connect(self): self.callback_list = [] if not self.asst.connect(adb, self.serial): - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover self.callback_list = old_callback_list @@ -367,7 +367,7 @@ def infrast(self): if periods is None: if self.config.MaaCustomInfrast_CustomPeriod == 'null': logger.critical('无法找到配置文件中的排班周期,请检查文件是否有效') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover else: args['plan_index'] = self.config.MaaCustomInfrast_PlanIndex else: @@ -407,7 +407,7 @@ def infrast(self): else: if self.config.MaaInfrast_WorkThreshold <= self.config.MaaInfrast_ShiftThreshold: logger.warning('基建换班心情阈值必须小于基建工作心情阈值,请调整基建设置') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover self.maa_start('Infrast', args) # 根据心情阈值计算下次换班时间 @@ -504,7 +504,7 @@ def copilot(self): r = requests.get(f"https://prts.maa.plus/copilot/get/{filename.strip('maa://')}", timeout=30) if r.status_code != 200: logger.critical('作业文件下载失败,请检查神秘代码或网络状况') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover logger.info('作业下载完毕') r.encoding = 'utf-8' @@ -518,7 +518,7 @@ def copilot(self): stage = deep_get(homework, keys='stage_name') if not stage: logger.critical('作业文件不存在或已经损坏') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover if self.config.MaaCopilot_Identify: logger.info(deep_get(homework, keys='doc.title', default='标题:无') + '\n') From 59e1ffe473a1efd891600febb9bc813b107a154c Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 11 Oct 2024 00:54:00 +0800 Subject: [PATCH 3/6] Upd: Fix. --- module/exception.py | 3 ++- module/os/globe_operation.py | 5 ++--- module/os_ash/ash.py | 3 +-- module/os_combat/combat.py | 3 +-- module/os_handler/action_point.py | 3 +-- module/os_handler/mission.py | 3 +-- module/raid/raid.py | 4 ++-- module/storage/storage.py | 4 ++-- module/webui/remote_access.py | 3 +-- submodule/AlasMaaBridge/maa.py | 6 +++--- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/module/exception.py b/module/exception.py index 8af73815dc..be1272eb73 100644 --- a/module/exception.py +++ b/module/exception.py @@ -60,4 +60,5 @@ class GamePageUnknownError(ALASBaseError): class RequestHumanTakeover(ALASBaseError): # Request human takeover # Alas is unable to handle such error, probably because of wrong settings. - pass + def __init__(self, message='Request human takeover'): + super().__init__(message) diff --git a/module/os/globe_operation.py b/module/os/globe_operation.py index fe85e6f19f..22aa5e2591 100644 --- a/module/os/globe_operation.py +++ b/module/os/globe_operation.py @@ -6,18 +6,17 @@ from module.os_handler.assets import AUTO_SEARCH_REWARD from module.os_handler.port import PORT_CHECK from module.ui.assets import BACK_ARROW -from module.exception import ALASBaseError ZONE_TYPES = [ZONE_DANGEROUS, ZONE_SAFE, ZONE_OBSCURE, ZONE_ABYSSAL, ZONE_STRONGHOLD, ZONE_ARCHIVE] ZONE_SELECT = [SELECT_DANGEROUS, SELECT_SAFE, SELECT_OBSCURE, SELECT_ABYSSAL, SELECT_STRONGHOLD, SELECT_ARCHIVE] ASSETS_PINNED_ZONE = ZONE_TYPES + [ZONE_ENTRANCE, ZONE_SWITCH, ZONE_PINNED] -class OSExploreError(ALASBaseError): +class OSExploreError(Exception): pass -class RewardUncollectedError(ALASBaseError): +class RewardUncollectedError(Exception): pass diff --git a/module/os_ash/ash.py b/module/os_ash/ash.py index 8a7afdf1a8..aeee4e621d 100644 --- a/module/os_ash/ash.py +++ b/module/os_ash/ash.py @@ -9,7 +9,6 @@ from module.os_handler.map_event import MapEventHandler from module.ui.assets import BACK_ARROW from module.ui.ui import UI -from module.exception import ALASBaseError class DailyDigitCounter(DigitCounter): @@ -19,7 +18,7 @@ def pre_process(self, image): return image -class AshBeaconFinished(ALASBaseError): +class AshBeaconFinished(Exception): pass diff --git a/module/os_combat/combat.py b/module/os_combat/combat.py index 11aa002e94..fdacdc751f 100644 --- a/module/os_combat/combat.py +++ b/module/os_combat/combat.py @@ -4,10 +4,9 @@ from module.os_combat.assets import * from module.os_handler.assets import * from module.os_handler.map_event import MapEventHandler -from module.exception import ALASBaseError -class ContinuousCombat(ALASBaseError): +class ContinuousCombat(Exception): pass diff --git a/module/os_handler/action_point.py b/module/os_handler/action_point.py index 110ef1be20..17084dd657 100644 --- a/module/os_handler/action_point.py +++ b/module/os_handler/action_point.py @@ -12,7 +12,6 @@ from module.statistics.item import Item, ItemGrid from module.ui.assets import OS_CHECK from module.ui.ui import UI -from module.exception import ALASBaseError OCR_ACTION_POINT_REMAIN = Digit(ACTION_POINT_REMAIN, letter=(255, 219, 66), name='OCR_ACTION_POINT_REMAIN') OCR_ACTION_POINT_REMAIN_OS = Digit(ACTION_POINT_REMAIN_OS, letter=(239, 239, 239), @@ -94,7 +93,7 @@ def predict_valid(self): } -class ActionPointLimit(ALASBaseError): +class ActionPointLimit(Exception): pass diff --git a/module/os_handler/mission.py b/module/os_handler/mission.py index 8201d7748b..51a0697f34 100644 --- a/module/os_handler/mission.py +++ b/module/os_handler/mission.py @@ -10,10 +10,9 @@ from module.os.globe_operation import GlobeOperation from module.os.globe_zone import Zone, ZoneManager from module.os_handler.assets import * -from module.exception import ALASBaseError -class MissionAtCurrentZone(ALASBaseError): +class MissionAtCurrentZone(Exception): pass diff --git a/module/raid/raid.py b/module/raid/raid.py index 0d4eac7fe5..bf9c18944d 100644 --- a/module/raid/raid.py +++ b/module/raid/raid.py @@ -6,7 +6,7 @@ from module.base.timer import Timer from module.campaign.campaign_event import CampaignEvent from module.combat.assets import * -from module.exception import ScriptError, ALASBaseError +from module.exception import ScriptError from module.logger import logger from module.map.map_operation import MapOperation from module.ocr.ocr import Digit, DigitCounter @@ -16,7 +16,7 @@ from module.ui.page import page_rpg_stage -class OilExhausted(ALASBaseError): +class OilExhausted(Exception): pass diff --git a/module/storage/storage.py b/module/storage/storage.py index ce28f67f87..b13d4c67df 100644 --- a/module/storage/storage.py +++ b/module/storage/storage.py @@ -4,7 +4,7 @@ from module.base.timer import Timer from module.base.utils import rgb2gray from module.combat.assets import GET_ITEMS_1, GET_ITEMS_2 -from module.exception import ScriptError, ALASBaseError +from module.exception import ScriptError from module.logger import logger from module.ocr.ocr import Digit from module.statistics.item import ItemGrid @@ -21,7 +21,7 @@ OCR_DISASSEMBLE_COUNT = Digit(DISASSEMBLE_COUNT_OCR, letter=(235, 235, 235)) -class StorageFull(ALASBaseError): +class StorageFull(Exception): pass diff --git a/module/webui/remote_access.py b/module/webui/remote_access.py index 43b06908f9..1dd45b65f0 100644 --- a/module/webui/remote_access.py +++ b/module/webui/remote_access.py @@ -19,7 +19,6 @@ from module.logger import logger from module.config.utils import random_id from module.webui.setting import State -from module.exception import ALASBaseError if TYPE_CHECKING: from module.webui.utils import TaskHandler @@ -144,7 +143,7 @@ def start_remote_access_service_(**kwargs): logger.info("Exit remote access service thread") -class ParseError(ALASBaseError): +class ParseError(Exception): pass diff --git a/submodule/AlasMaaBridge/maa.py b/submodule/AlasMaaBridge/maa.py index 1d2c33845f..b8df787d19 100644 --- a/submodule/AlasMaaBridge/maa.py +++ b/submodule/AlasMaaBridge/maa.py @@ -74,7 +74,7 @@ def asst(self): AssistantHandler.load(self.config.MaaEmulator_MaaPath, incremental_path) except ModuleNotFoundError: logger.critical('找不到MAA,请检查安装路径是否正确') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover except OSError as e: # OSError: [WinError 126] 找不到指定的模块。 if '[WinError 126]' in str(e): @@ -82,7 +82,7 @@ def asst(self): logger.critical( f'无法导入MAA,请确认MAA已正确安装在 {self.config.MaaEmulator_MaaPath}' ) - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover else: raise @@ -113,7 +113,7 @@ def callback(msg, details, arg): asst.set_instance_option(AssistantHandler.InstanceOptionType.deployment_with_pause, '1') else: logger.critical('使用了不支持暂停下干员的触控方案') - raise RequestHumanTakeover('Request human takeover') + raise RequestHumanTakeover return asst From 2f7a502de01626bffcf1212c589aace650a3c9ce Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 11 Oct 2024 01:12:10 +0800 Subject: [PATCH 4/6] Upd: Fix. --- module/config/config.py | 4 ++-- module/device/method/ascreencap.py | 4 ++-- module/device/method/droidcast.py | 4 ++-- module/device/method/hermit.py | 4 ++-- module/device/method/ldopengl.py | 6 +++--- module/device/method/maatouch.py | 6 +++--- module/device/method/minitouch.py | 4 ++-- module/device/method/nemu_ipc.py | 6 +++--- module/device/method/scrcpy/core.py | 4 ++-- module/device/method/utils.py | 5 ++--- module/exception.py | 2 ++ module/statistics/utils.py | 3 +-- module/ui/ui.py | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/module/config/config.py b/module/config/config.py index 25087912e9..f57aa0be02 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -11,12 +11,12 @@ from module.config.config_updater import ConfigUpdater from module.config.watcher import ConfigWatcher from module.config.utils import * -from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError +from module.exception import RequestHumanTakeover, ScriptError from module.logger import logger from module.map.map_grids import SelectedGrids -class TaskEnd(ALASBaseError): +class TaskEnd(Exception): pass diff --git a/module/device/method/ascreencap.py b/module/device/method/ascreencap.py index f0f3fb1264..24ba9902c0 100644 --- a/module/device/method/ascreencap.py +++ b/module/device/method/ascreencap.py @@ -8,11 +8,11 @@ from module.device.connection import Connection from module.device.method.utils import (ImageTruncated, RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep) -from module.exception import RequestHumanTakeover, ScriptError, ALASBaseError +from module.exception import RequestHumanTakeover, ScriptError from module.logger import logger -class AscreencapError(ALASBaseError): +class AscreencapError(Exception): pass diff --git a/module/device/method/droidcast.py b/module/device/method/droidcast.py index 57e3405347..43dad33cc0 100644 --- a/module/device/method/droidcast.py +++ b/module/device/method/droidcast.py @@ -11,11 +11,11 @@ from module.device.method.uiautomator_2 import ProcessInfo, Uiautomator2 from module.device.method.utils import ( ImageTruncated, PackageNotInstalled, RETRY_TRIES, handle_adb_error, handle_unknown_host_service, retry_sleep) -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger -class DroidCastVersionIncompatible(ALASBaseError): +class DroidCastVersionIncompatible(Exception): pass diff --git a/module/device/method/hermit.py b/module/device/method/hermit.py index 9ed994a4c1..8b1da67abc 100644 --- a/module/device/method/hermit.py +++ b/module/device/method/hermit.py @@ -10,11 +10,11 @@ from module.device.method.adb import Adb from module.device.method.utils import (RETRY_TRIES, handle_unknown_host_service, retry_sleep, HierarchyButton, handle_adb_error) -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger -class HermitError(ALASBaseError): +class HermitError(Exception): pass diff --git a/module/device/method/ldopengl.py b/module/device/method/ldopengl.py index e99800b825..4e46871730 100644 --- a/module/device/method/ldopengl.py +++ b/module/device/method/ldopengl.py @@ -11,15 +11,15 @@ from module.base.decorator import cached_property from module.device.method.utils import RETRY_TRIES, get_serial_pair, retry_sleep from module.device.platform import Platform -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger -class LDOpenGLIncompatible(ALASBaseError): +class LDOpenGLIncompatible(Exception): pass -class LDOpenGLError(ALASBaseError): +class LDOpenGLError(Exception): pass diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index 1357431b60..5e135fe399 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -11,7 +11,7 @@ from module.device.connection import Connection from module.device.method.minitouch import Command, CommandBuilder, insert_swipe from module.device.method.utils import RETRY_TRIES, handle_adb_error, retry_sleep -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger @@ -121,11 +121,11 @@ def end(self): self.device.sleep(self.DEFAULT_DELAY) -class MaaTouchNotInstalledError(ALASBaseError): +class MaaTouchNotInstalledError(Exception): pass -class MaaTouchSyncTimeout(ALASBaseError): +class MaaTouchSyncTimeout(Exception): pass diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index 73e52e03d3..732cc1bdd3 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -357,11 +357,11 @@ def _check_empty(self, text=None): return empty -class MinitouchNotInstalledError(ALASBaseError): +class MinitouchNotInstalledError(Exception): pass -class MinitouchOccupiedError(ALASBaseError): +class MinitouchOccupiedError(Exception): pass diff --git a/module/device/method/nemu_ipc.py b/module/device/method/nemu_ipc.py index 7b4eca9c30..86948783ab 100644 --- a/module/device/method/nemu_ipc.py +++ b/module/device/method/nemu_ipc.py @@ -15,15 +15,15 @@ from module.device.method.minitouch import insert_swipe, random_rectangle_point from module.device.method.utils import RETRY_TRIES, retry_sleep from module.device.platform import Platform -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger -class NemuIpcIncompatible(ALASBaseError): +class NemuIpcIncompatible(Exception): pass -class NemuIpcError(ALASBaseError): +class NemuIpcError(Exception): pass diff --git a/module/device/method/scrcpy/core.py b/module/device/method/scrcpy/core.py index 4bc65dfca9..499338b360 100644 --- a/module/device/method/scrcpy/core.py +++ b/module/device/method/scrcpy/core.py @@ -14,11 +14,11 @@ from module.device.method.scrcpy.control import ControlSender from module.device.method.scrcpy.options import ScrcpyOptions from module.device.method.utils import AdbConnection, recv_all -from module.exception import RequestHumanTakeover, ALASBaseError +from module.exception import RequestHumanTakeover from module.logger import logger -class ScrcpyError(ALASBaseError): +class ScrcpyError(Exception): pass diff --git a/module/device/method/utils.py b/module/device/method/utils.py index 7421b14988..dc8e7ae3be 100644 --- a/module/device/method/utils.py +++ b/module/device/method/utils.py @@ -49,7 +49,6 @@ def shell(self, from module.base.decorator import cached_property from module.logger import logger -from module.exception import ALASBaseError RETRY_TRIES = 5 RETRY_DELAY = 3 @@ -144,11 +143,11 @@ def possible_reasons(*args): logger.critical(f'Possible reason #{index}: {reason}') -class PackageNotInstalled(ALASBaseError): +class PackageNotInstalled(Exception): pass -class ImageTruncated(ALASBaseError): +class ImageTruncated(Exception): pass diff --git a/module/exception.py b/module/exception.py index be1272eb73..63921a6245 100644 --- a/module/exception.py +++ b/module/exception.py @@ -54,6 +54,8 @@ class GameNotRunningError(ALASBaseError): class GamePageUnknownError(ALASBaseError): + def __init__(self, message='Game page unknown'): + super().__init__(message) pass diff --git a/module/statistics/utils.py b/module/statistics/utils.py index 6936921029..da4aec4ad5 100644 --- a/module/statistics/utils.py +++ b/module/statistics/utils.py @@ -4,10 +4,9 @@ import numpy as np from module.base.utils import crop, image_size -from module.exception import ALASBaseError -class ImageError(ALASBaseError): +class ImageError(Exception): """ Error when parsing images """ pass diff --git a/module/ui/ui.py b/module/ui/ui.py index 8865513fbd..bfb8fe9ccc 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -219,7 +219,7 @@ def rotation_check(): logger.warning(f"Supported page: {[str(page) for page in Page.iter_pages()]}") logger.warning('Supported page: Any page with a "HOME" button on the upper-right') logger.critical("Please switch to a supported page before starting Alas") - raise GamePageUnknownError('Game page unknown') + raise GamePageUnknownError def ui_goto(self, destination, offset=(30, 30), skip_first_screenshot=True): """ From 0c1429ccfecef8d8e34e4485ab30ee2f37793cb1 Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 11 Oct 2024 08:03:44 +0800 Subject: [PATCH 5/6] Upd: Fix GamePageUnknownError and RequestHumanTakeover. --- module/exception.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/module/exception.py b/module/exception.py index 63921a6245..fbb7014e66 100644 --- a/module/exception.py +++ b/module/exception.py @@ -54,13 +54,11 @@ class GameNotRunningError(ALASBaseError): class GamePageUnknownError(ALASBaseError): - def __init__(self, message='Game page unknown'): - super().__init__(message) - pass - + def __init__(self, message='Game page unknown', *args): + super().__init__(message, *args) class RequestHumanTakeover(ALASBaseError): # Request human takeover # Alas is unable to handle such error, probably because of wrong settings. - def __init__(self, message='Request human takeover'): - super().__init__(message) + def __init__(self, message='Request human takeover', *args): + super().__init__(message, *args) From 327b4ec0e0bb836989c0d68bc41dd4efb3aef0ac Mon Sep 17 00:00:00 2001 From: PPPlatelet Date: Fri, 11 Oct 2024 13:36:40 +0800 Subject: [PATCH 6/6] Opt: Optimized the inheritance relationship of exception classes --- module/exception.py | 82 ++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/module/exception.py b/module/exception.py index fbb7014e66..d0a7b85b8e 100644 --- a/module/exception.py +++ b/module/exception.py @@ -1,64 +1,100 @@ -class ALASBaseError(Exception): +# ALASBaseException +# ├── ScriptError +# ├── ScriptEnd +# ├── EmulatorNotRunningError +# ├── RequestHumanTakeover +# ├── CampaignBaseException +# │ ├── CampaignEnd +# │ └── CampaignNameError +# ├── MapBaseException +# │ ├── MapDetectionError +# │ ├── MapWalkError +# │ └── MapEnemyMoved +# └── GameBaseException +# ├── GameStuckError +# ├── GameBugError +# ├── GameTooManyClickError +# ├── GameNotRunningError +# └── GamePageUnknownError + + +class ALASBaseException(Exception): pass -class CampaignEnd(ALASBaseError): +class ScriptError(ALASBaseException): + # This is likely to be a mistake of developers, but sometimes a random issue pass -class MapDetectionError(ALASBaseError): +class ScriptEnd(ALASBaseException): pass -class MapWalkError(ALASBaseError): +class EmulatorNotRunningError(ALASBaseException): pass -class MapEnemyMoved(ALASBaseError): +class RequestHumanTakeover(ALASBaseException): + # Request human takeover + # Alas is unable to handle such error, probably because of wrong settings. + def __init__(self, message='Request human takeover', *args): + super().__init__(message, *args) + + +# Campaign +class CampaignBaseException(ALASBaseException): pass -class CampaignNameError(ALASBaseError): +class CampaignEnd(CampaignBaseException): pass -class ScriptError(ALASBaseError): - # This is likely to be a mistake of developers, but sometimes a random issue +class CampaignNameError(CampaignBaseException): pass -class ScriptEnd(ALASBaseError): +# Map +class MapBaseException(ALASBaseException): pass -class GameStuckError(ALASBaseError): +class MapDetectionError(MapBaseException): pass -class GameBugError(ALASBaseError): - # An error has occurred in Azur Lane game client. Alas is unable to handle. - # A restart should fix it. +class MapWalkError(MapBaseException): pass -class GameTooManyClickError(ALASBaseError): +class MapEnemyMoved(MapBaseException): pass -class EmulatorNotRunningError(ALASBaseError): +# Game +class GameBaseException(ALASBaseException): pass -class GameNotRunningError(ALASBaseError): +class GameStuckError(GameBaseException): pass -class GamePageUnknownError(ALASBaseError): - def __init__(self, message='Game page unknown', *args): - super().__init__(message, *args) +class GameBugError(GameBaseException): + # An error has occurred in Azur Lane game client. Alas is unable to handle. + # A restart should fix it. + pass -class RequestHumanTakeover(ALASBaseError): - # Request human takeover - # Alas is unable to handle such error, probably because of wrong settings. - def __init__(self, message='Request human takeover', *args): + +class GameTooManyClickError(GameBaseException): + pass + + +class GameNotRunningError(GameBaseException): + pass + + +class GamePageUnknownError(GameBaseException): + def __init__(self, message='Game page unknown', *args): super().__init__(message, *args)