Skip to content

Commit

Permalink
fix:每日任务会不执行
Browse files Browse the repository at this point in the history
  • Loading branch information
EightyDollars committed Nov 18, 2023
1 parent 321a70d commit c32a708
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
25 changes: 15 additions & 10 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def main(c, p, o={}, child_conn=None):
from arknights_mower.utils.log import init_fhlr
from arknights_mower.utils import config

global plan
global conf
global operators
Expand Down Expand Up @@ -351,18 +351,23 @@ def simulate():

if sleep_time > 540:
# 刷新时间以鹰历为准
if base_scheduler.daily_report:
base_scheduler.daily_report = base_scheduler.report_plan_solver()
# if base_scheduler.daily_skland and base_scheduler.skland_config['skland_enable']:
# base_scheduler.daily_report = base_scheduler.skland_plan_solover()
# base_scheduler.daily_skland=False
if base_scheduler.skland_config['skland_enable']:
base_scheduler.skland_plan_solover()
if base_scheduler.daily_mail:
base_scheduler.daily_report = base_scheduler.mail_plan_solver()
if base_scheduler.daily_report < (datetime.now() - timedelta(hours=4)).date():
if base_scheduler.report_plan_solver():
base_scheduler.daily_report = (datetime.now() - timedelta(hours=4)).date()

if base_scheduler.skland_config['skland_enable'] and base_scheduler.daily_skland < (
datetime.now() - timedelta(hours=4)).date():
if base_scheduler.skland_plan_solover():
base_scheduler.daily_skland = (datetime.now() - timedelta(hours=4)).date()

if base_scheduler.check_mail_enable and base_scheduler.daily_mail < (
datetime.now() - timedelta(hours=8)).date():
if base_scheduler.mail_plan_solver():
base_scheduler.daily_mail = (datetime.now() - timedelta(hours=8)).date()

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')}"
Expand Down
46 changes: 26 additions & 20 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
stage_drop = {}



