diff --git a/arknights_mower/__main__.py b/arknights_mower/__main__.py index c1c87018..1acb11a7 100644 --- a/arknights_mower/__main__.py +++ b/arknights_mower/__main__.py @@ -22,7 +22,6 @@ from arknights_mower.utils.simulator import restart_simulator base_scheduler = None -conf = config.conf operators = config.operators @@ -51,6 +50,7 @@ def initialize(tasks, scheduler=None): base_scheduler.operators = {} plan1 = {} plan = config.plan + conf = config.conf plan_config = PlanConfig( plan["conf"]["rest_in_full"], plan["conf"]["exhaust_require"], @@ -248,13 +248,13 @@ def simulate(): base_scheduler.daily_report < (datetime.now() - timedelta(hours=4)).date() ): - if base_scheduler.report_plan_solver(conf.send_report): + if base_scheduler.report_plan_solver(): base_scheduler.daily_report = ( datetime.now() - timedelta(hours=4) ).date() if ( - conf.skland_enable + config.conf.skland_enable and base_scheduler.daily_skland < (datetime.now() - timedelta(hours=4)).date() ): @@ -273,7 +273,7 @@ def simulate(): datetime.now() - timedelta(hours=8) ).date() - if conf.recruit_enable: + if config.conf.recruit_enable: base_scheduler.recruit_plan_solver() # 应该在maa任务之后 @@ -288,21 +288,21 @@ def _is_depotscan(): else: logger.info(f"{path} 不存在,新建一个存储仓库物品的csv") now_time = ( - int(datetime.now().timestamp()) - conf.maa_gap * 3600 + int(datetime.now().timestamp()) - config.conf.maa_gap * 3600 ) 创建csv() 创建json() return now_time - if conf.maa_depot_enable: + if config.conf.maa_depot_enable: dt = int(datetime.now().timestamp()) - _is_depotscan() - if dt >= conf.maa_gap * 3600: + if dt >= config.conf.maa_gap * 3600: base_scheduler.仓库扫描() else: logger.info( - f"仓库扫描未到时间,将在 {conf.maa_gap - dt // 3600}小时之内开始扫描" + f"仓库扫描未到时间,将在 {config.conf.maa_gap - dt // 3600}小时之内开始扫描" ) - if conf.maa_enable == 1: + if config.conf.maa_enable == 1: subject = f"下次任务在{base_scheduler.tasks[0].time.strftime('%H:%M:%S')}" context = f"下一次任务:{base_scheduler.tasks[0].plan}" logger.info(context) @@ -349,10 +349,10 @@ def _is_depotscan(): now_time = datetime.now().time() try: min_time = datetime.strptime( - conf.maa_rg_sleep_min, "%H:%M" + config.conf.maa_rg_sleep_min, "%H:%M" ).time() max_time = datetime.strptime( - conf.maa_rg_sleep_max, "%H:%M" + config.conf.maa_rg_sleep_max, "%H:%M" ).time() if max_time < min_time: rg_sleep = now_time > min_time or now_time < max_time @@ -390,9 +390,9 @@ def _is_depotscan(): base_scheduler.task_count += 1 logger.info(f"第{base_scheduler.task_count}次任务结束") if remaining_time > 300: - if conf.close_simulator_when_idle: + if config.conf.close_simulator_when_idle: restart_simulator(start=False) - elif conf.exit_game_when_idle: + elif config.conf.exit_game_when_idle: base_scheduler.device.exit() body = task_template.render( tasks=[ diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 81d0e746..72d6b5d3 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -47,8 +47,6 @@ try_add_release_dorm, ) -conf = config.conf - class BaseSchedulerSolver(SceneGraphSolver, BaseMixin): """ @@ -742,7 +740,8 @@ def infra_main(self): and self.no_pending_task(2) and ( self.reload_time is None - or self.reload_time < datetime.now() - timedelta(hours=conf.maa_gap) + or self.reload_time + < datetime.now() - timedelta(hours=config.conf.maa_gap) ) ): self.reload() @@ -3114,6 +3113,7 @@ def log_maa(msg, details, arg): logger.debug(Message(msg)) def initialize_maa(self): + conf = config.conf path = pathlib.Path(conf.maa_path) asst_path = os.path.dirname(path / "Python" / "asst") if asst_path not in sys.path: @@ -3146,6 +3146,7 @@ def initialize_maa(self): def maa_plan_solver(self): """清日常""" try: + conf = config.conf if ( self.last_execution["maa"] is not None and ( @@ -3318,20 +3319,20 @@ def recruit_plan_solver(self): if self.last_execution[ "recruit" ] is None or datetime.now() > self.last_execution["recruit"] + timedelta( - hours=conf.recruit_gap + hours=config.conf.recruit_gap ): RecruitSolver(self.device, self.recog).run() self.last_execution["recruit"] = datetime.now() - logger.info(f"下一次公开招募执行时间在{conf.recruit_gap}小时之后") + logger.info(f"下一次公开招募执行时间在{config.conf.recruit_gap}小时之后") def mail_plan_solver(self): if self.check_mail_enable: MailSolver(self.device, self.recog).run() return True - def report_plan_solver(self, send_report=False): + def report_plan_solver(self): if self.report_enable: - return ReportSolver(self.device, self.recog, send_report).run() + return ReportSolver(self.device, self.recog).run() def visit_friend_plan_solver(self): if self.visit_friend_enable: diff --git a/arknights_mower/solvers/cultivate_depot.py b/arknights_mower/solvers/cultivate_depot.py index f5985657..bbf847c5 100644 --- a/arknights_mower/solvers/cultivate_depot.py +++ b/arknights_mower/solvers/cultivate_depot.py @@ -10,8 +10,6 @@ from arknights_mower.utils.log import logger from arknights_mower.utils.path import get_path -conf = config.conf - app_code = "4ca99fa6b56cc2ba" # 签到url @@ -52,7 +50,7 @@ def __init__(self): self.all_recorded = True def start(self): - for item in conf.skland_info: + for item in config.conf.skland_info: if item.isCheck: self.save_param(self.get_cred_by_token(self.log(item))) for i in self.get_binding_list(): diff --git a/arknights_mower/solvers/reclamation_algorithm.py b/arknights_mower/solvers/reclamation_algorithm.py index 6a5a5740..305665ca 100644 --- a/arknights_mower/solvers/reclamation_algorithm.py +++ b/arknights_mower/solvers/reclamation_algorithm.py @@ -15,8 +15,6 @@ from arknights_mower.utils.scene import Scene from arknights_mower.utils.solver import BaseSolver -conf = config.conf - src_pts = np.float32([[0, 97], [1920, 97], [-400, 1080], [2320, 1080]]) dst_pts = np.float32([[0, 0], [1920, 0], [0, 1000], [1920, 1000]]) trans_mat = cv2.getPerspectiveTransform(src_pts, dst_pts) @@ -63,7 +61,7 @@ def run( ) -> None: logger.info("Start: 生息演算") - self.timeout = conf.reclamation_algorithm.timeout + self.timeout = config.conf.reclamation_algorithm.timeout self.deadline = datetime.now() + duration - self.timeout if duration else None self.battle_wait = 0 # 进入战斗后等待剧情出现 diff --git a/arknights_mower/solvers/recruit.py b/arknights_mower/solvers/recruit.py index 8e427bad..a04288bc 100644 --- a/arknights_mower/solvers/recruit.py +++ b/arknights_mower/solvers/recruit.py @@ -21,8 +21,6 @@ from arknights_mower.utils.log import logger from arknights_mower.utils.recognize import Recognizer, Scene -conf = config.conf - class RecruitSolver(SceneGraphSolver): def __init__(self, device: Device = None, recog: Recognizer = None) -> None: @@ -100,7 +98,7 @@ def run(self): + "]:{}".format(",".join(agent)) ) if self.agent_choose or self.result_agent: - if conf.recruit_email_enable: + if config.conf.recruit_email_enable: send_message( recruit_template.render( recruit_results=self.agent_choose, @@ -114,7 +112,7 @@ def run(self): return self.agent_choose, self.result_agent def add_recruit_param(self): - if not conf.recruit_robot: + if not config.conf.recruit_robot: self.recruit_order = [6, 5, 4, 3, 2, 1] self.recruit_index = 1 @@ -261,6 +259,8 @@ def recruit_tags(self): raise "筛选tag失败" logger.info("recruit_result_level={}".format(recruit_result_level)) + conf = config.conf + if self.recruit_order.index(recruit_result_level) <= self.recruit_index: if conf.recruit_email_enable: logger.info("稀有tag,发送邮件") diff --git a/arknights_mower/solvers/report.py b/arknights_mower/solvers/report.py index d09fc276..b441f2cf 100644 --- a/arknights_mower/solvers/report.py +++ b/arknights_mower/solvers/report.py @@ -5,6 +5,7 @@ import pandas as pd from arknights_mower.models import noto_sans +from arknights_mower.utils import config from arknights_mower.utils.device.device import Device from arknights_mower.utils.digit_reader import DigitReader from arknights_mower.utils.email import report_template, send_message @@ -30,7 +31,6 @@ def __init__( self, device: Device = None, recog: Recognizer = None, - send_report: bool = False, ) -> None: super().__init__(device, recog) self.record_path = get_path("@app/tmp/report.csv") @@ -40,7 +40,7 @@ def __init__( (datetime.datetime.now() - datetime.timedelta(hours=4)).date().__str__() ) self.digitReader = DigitReader() - self.send_report = send_report + self.send_report = config.conf.send_report self.report_res = { "作战录像": None, "赤金": None, diff --git a/arknights_mower/solvers/secret_front.py b/arknights_mower/solvers/secret_front.py index 58bc5705..14439601 100644 --- a/arknights_mower/solvers/secret_front.py +++ b/arknights_mower/solvers/secret_front.py @@ -14,8 +14,6 @@ from arknights_mower.utils.recognize import Scene from arknights_mower.utils.solver import BaseSolver -conf = config.conf - def exp(card): data = card[:3] @@ -74,7 +72,7 @@ def run( ): logger.info("Start: 隐秘战线") - self.timeout = conf.reclamation_algorithm.timeout + self.timeout = config.conf.reclamation_algorithm.timeout self.deadline = datetime.now() + duration - self.timeout if duration else None self.unknown_time = None diff --git a/arknights_mower/solvers/skland.py b/arknights_mower/solvers/skland.py index 6ea6bccf..a07827ce 100644 --- a/arknights_mower/solvers/skland.py +++ b/arknights_mower/solvers/skland.py @@ -13,8 +13,6 @@ from arknights_mower.utils.log import logger from arknights_mower.utils.path import get_path -conf = config.conf - app_code = "4ca99fa6b56cc2ba" # 签到url @@ -57,7 +55,7 @@ def __init__(self): self.all_recorded = True def start(self): - for item in conf.skland_info: + for item in config.conf.skland_info: if self.has_record(item.account): continue self.all_recorded = False diff --git a/arknights_mower/utils/email.py b/arknights_mower/utils/email.py index f8170bb2..766e7ee7 100644 --- a/arknights_mower/utils/email.py +++ b/arknights_mower/utils/email.py @@ -40,11 +40,9 @@ report_template = env.get_template("report_template.html") -conf = config.conf - - class Email: def __init__(self, body, subject, attach_image): + conf = config.conf msg = MIMEMultipart() msg.attach(MIMEText(body, "html")) msg["Subject"] = subject @@ -78,6 +76,7 @@ def send(self): s.starttls() else: s = smtplib.SMTP_SSL(self.smtp_server, self.port, timeout=10) + conf = config.conf s.login(conf.account, conf.pass_code) recipient = conf.recipient or [conf.account] s.send_message(self.msg, conf.account, recipient) @@ -85,6 +84,7 @@ def send(self): def send_message_sync(body="", subject="", attach_image=None): + conf = config.conf if subject == "": subject = body.split("\n")[0].strip() subject = conf.mail_subject + subject