From 290b7174ebf43e5e811334a8326bc527aada28df Mon Sep 17 00:00:00 2001 From: EightyDollars Date: Sat, 4 Nov 2023 15:40:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E8=B0=83=E6=95=B4=E5=85=AC=E6=8B=9B?= =?UTF-8?q?=E7=AD=89=E4=BB=BB=E5=8A=A1=E8=B0=83=E7=94=A8=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/__main__.py | 36 +++++++++++++++--------- arknights_mower/command.py | 2 +- arknights_mower/solvers/base_schedule.py | 34 ++++++++++------------ arknights_mower/solvers/report.py | 11 ++++++-- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/arknights_mower/__main__.py b/arknights_mower/__main__.py index 23079ca8e..88613de95 100644 --- a/arknights_mower/__main__.py +++ b/arknights_mower/__main__.py @@ -337,20 +337,28 @@ def simulate(): set_recruit_options(base_scheduler, new_conf) set_skland_options(base_scheduler, new_conf) - if sleep_time > 540 and base_scheduler.maa_config["maa_enable"] == 1: - subject = ( - f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}" - ) - context = f"下一次任务:{base_scheduler.tasks[0].plan}" - logger.info(context) - logger.info(subject) - body = task_template.render( - tasks=[ - obj.format(timezone_offset) for obj in base_scheduler.tasks - ] - ) - base_scheduler.send_message(body, subject, "html") - base_scheduler.maa_plan_solver() + if sleep_time > 540: + if base_scheduler.daily_mission is False: + base_scheduler.daily_mission = base_scheduler.read_report() + base_scheduler.mail_plan_solver() + if base_scheduler.skland_config["skland_enable"] == 1: + base_scheduler.skland_plan_solover() + if base_scheduler.recruit_config['recruit_enable'] == 1: + base_scheduler.recruit_plan_solver() + if base_scheduler.maa_config["maa_enable"] == 1: + subject = ( + f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}" + ) + context = f"下一次任务:{base_scheduler.tasks[0].plan}" + logger.info(context) + logger.info(subject) + body = task_template.render( + tasks=[ + obj.format(timezone_offset) for obj in base_scheduler.tasks + ] + ) + base_scheduler.send_message(body, subject, "html") + base_scheduler.maa_plan_solver() elif sleep_time > 0: subject = f"休息 {format_time(remaining_time)},到{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}开始工作" context = f"下一次任务:{base_scheduler.tasks[0].plan}" diff --git a/arknights_mower/command.py b/arknights_mower/command.py index cf82f4b2c..41fb2885a 100644 --- a/arknights_mower/command.py +++ b/arknights_mower/command.py @@ -102,7 +102,7 @@ def recruit(args: list[str] = [], send_message_config={}, recruit_config={}, dev def daily_report(device: Device = None): - ReportSolver(device).run() + return ReportSolver(device).run() def mission(args: list[str] = [], device: Device = None): diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 14f218093..20c41e9bf 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -14,7 +14,7 @@ from email.mime.multipart import MIMEMultipart from .skland import SKLand -from ..command import recruit, daily_report +from ..command import recruit, daily_report, mail from ..data import agent_list, base_room_list, ocr_error from ..utils import character_recognize, detector, segment from ..utils.digit_reader import DigitReader @@ -92,9 +92,10 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None: self.refresh_connecting = False self.recruit_config = {} self.skland_config = {} - self.sk_time = None + self.recruit_time = None + self.daily_mission = False def run(self) -> None: """ :param clue_collect: bool, 是否收取线索 @@ -2288,30 +2289,16 @@ def append_maa_task(self, type): }) def maa_plan_solver(self, tasks='All', one_time=False): try: - if not one_time and 'last_execution' in self.maa_config and self.maa_config['last_execution'] is not None and datetime.now() - timedelta( + if not one_time and 'last_execution' in self.maa_config and self.maa_config[ seconds=self.maa_config['maa_execution_gap'] * 3600) < self.maa_config['last_execution']: logger.info("间隔未超过设定时间,不启动maa") else: - daily_report() - - """森空岛签到""" - try: - if self.skland_config['skland_enable']: - skland = SKLand(self.skland_config['skland_info']) - skland.attendance() - except RuntimeError as e: - logger.info("森空岛签到失败:{}".format(e.__str__())) - - """测试公招用""" - if self.recruit_config['recruit_enable']: - recruit([], self.send_message_config, self.recruit_config) - self.send_message('启动MAA') self.back_to_index() # 任务及参数请参考 docs/集成文档.md self.initialize_maa() if tasks == 'All': - tasks = ['StartUp','Fight', 'Visit', 'Mall', 'Award','Depot'] + tasks = ['StartUp', 'Fight', 'Visit', 'Mall', 'Award', 'Depot'] # tasks = ['StartUp', 'Fight', 'Recruit', 'Visit', 'Mall', 'Award'] for maa_task in tasks: if maa_task == 'Recruit': @@ -2466,4 +2453,13 @@ def maa_plan_solver(self, tasks='All', one_time=False): def skland_plan_solover(self): skland = SKLand(self.skland_config['skland_info']) skland.attendance() - del self.tasks[0] + + def recruit_plan_solver(self): + recruit([], self.send_message_config, self.recruit_config) + + def read_report(self): + return daily_report() + + def mail_plan_solver(self): + mail([]) + diff --git a/arknights_mower/solvers/report.py b/arknights_mower/solvers/report.py index 960724ace..d9fce2ded 100644 --- a/arknights_mower/solvers/report.py +++ b/arknights_mower/solvers/report.py @@ -41,15 +41,18 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None: 'riic_orundum_order': "贸易站合成玉订单", } - def run(self) -> None: + + def run(self) -> bool: if self.is_today_recorded(): - return + return True try: super().run() + return self.record_report() except TypeError: logger.error("基报识别失败 润!") except PermissionError: logger.error("基报记录访问失败") + return False def is_today_recorded(self) -> bool: if os.path.exists(self.record_path) is not True: @@ -150,7 +153,7 @@ def read_report(self): self.report_res[item] = res self.report_res['riic_iron_number'] = int(int(self.report_res['riic_iron']) / 500) - self.record_report() + def record_report(self): logger.debug(f"存入数据{self.report_res}") @@ -164,3 +167,5 @@ def record_report(self): csv_writer.writerow(self.riic_key_str) csv_writer.writerow(self.report_res) file.close() + logger.info("{}的基报记录完成".format(self.report_res['riic_date'])) + return True