class BaseSchedulerSolver(BaseSolver, BaseMixin):
"""
收集基建的产物:物资、赤金、信赖
Expand Down Expand Up @@ -78,14 +77,14 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
self.recruit_config = {}
self.skland_config = {}
self.recruit_time = None
self.daily_mission = False
self.daily_report = False
self.daily_skland = True
self.daily_mail = False

self.daily_report = (datetime.now() - timedelta(days=1, hours=4)).date()
self.daily_skland = (datetime.now() - timedelta(days=1, hours=4)).date()
self.daily_mail = (datetime.now() - timedelta(days=1, hours=8)).date()

self.check_mail_enable = True
self.report_enable = True


@property
def party_time(self):
return self._party_time
Expand Down Expand Up @@ -489,7 +488,8 @@ def infra_main(self):
logger.info(f"记录本次无人机使用时间为:{datetime.now()}")
self.drone_time = datetime.now()
if self.reload_room is not None and (
self.reload_time is None or self.reload_time < datetime.now() - timedelta(hours=self.maa_config['maa_execution_gap'])):
self.reload_time is None or self.reload_time < datetime.now() - timedelta(
hours=self.maa_config['maa_execution_gap'])):
self.reload()
logger.info(f"记录本次补货时间为:{datetime.now()}")
self.todo_task = True
Expand All @@ -503,7 +503,8 @@ def infra_main(self):
self.collect_notification = True
else:
return self.handle_error()
def translate_room(self,room):

def translate_room(self, room):
if "room" in room:
parts = room.split("_")
return f"B{parts[1]}0{parts[2]}"
Expand All @@ -516,6 +517,7 @@ def translate_room(self,room):
return "控制中枢"
else:
return "会客室"

def agent_get_mood(self, skip_dorm=False, force=False):
# 暂时规定纠错只适用于主班表
need_read = set(
Expand All @@ -528,7 +530,7 @@ def agent_get_mood(self, skip_dorm=False, force=False):
_mood_data = self.get_agent_from_room(room)
mood_info = [f"干员: {item['agent']}, 心情: {round(item['mood'], 3)}" for item in _mood_data]
logger.info(f'房间 {self.translate_room(room)} {mood_info}')
#logger.info(f'房间 {room} 心情为:{_mood_data}')
# logger.info(f'房间 {room} 心情为:{_mood_data}')
break
except Exception as e:
if error_count > 3: raise e
Expand Down Expand Up @@ -735,7 +737,9 @@ def plan_solver(self):
_time = result[op.current_index]['time'] - timedelta(minutes=10)
elif op.current_mood() > 0.25 + op.lower_limit and op.depletion_rate != 0:
_time = datetime.now() + timedelta(
hours=(op.current_mood() - op.lower_limit- 0.25) / op.depletion_rate) - timedelta(minutes=10)
hours=(
op.current_mood() - op.lower_limit - 0.25) / op.depletion_rate) - timedelta(
minutes=10)
self.back()
# plan 是空的是因为得动态生成
exhaust_type = op.name
Expand Down Expand Up @@ -1107,7 +1111,8 @@ def clue(self) -> None:
# 如果启用 MAA,则在线索交流结束后购物
if self.maa_config['maa_enable'] and self.party_time is not None:
if find_next_task(self.tasks, task_type=TaskTypes.MAA_MALL) is None:
self.tasks.append(SchedulerTask(time=self.party_time - timedelta(milliseconds=1), task_type=TaskTypes.CLUE_PARTY))
self.tasks.append(
SchedulerTask(time=self.party_time - timedelta(milliseconds=1), task_type=TaskTypes.CLUE_PARTY))
self.tasks.append(SchedulerTask(time=self.party_time, task_type=TaskTypes.MAA_MALL))

self.back(interval=2)
Expand Down Expand Up @@ -1360,7 +1365,6 @@ def drone(self, room: str, not_customize=False, not_return=False, adjust_time=Fa
self.back(interval=2, rebuild=False)
self.back(interval=2)


# 用于制造站切换产物,请注意在调用该函数前有足够的无人机,并补足相应制造站产物,目前仅支持中级作战记录与赤金之间的切换
# def 制造站切换产物(self, room: str, 目标产物: str, not_customize=False, not_return=False):
# # 点击进入该房间
Expand Down Expand Up @@ -1466,7 +1470,6 @@ def drone(self, room: str, not_customize=False, not_return=False, adjust_time=Fa
# self.tap((self.recog.w * 3 // 4, self.recog.h * 5 // 6), interval=1) # 确认数量
# self.tap((self.recog.w * 3 // 4, self.recog.h * 7 // 10), interval=1) # 确认更改


def get_arrange_order(self) -> ArrangeOrder:
best_score, best_order = 0, None
for order in ArrangeOrder:
Expand Down Expand Up @@ -1758,11 +1761,12 @@ def get_order_remaining_time(self):

def current_room_changed(self, instance):
logger.info(f"{instance.name} 房间变动")
ref_rooms = instance.refresh_order_room[1] if instance.refresh_order_room[1] else list(self.op_data.run_order_rooms.keys())
ref_rooms = instance.refresh_order_room[1] if instance.refresh_order_room[1] else list(
self.op_data.run_order_rooms.keys())
for ref_room in ref_rooms:
self.refresh_run_order_time(ref_room)

def refresh_run_order_time(self,room):
def refresh_run_order_time(self, room):
logger.debug("检测到插拔房间人员变动!")
run_order_task = find_next_task(self.tasks, datetime.now() + timedelta(minutes=15),
task_type=TaskTypes.RUN_ORDER,
Expand Down Expand Up @@ -2109,12 +2113,14 @@ def append_maa_task(self, type):
"force_shopping_if_credit_full": self.maa_config['mall_ignore_when_full']
})
elif type == 'Depot':
self.MAA.append_task('Depot',{
self.MAA.append_task('Depot', {
"enable": self.maa_config['maa_depot_enable']
})
})

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[
'last_execution'] is not None and datetime.now() - timedelta(
seconds=self.maa_config['maa_execution_gap'] * 3600) < self.maa_config['last_execution']:
logger.info("间隔未超过设定时间,不启动maa")
else:
Expand Down Expand Up @@ -2278,11 +2284,11 @@ def maa_plan_solver(self, tasks='All', one_time=False):
def skland_plan_solover(self):
return SKLand(self.skland_config['skland_info']).start()


def recruit_plan_solver(self):
if ('last_execution' not in self.recruit_config
or self.recruit_config['last_execution'] is None
or self.recruit_config['last_execution'] <= (datetime.now() - timedelta(seconds=self.recruit_config['recruit_execution_gap'] * 3600))):
or self.recruit_config['last_execution'] <= (
datetime.now() - timedelta(seconds=self.recruit_config['recruit_execution_gap'] * 3600))):
recruit([], self.send_message_config, self.recruit_config)
self.recruit_config['last_execution'] = datetime.now()
logger.info("下一次公开招募执行时间在{}小时之后".format(self.recruit_config['recruit_execution_gap']))
Expand Down
5 changes: 3 additions & 2 deletions arknights_mower/solvers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def run(self):
logger.info("康康大基报")
try:
super().run()
return True
except:
return False
return True
pass
return False

def transition(self) -> bool:
if self.scene() == Scene.INDEX:
Expand Down
7 changes: 6 additions & 1 deletion arknights_mower/solvers/skland.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ def __init__(self, skland_info):
'vName': ''
}
self.sign_token = ''
self.all_recorded = True

def start(self):
for item in self.account_list:
if item['isCheck']:
if self.has_record(item['account']):
continue
self.all_recorded = False
self.save_param(self.get_cred_by_token(self.log(item)))
for i in self.get_binding_list():
body = {
Expand Down Expand Up @@ -103,6 +105,8 @@ def start(self):
f'{i.get("nickName")}获得了{res["name"]}×{j.get("count") or 1}')
if len(self.reward) > 0:
return self.record_log()
if self.all_recorded:
return True
return False

def save_param(self, cred_resp):
Expand Down Expand Up @@ -197,10 +201,11 @@ def record_log(self):
for item in self.reward:
res_df = pd.DataFrame(item, index=[date_str])
res_df.to_csv(self.record_path, mode='a', header=False, encoding='gbk')
return True
except:
pass

return True

def has_record(self, phone: str):
try:
if os.path.exists(self.record_path) is False:
Expand Down
11 changes: 1 addition & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,12 @@ def get_half_month_data():
@app.route("/test-email")
@require_token
def test_email():
host_smtp = ""
if re.findall(r'^[\w]{1,19}@(qq).((com)|(cn))$', conf["account"], re.IGNORECASE):
host_smtp = "smtp.qq.com"
elif re.findall(r'^[\w]{1,19}@(163).((com)|(cn))$', conf["account"], re.IGNORECASE):
host_smtp = "smtp.163.com"
elif re.findall(r'^[\w]{1,19}@(126).((com)|(cn))$', conf["account"], re.IGNORECASE):
host_smtp = "smtp.126.com"

print(host_smtp)
msg = MIMEMultipart()
msg.attach(MIMEText("arknights-mower测试邮件", "plain"))
msg["Subject"] = conf["mail_subject"] + "测试邮件"
msg["From"] = conf["account"]
try:
s = smtplib.SMTP_SSL(host_smtp, 465, timeout=10.0)
s = smtplib.SMTP_SSL("smtp.qq.com", 465, timeout=10.0)
s.login(conf["account"], conf["pass_code"])
s.sendmail(conf["account"], conf["account"], msg.as_string())
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/Email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function test_email() {
label-width="96"
label-align="left"
>
<n-form-item label="邮箱">
<n-form-item label="QQ邮箱">
<n-input v-model:value="account" />
</n-form-item>
<n-form-item label="授权码">
Expand Down

0 comments on commit c32a708

Please sign in to comment.