AzurLaneAutoScript/alas.py

117 lines
3.8 KiB
Python
Raw Normal View History

import time
2021-09-14 17:32:23 +08:00
import inflection
from cached_property import cached_property
from module.campaign.gems_farming import GemsFarming
from module.campaign.run import CampaignRun
2021-09-14 17:32:23 +08:00
from module.commission.commission import RewardCommission
from module.config.config import AzurLaneConfig, TaskEnd
from module.config.db import Database
from module.device.device import Device
from module.exception import *
from module.handler.login import LoginHandler
2021-09-14 17:32:23 +08:00
from module.logger import logger
from module.research.research import RewardResearch
from module.tactical.tactical_class import RewardTacticalClass
from module.ui.ui import UI, page_main
2020-06-17 00:36:05 +08:00
class AzurLaneAutoScript:
2021-09-14 17:32:23 +08:00
def __init__(self, config_name='alas'):
self.config_name = config_name
Database().update_config(config_name)
@cached_property
def config(self):
config = AzurLaneConfig(config_name=self.config_name)
return config
@cached_property
def device(self):
device = Device(config=self.config)
return device
2020-03-29 01:22:46 +08:00
def run(self, command):
while 1:
try:
2021-09-14 17:32:23 +08:00
self.__getattribute__(command)()
UI(config=self.config, device=self.device).ui_ensure(page_main)
2021-09-14 17:32:23 +08:00
return True
except TaskEnd:
return True
except GameNotRunningError as e:
logger.warning(e)
az = LoginHandler(self.config, device=self.device)
az.app_restart()
az.ensure_no_unfinished_campaign()
continue
except GameTooManyClickError as e:
logger.warning(e)
self.save_error_log()
az = LoginHandler(self.config, device=self.device)
az.handle_game_stuck()
continue
except GameStuckError as e:
logger.warning(e)
self.save_error_log()
az = LoginHandler(self.config, device=self.device)
az.handle_game_stuck()
continue
except LogisticsRefreshBugHandler as e:
logger.warning(e)
self.save_error_log()
az = LoginHandler(self.config, device=self.device)
az.device.app_stop()
time.sleep(600)
az.app_ensure_start()
continue
except Exception as e:
logger.exception(e)
self.save_error_log()
2021-09-14 17:32:23 +08:00
return False
def save_error_log(self):
"""
Save last 60 screenshots in ./log/error/<timestamp>
Save logs to ./log/error/<timestamp>/log.txt
"""
2021-09-14 17:32:23 +08:00
pass
2021-09-14 17:32:23 +08:00
def research(self):
RewardResearch(config=self.config, device=self.device).run()
2021-09-14 17:32:23 +08:00
def commission(self):
RewardCommission(config=self.config, device=self.device).run()
2021-09-14 17:32:23 +08:00
def tactical(self):
RewardTacticalClass(config=self.config, device=self.device).run()
def main(self):
CampaignRun(config=self.config, device=self.device).run(
name=self.config.Campaign_Name,
folder=self.config.Campaign_Event,
mode=self.config.Campaign_Mode)
def gems_farming(self):
GemsFarming(config=self.config, device=self.device).run(
name=self.config.Campaign_Name,
folder=self.config.Campaign_Event,
mode=self.config.Campaign_Mode)
2021-09-14 17:32:23 +08:00
def loop(self):
while 1:
logger.info(f'Scheduler: Start task `{self.config.task}`')
success = self.run(inflection.underscore(self.config.task))
2021-09-14 17:32:23 +08:00
logger.info(f'Scheduler: End task `{self.config.task}`')
del self.__dict__['config']
2021-09-14 17:32:23 +08:00
if not success:
break
2021-04-17 22:20:21 +08:00
2021-09-14 17:32:23 +08:00
if __name__ == '__main__':
alas = AzurLaneAutoScript()
alas.loop()