mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 10:58:21 +08:00
Fix: Stop scheduler if a task failed 3 or more times
- Add: Clear click record - Opt: Check the type of user setting and display invalid settings
This commit is contained in:
@@ -81,6 +81,7 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig):
|
||||
|
||||
def load(self):
|
||||
self.data = self.read_file(self.config_name)
|
||||
ConfigTypeChecker.check(self.data)
|
||||
|
||||
for path, value in self.modified.items():
|
||||
deep_set(self.data, keys=path, value=value)
|
||||
@@ -489,3 +490,32 @@ class MultiSetWrapper:
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.main.update()
|
||||
self.main.auto_update = True
|
||||
|
||||
|
||||
class ConfigTypeChecker:
|
||||
checkers = [
|
||||
(['Scheduler', 'NextRun'], datetime),
|
||||
(['Emotion', 'Fleet1Record'], datetime),
|
||||
(['Emotion', 'Fleet2Record'], datetime),
|
||||
(['Exercise', 'OpponentRefreshRecord'], datetime),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def check(cls, data):
|
||||
"""
|
||||
Args:
|
||||
data (dict): User config.
|
||||
|
||||
Raises:
|
||||
RequestHumanTakeover: If there's invalid setting.
|
||||
"""
|
||||
for func, func_data in data.items():
|
||||
for path, typ in cls.checkers:
|
||||
value = deep_get(func_data, keys=path, default=None)
|
||||
if value is None:
|
||||
continue
|
||||
if not isinstance(value, typ):
|
||||
logger.critical(f'Task `{func}` has an invalid setting {".".join(path)}="{str(value)}". '
|
||||
f'Current type: {type_to_str(value)}, expected type: {type_to_str(typ)}')
|
||||
logger.critical('Please check your settings')
|
||||
raise RequestHumanTakeover
|
||||
|
||||
@@ -439,3 +439,19 @@ def to_list(text, length=1):
|
||||
return [int(text)] * length
|
||||
out = [int(letter.strip()) for letter in text.split(',')]
|
||||
return out
|
||||
|
||||
|
||||
def type_to_str(typ):
|
||||
"""
|
||||
Convert any types or any objects to a string。
|
||||
Remove <> to prevent them from being parsed as HTML tags.
|
||||
|
||||
Args:
|
||||
typ:
|
||||
|
||||
Returns:
|
||||
str: Such as `int`, 'datetime.datetime'.
|
||||
"""
|
||||
if not isinstance(typ, type):
|
||||
typ = type(typ)
|
||||
return str(typ).strip("<class '>").replace('<', '_').replace('>', '_')
|
||||
|
||||
@@ -45,14 +45,19 @@ class Control(MiniTouch):
|
||||
if count[0][1] >= 12:
|
||||
logger.warning(f'Too many click for a button: {count[0][0]}')
|
||||
logger.warning(f'History click: {[str(prev) for prev in self.click_record]}')
|
||||
self.click_record_clear()
|
||||
raise GameTooManyClickError(f'Too many click for a button: {count[0][0]}')
|
||||
if len(count) >= 2 and count[0][1] >= 6 and count[1][1] >= 6:
|
||||
logger.warning(f'Too many click between 2 buttons: {count[0][0]}, {count[1][0]}')
|
||||
logger.warning(f'History click: {[str(prev) for prev in self.click_record]}')
|
||||
self.click_record_clear()
|
||||
raise GameTooManyClickError(f'Too many click between 2 buttons: {count[0][0]}, {count[1][0]}')
|
||||
|
||||
return False
|
||||
|
||||
def click_record_clear(self):
|
||||
self.click_record.clear()
|
||||
|
||||
def click(self, button, record_check=True):
|
||||
"""Method to click a button.
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ class LoginHandler(Combat):
|
||||
"""
|
||||
for _ in range(3):
|
||||
self.device.stuck_record_clear()
|
||||
self.device.click_record_clear()
|
||||
try:
|
||||
self._handle_app_login()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user