mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 11:19:26 +08:00
add: support game auto restart
This commit is contained in:
129
alas.py
129
alas.py
@@ -587,27 +587,6 @@ class AzurLaneAutoScript:
|
|||||||
|
|
||||||
|
|
||||||
from module.luahook.crack import *
|
from module.luahook.crack import *
|
||||||
from module.counter import *
|
|
||||||
|
|
||||||
|
|
||||||
class FailedTaskCounterManager:
|
|
||||||
def __init__(self, config: AzurLaneConfig):
|
|
||||||
self.task_counter = {}
|
|
||||||
|
|
||||||
if config.full_config.Restart_GameRestart_Enable:
|
|
||||||
self.counter_max_count = config.full_config.Restart_GameRestart_MaxRetryTimes
|
|
||||||
self.counter_class = MaxCounter
|
|
||||||
else:
|
|
||||||
self.counter_max_count = 0
|
|
||||||
self.counter_class = Counter
|
|
||||||
|
|
||||||
def count(self, task, throw=True) -> bool:
|
|
||||||
counter = self.task_counter.get(task, self.counter_class(self.counter_max_count))
|
|
||||||
return counter.count_once(throw=throw)
|
|
||||||
|
|
||||||
def reset(self, task):
|
|
||||||
counter = self.task_counter.get(task, self.counter_class(self.counter_max_count))
|
|
||||||
counter.reset()
|
|
||||||
|
|
||||||
|
|
||||||
class AzurLaneAutoScript(AzurLaneAutoScript):
|
class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||||
@@ -623,7 +602,9 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
|||||||
elif self.class_name == "ArknightsAutoScript":
|
elif self.class_name == "ArknightsAutoScript":
|
||||||
self.is_ark = True
|
self.is_ark = True
|
||||||
|
|
||||||
self.failed_task_counter = FailedTaskCounterManager(self.config)
|
full_config = self.config.full_config
|
||||||
|
self.is_fatal_error_restart = full_config.Restart_GameRestart_FatalErrorRestart
|
||||||
|
self.max_retry_times_for_same_task_failed = full_config.Restart_GameRestart_MaxRetryTimesForSameTaskFailed
|
||||||
|
|
||||||
def pre_init(self):
|
def pre_init(self):
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -680,12 +661,18 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
|||||||
if self.checker.is_available():
|
if self.checker.is_available():
|
||||||
logger.critical('Game page unknown')
|
logger.critical('Game page unknown')
|
||||||
self.save_error_log()
|
self.save_error_log()
|
||||||
handle_notify(
|
if self.is_fatal_error_restart:
|
||||||
self.config.Error_OnePushConfig,
|
logger.info("Fatal error occured, call restart")
|
||||||
title=f"Alas <{self.config_name}> crashed",
|
self.config.task_call('Restart')
|
||||||
content=f"<{self.config_name}> GamePageUnknownError",
|
self.device.sleep(10)
|
||||||
)
|
return False
|
||||||
exit(1)
|
else:
|
||||||
|
handle_notify(
|
||||||
|
self.config.Error_OnePushConfig,
|
||||||
|
title=f"Alas <{self.config_name}> crashed",
|
||||||
|
content=f"<{self.config_name}> GamePageUnknownError",
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
else:
|
else:
|
||||||
self.checker.wait_until_available()
|
self.checker.wait_until_available()
|
||||||
return False
|
return False
|
||||||
@@ -693,31 +680,49 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
|||||||
def handle_ScriptError(self, e) -> bool:
|
def handle_ScriptError(self, e) -> bool:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
logger.critical('This is likely to be a mistake of developers, but sometimes just random issues')
|
logger.critical('This is likely to be a mistake of developers, but sometimes just random issues')
|
||||||
handle_notify(
|
if self.is_fatal_error_restart:
|
||||||
self.config.Error_OnePushConfig,
|
logger.info("Fatal error occured, call restart")
|
||||||
title=f"Alas <{self.config_name}> crashed",
|
self.config.task_call('Restart')
|
||||||
content=f"<{self.config_name}> ScriptError",
|
self.device.sleep(10)
|
||||||
)
|
return False
|
||||||
exit(1)
|
else:
|
||||||
|
handle_notify(
|
||||||
|
self.config.Error_OnePushConfig,
|
||||||
|
title=f"Alas <{self.config_name}> crashed",
|
||||||
|
content=f"<{self.config_name}> ScriptError",
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def handle_RequestHumanTakeover(self, e) -> bool:
|
def handle_RequestHumanTakeover(self, e) -> bool:
|
||||||
logger.critical('Request human takeover')
|
logger.critical('Request human takeover')
|
||||||
handle_notify(
|
if self.is_fatal_error_restart:
|
||||||
self.config.Error_OnePushConfig,
|
logger.info("Fatal error occured, call restart")
|
||||||
title=f"Alas <{self.config_name}> crashed",
|
self.config.task_call('Restart')
|
||||||
content=f"<{self.config_name}> RequestHumanTakeover",
|
self.device.sleep(10)
|
||||||
)
|
return False
|
||||||
exit(1)
|
else:
|
||||||
|
handle_notify(
|
||||||
|
self.config.Error_OnePushConfig,
|
||||||
|
title=f"Alas <{self.config_name}> crashed",
|
||||||
|
content=f"<{self.config_name}> RequestHumanTakeover",
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def handle_Exception(self, e) -> bool:
|
def handle_Exception(self, e) -> bool:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
self.save_error_log()
|
self.save_error_log()
|
||||||
handle_notify(
|
if self.is_fatal_error_restart:
|
||||||
self.config.Error_OnePushConfig,
|
logger.info("Fatal error occured, call restart")
|
||||||
title=f"Alas <{self.config_name}> crashed",
|
self.config.task_call('Restart')
|
||||||
content=f"<{self.config_name}> Exception occured",
|
self.device.sleep(10)
|
||||||
)
|
return False
|
||||||
exit(1)
|
else:
|
||||||
|
handle_notify(
|
||||||
|
self.config.Error_OnePushConfig,
|
||||||
|
title=f"Alas <{self.config_name}> crashed",
|
||||||
|
content=f"<{self.config_name}> Exception occured",
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def run(self, command, skip_first_screenshot=False):
|
def run(self, command, skip_first_screenshot=False):
|
||||||
try:
|
try:
|
||||||
@@ -863,23 +868,25 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
|||||||
logger.info(f'Scheduler: End task `{task}`')
|
logger.info(f'Scheduler: End task `{task}`')
|
||||||
self.is_first_task = False
|
self.is_first_task = False
|
||||||
|
|
||||||
if not success:
|
# Check failures
|
||||||
if not self.failed_task_counter.count(task, throw=False):
|
failed = deep_get(self.failure_record, keys=task, default=0)
|
||||||
logger.critical(f"Task `{task}` failed 3 or more times.")
|
failed = 0 if success else failed + 1
|
||||||
logger.critical("Possible reason #1: You haven't used it correctly. "
|
deep_set(self.failure_record, keys=task, value=failed)
|
||||||
"Please read the help text of the options.")
|
if failed >= self.max_retry_times_for_same_task_failed:
|
||||||
logger.critical("Possible reason #2: There is a problem with this task. "
|
logger.critical(f"Task `{task}` failed {self.max_retry_times_for_same_task_failed} or more times.")
|
||||||
"Please contact developers or try to fix it yourself.")
|
logger.critical("Possible reason #1: You haven't used it correctly. "
|
||||||
logger.critical('Request human takeover')
|
"Please read the help text of the options.")
|
||||||
handle_notify(
|
logger.critical("Possible reason #2: There is a problem with this task. "
|
||||||
self.config.Error_OnePushConfig,
|
"Please contact developers or try to fix it yourself.")
|
||||||
title=f"Alas <{self.config_name}> crashed",
|
logger.critical('Request human takeover')
|
||||||
content=f"<{self.config_name}> RequestHumanTakeover\nTask `{task}` failed 3 or more times.",
|
handle_notify(
|
||||||
)
|
self.config.Error_OnePushConfig,
|
||||||
exit(1)
|
title=f"Alas <{self.config_name}> crashed",
|
||||||
|
content=f"<{self.config_name}> RequestHumanTakeover\nTask `{task}` failed {self.max_retry_times_for_same_task_failed} or more times.",
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
self.failed_task_counter.reset(task)
|
|
||||||
del_cached_property(self, 'config')
|
del_cached_property(self, 'config')
|
||||||
continue
|
continue
|
||||||
elif self.config.Error_HandleError:
|
elif self.config.Error_HandleError:
|
||||||
|
|||||||
@@ -74,9 +74,8 @@
|
|||||||
"ServerUpdate": "00:00"
|
"ServerUpdate": "00:00"
|
||||||
},
|
},
|
||||||
"GameRestart": {
|
"GameRestart": {
|
||||||
"Enable": false,
|
"FatalErrorRestart": false,
|
||||||
"MaxRetryTimes": 5,
|
"MaxRetryTimesForSameTaskFailed": 5
|
||||||
"Notify": false
|
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
"Enable": false,
|
"Enable": false,
|
||||||
|
|||||||
@@ -414,17 +414,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"GameRestart": {
|
"GameRestart": {
|
||||||
"Enable": {
|
"FatalErrorRestart": {
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
"MaxRetryTimes": {
|
"MaxRetryTimesForSameTaskFailed": {
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"value": 5
|
"value": 5
|
||||||
},
|
|
||||||
"Notify": {
|
|
||||||
"type": "checkbox",
|
|
||||||
"value": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
|
|||||||
@@ -844,9 +844,8 @@ PowerLimit:
|
|||||||
Raid: 25000
|
Raid: 25000
|
||||||
Ash: 25000
|
Ash: 25000
|
||||||
GameRestart:
|
GameRestart:
|
||||||
Enable: false
|
FatalErrorRestart: false
|
||||||
MaxRetryTimes: 5
|
MaxRetryTimesForSameTaskFailed: 5
|
||||||
Notify: false
|
|
||||||
InstanceRestart:
|
InstanceRestart:
|
||||||
Enable: false
|
Enable: false
|
||||||
MaxRetryTimes: 5
|
MaxRetryTimes: 5
|
||||||
|
|||||||
@@ -522,9 +522,8 @@ class GeneratedConfig:
|
|||||||
PowerLimit_Ash = 25000
|
PowerLimit_Ash = 25000
|
||||||
|
|
||||||
# Group `GameRestart`
|
# Group `GameRestart`
|
||||||
GameRestart_Enable = False
|
GameRestart_FatalErrorRestart = False
|
||||||
GameRestart_MaxRetryTimes = 5
|
GameRestart_MaxRetryTimesForSameTaskFailed = 5
|
||||||
GameRestart_Notify = False
|
|
||||||
|
|
||||||
# Group `InstanceRestart`
|
# Group `InstanceRestart`
|
||||||
InstanceRestart_Enable = False
|
InstanceRestart_Enable = False
|
||||||
|
|||||||
@@ -57,9 +57,8 @@ class FullGeneratedConfig:
|
|||||||
Restart_Scheduler_SuccessInterval = None
|
Restart_Scheduler_SuccessInterval = None
|
||||||
Restart_Scheduler_FailureInterval = None
|
Restart_Scheduler_FailureInterval = None
|
||||||
Restart_Scheduler_ServerUpdate = None
|
Restart_Scheduler_ServerUpdate = None
|
||||||
Restart_GameRestart_Enable = None
|
Restart_GameRestart_FatalErrorRestart = None
|
||||||
Restart_GameRestart_MaxRetryTimes = None
|
Restart_GameRestart_MaxRetryTimesForSameTaskFailed = None
|
||||||
Restart_GameRestart_Notify = None
|
|
||||||
Restart_InstanceRestart_Enable = None
|
Restart_InstanceRestart_Enable = None
|
||||||
Restart_InstanceRestart_MaxRetryTimes = None
|
Restart_InstanceRestart_MaxRetryTimes = None
|
||||||
Restart_InstanceRestart_Notify = None
|
Restart_InstanceRestart_Notify = None
|
||||||
|
|||||||
@@ -2922,17 +2922,13 @@
|
|||||||
"name": "GameRestart._info.name",
|
"name": "GameRestart._info.name",
|
||||||
"help": "GameRestart._info.help"
|
"help": "GameRestart._info.help"
|
||||||
},
|
},
|
||||||
"Enable": {
|
"FatalErrorRestart": {
|
||||||
"name": "GameRestart.Enable.name",
|
"name": "GameRestart.FatalErrorRestart.name",
|
||||||
"help": "GameRestart.Enable.help"
|
"help": "GameRestart.FatalErrorRestart.help"
|
||||||
},
|
},
|
||||||
"MaxRetryTimes": {
|
"MaxRetryTimesForSameTaskFailed": {
|
||||||
"name": "GameRestart.MaxRetryTimes.name",
|
"name": "GameRestart.MaxRetryTimesForSameTaskFailed.name",
|
||||||
"help": "GameRestart.MaxRetryTimes.help"
|
"help": "GameRestart.MaxRetryTimesForSameTaskFailed.help"
|
||||||
},
|
|
||||||
"Notify": {
|
|
||||||
"name": "GameRestart.Notify.name",
|
|
||||||
"help": "GameRestart.Notify.help"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
|
|||||||
@@ -2922,17 +2922,13 @@
|
|||||||
"name": "GameRestart._info.name",
|
"name": "GameRestart._info.name",
|
||||||
"help": "GameRestart._info.help"
|
"help": "GameRestart._info.help"
|
||||||
},
|
},
|
||||||
"Enable": {
|
"FatalErrorRestart": {
|
||||||
"name": "GameRestart.Enable.name",
|
"name": "GameRestart.FatalErrorRestart.name",
|
||||||
"help": "GameRestart.Enable.help"
|
"help": "GameRestart.FatalErrorRestart.help"
|
||||||
},
|
},
|
||||||
"MaxRetryTimes": {
|
"MaxRetryTimesForSameTaskFailed": {
|
||||||
"name": "GameRestart.MaxRetryTimes.name",
|
"name": "GameRestart.MaxRetryTimesForSameTaskFailed.name",
|
||||||
"help": "GameRestart.MaxRetryTimes.help"
|
"help": "GameRestart.MaxRetryTimesForSameTaskFailed.help"
|
||||||
},
|
|
||||||
"Notify": {
|
|
||||||
"name": "GameRestart.Notify.name",
|
|
||||||
"help": "GameRestart.Notify.help"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
|
|||||||
@@ -2922,17 +2922,13 @@
|
|||||||
"name": "游戏重启",
|
"name": "游戏重启",
|
||||||
"help": "该功能的启用和关闭需要重启这个Alas实例"
|
"help": "该功能的启用和关闭需要重启这个Alas实例"
|
||||||
},
|
},
|
||||||
"Enable": {
|
"FatalErrorRestart": {
|
||||||
"name": "启用",
|
"name": "致命错误重启",
|
||||||
"help": ""
|
"help": ""
|
||||||
},
|
},
|
||||||
"MaxRetryTimes": {
|
"MaxRetryTimesForSameTaskFailed": {
|
||||||
"name": "最大尝试重启次数",
|
"name": "同一个任务最多重启 X 次",
|
||||||
"help": ""
|
"help": ""
|
||||||
},
|
|
||||||
"Notify": {
|
|
||||||
"name": "重启时通知",
|
|
||||||
"help": "不建议开启,防止消息轰炸"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
|
|||||||
@@ -2922,17 +2922,13 @@
|
|||||||
"name": "GameRestart._info.name",
|
"name": "GameRestart._info.name",
|
||||||
"help": "GameRestart._info.help"
|
"help": "GameRestart._info.help"
|
||||||
},
|
},
|
||||||
"Enable": {
|
"FatalErrorRestart": {
|
||||||
"name": "GameRestart.Enable.name",
|
"name": "GameRestart.FatalErrorRestart.name",
|
||||||
"help": "GameRestart.Enable.help"
|
"help": "GameRestart.FatalErrorRestart.help"
|
||||||
},
|
},
|
||||||
"MaxRetryTimes": {
|
"MaxRetryTimesForSameTaskFailed": {
|
||||||
"name": "GameRestart.MaxRetryTimes.name",
|
"name": "GameRestart.MaxRetryTimesForSameTaskFailed.name",
|
||||||
"help": "GameRestart.MaxRetryTimes.help"
|
"help": "GameRestart.MaxRetryTimesForSameTaskFailed.help"
|
||||||
},
|
|
||||||
"Notify": {
|
|
||||||
"name": "GameRestart.Notify.name",
|
|
||||||
"help": "GameRestart.Notify.help"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"InstanceRestart": {
|
"InstanceRestart": {
|
||||||
|
|||||||
Reference in New Issue
Block a user