Skip to content

Commit

Permalink
修复某些设置重启mower前不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Jul 26, 2024
1 parent 1350148 commit b3f6c87
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 41 deletions.
26 changes: 13 additions & 13 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from arknights_mower.utils.simulator import restart_simulator

base_scheduler = None
conf = config.conf
operators = config.operators


Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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()
):
Expand All @@ -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任务之后
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=[
Expand Down
15 changes: 8 additions & 7 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
try_add_release_dorm,
)

conf = config.conf


class BaseSchedulerSolver(SceneGraphSolver, BaseMixin):
"""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions arknights_mower/solvers/cultivate_depot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 1 addition & 3 deletions arknights_mower/solvers/reclamation_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 # 进入战斗后等待剧情出现
Expand Down
8 changes: 4 additions & 4 deletions arknights_mower/solvers/recruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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,发送邮件")
Expand Down
4 changes: 2 additions & 2 deletions arknights_mower/solvers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions arknights_mower/solvers/secret_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions arknights_mower/solvers/skland.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions arknights_mower/utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,13 +76,15 @@ 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)
s.quit()


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
Expand Down

0 comments on commit b3f6c87

Please sign in to comment.