|
@@ -351,9 +351,17 @@ class Script:
|
|
|
self.device.release_during_wait()
|
|
self.device.release_during_wait()
|
|
|
return self.wait_until(next_run)
|
|
return self.wait_until(next_run)
|
|
|
|
|
|
|
|
|
|
+ def exception_handler(self, e: Exception, command: str) -> None:
|
|
|
|
|
+ # 处理御魂溢出
|
|
|
|
|
+ from tasks.Utils.post_diagnotor import PostDiagnotor, AnalyzeType
|
|
|
|
|
+ image = getattr(self.device, 'image', None)
|
|
|
|
|
+ analyse_type = PostDiagnotor().handle(e=e, command=command, image=image)
|
|
|
|
|
+ if analyse_type == AnalyzeType.SoulOverflow:
|
|
|
|
|
+ self.config.task_call('SoulsTidy')
|
|
|
|
|
+ time.sleep(1)
|
|
|
|
|
+
|
|
|
def run(self, command: str) -> bool:
|
|
def run(self, command: str) -> bool:
|
|
|
"""
|
|
"""
|
|
|
-
|
|
|
|
|
:param command: 大写驼峰命名的任务名字
|
|
:param command: 大写驼峰命名的任务名字
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
@@ -371,11 +379,13 @@ class Script:
|
|
|
return True
|
|
return True
|
|
|
except GameNotRunningError as e:
|
|
except GameNotRunningError as e:
|
|
|
logger.warning(e)
|
|
logger.warning(e)
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
self.config.task_call('Restart')
|
|
self.config.task_call('Restart')
|
|
|
return True
|
|
return True
|
|
|
except (GameStuckError, GameTooManyClickError) as e:
|
|
except (GameStuckError, GameTooManyClickError) as e:
|
|
|
logger.error(e)
|
|
logger.error(e)
|
|
|
self.save_error_log()
|
|
self.save_error_log()
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
logger.warning(f'Game stuck, {self.device.package} will be restarted in 10 seconds')
|
|
logger.warning(f'Game stuck, {self.device.package} will be restarted in 10 seconds')
|
|
|
logger.warning('If you are playing by hand, please stop Alas')
|
|
logger.warning('If you are playing by hand, please stop Alas')
|
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> GameStuckError or GameTooManyClickError")
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> GameStuckError or GameTooManyClickError")
|
|
@@ -385,32 +395,37 @@ class Script:
|
|
|
except GameBugError as e:
|
|
except GameBugError as e:
|
|
|
logger.warning(e)
|
|
logger.warning(e)
|
|
|
self.save_error_log()
|
|
self.save_error_log()
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
logger.warning('An error has occurred in Azur Lane game client, Alas is unable to handle')
|
|
logger.warning('An error has occurred in Azur Lane game client, Alas is unable to handle')
|
|
|
logger.warning(f'Restarting {self.device.package} to fix it')
|
|
logger.warning(f'Restarting {self.device.package} to fix it')
|
|
|
self.config.task_call('Restart')
|
|
self.config.task_call('Restart')
|
|
|
self.device.sleep(10)
|
|
self.device.sleep(10)
|
|
|
return False
|
|
return False
|
|
|
- except GamePageUnknownError:
|
|
|
|
|
|
|
+ except GamePageUnknownError as e:
|
|
|
logger.info('Game server may be under maintenance or network may be broken, check server status now')
|
|
logger.info('Game server may be under maintenance or network may be broken, check server status now')
|
|
|
# 这个还不重要 留着坑填
|
|
# 这个还不重要 留着坑填
|
|
|
logger.critical('Game page unknown')
|
|
logger.critical('Game page unknown')
|
|
|
self.save_error_log()
|
|
self.save_error_log()
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> GamePageUnknownError")
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> GamePageUnknownError")
|
|
|
self.config.task_call('Restart')
|
|
self.config.task_call('Restart')
|
|
|
self.device.sleep(10)
|
|
self.device.sleep(10)
|
|
|
return False
|
|
return False
|
|
|
except ScriptError as e:
|
|
except ScriptError as e:
|
|
|
logger.critical(e)
|
|
logger.critical(e)
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
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')
|
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> ScriptError")
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> ScriptError")
|
|
|
exit(1)
|
|
exit(1)
|
|
|
except RequestHumanTakeover as e:
|
|
except RequestHumanTakeover as e:
|
|
|
logger.critical(e)
|
|
logger.critical(e)
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
logger.critical('Request human takeover')
|
|
logger.critical('Request human takeover')
|
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> RequestHumanTakeover")
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> RequestHumanTakeover")
|
|
|
exit(1)
|
|
exit(1)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.exception(e)
|
|
logger.exception(e)
|
|
|
|
|
+ self.exception_handler(e=e, command=command)
|
|
|
self.save_error_log()
|
|
self.save_error_log()
|
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> Exception occured")
|
|
self.config.notifier.push(title=f'{I18n.trans_zh_cn(command)}{command}', content=f"<{self.config_name}> Exception occured")
|
|
|
exit(1)
|
|
exit(1)
|
|
@@ -460,8 +475,6 @@ class Script:
|
|
|
|
|
|
|
|
# Get task
|
|
# Get task
|
|
|
task = self.get_next_task()
|
|
task = self.get_next_task()
|
|
|
- # 更新 gui的任务
|
|
|
|
|
- # Init device and change server
|
|
|
|
|
_ = self.device
|
|
_ = self.device
|
|
|
# Skip first restart
|
|
# Skip first restart
|
|
|
if self.is_first_task and task == 'Restart':
|
|
if self.is_first_task and task == 'Restart':
|
|
@@ -526,6 +539,5 @@ class Script:
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- script = Script("oas1")
|
|
|
|
|
- print(script.gui_task_list())
|
|
|
|
|
- print(script.config.gui_menu)
|
|
|
|
|
|
|
+ script = Script("oas2")
|
|
|
|
|
+ script.loop()
|