Skip to content

Commit

Permalink
Merge pull request #338 from y2293456/dev_xxz
Browse files Browse the repository at this point in the history
feat:新增Server酱推送方式
  • Loading branch information
ZhaoZuohong authored Oct 11, 2023
2 parents 17f1607 + fe6f894 commit d0cafed
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 114 deletions.
10 changes: 5 additions & 5 deletions Mower0.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ def 添加MAA任务(self, type):

def maa_plan_solver(self, 任务列表=['Fight'], one_time=False):
try:
self.send_email('启动MAA')
self.send_message('启动MAA')
self.back_to_index()
# 任务及参数请参考 docs/集成文档.md
self.MAA初始化()
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def maa_plan_solver(self, 任务列表=['Fight'], one_time=False):
hard_stop = True
else:
time.sleep(0)
self.send_email('MAA 停止')
self.send_message('MAA 停止')
if hard_stop:
logger.info(f"由于 MAA 任务并未完成,等待3分钟重启软件")
time.sleep(180)
Expand Down Expand Up @@ -1315,7 +1315,7 @@ def maa_plan_solver(self, 任务列表=['Fight'], one_time=False):
context = f"下一次任务:{self.任务列表[0].plan if len(self.任务列表[0].plan) != 0 else '空任务' if self.任务列表[0].type == '' else self.任务列表[0].type}"
logger.info(context)
logger.info(subject)
self.send_email(context, subject)
self.send_message(context, subject)
if remaining_time > 0:
time.sleep(remaining_time)
self.MAA = None
Expand All @@ -1329,7 +1329,7 @@ def maa_plan_solver(self, 任务列表=['Fight'], one_time=False):
time.sleep(remaining_time)
self.device.exit(self.服务器)

def send_email(self, context=None, subject='', retry_time=3):
def send_message(self, context=None, subject='', retry_time=3):
global 任务
if not self.邮件设置['邮件提醒开关'] == '开':
logger.info('邮件功能未开启')
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def Mower0(self):
当前项目.返回基建主界面()
任务间隔 = (当前项目.任务列表[0].time - datetime.now()).total_seconds()
if 任务间隔 > 0:
当前项目.send_email()
当前项目.send_message()
任务提示 = str()
for i in range(len(任务列表)):
logger.warning(
Expand Down
25 changes: 15 additions & 10 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,20 @@ def initialize(tasks, scheduler=None):
base_scheduler.last_room = ""
logger.info("宿舍黑名单:" + str(plan_config.free_blacklist))
base_scheduler.MAA = None
base_scheduler.email_config = {
"mail_enable": conf["mail_enable"],
"subject": conf["mail_subject"],
"account": conf["account"],
"pass_code": conf["pass_code"],
"receipts": [conf["account"]],
"notify": False,
base_scheduler.send_message_config = {
"email_config":{
"mail_enable": conf["mail_enable"],
"subject": conf["mail_subject"],
"account": conf["account"],
"pass_code": conf["pass_code"],
"receipts": [conf["account"]],
"notify": False,
},
"serverJang_push_config":{
"server_push_enable": conf["server_push_enable"],
"sendKey": conf["sendKey"],
}
}

set_maa_options(base_scheduler)
set_recruit_options(base_scheduler)
set_skland_options(base_scheduler)
Expand Down Expand Up @@ -339,7 +344,7 @@ def simulate():
obj.format(timezone_offset) for obj in base_scheduler.tasks
]
)
base_scheduler.send_email(body, subject, "html")
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')}开始工作"
Expand All @@ -358,7 +363,7 @@ def simulate():
obj.format(timezone_offset) for obj in base_scheduler.tasks
]
)
base_scheduler.send_email(body, subject, "html")
base_scheduler.send_message(body, subject, "html")
time.sleep(sleep_time)
if conf["exit_game_when_idle"]:
restart_simulator(conf["simulator"], stop=False)
Expand Down
6 changes: 3 additions & 3 deletions arknights_mower/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def shop(args: list[str] = [], device: Device = None):
ShopSolver(device).run(args)


def recruit(args: list[str] = [], email_config={}, recruit_config={}, device: Device = None):
def recruit(args: list[str] = [], send_message_config={}, recruit_config={}, device: Device = None):
"""
recruit [agents ...]
自动进行公共招募
Expand All @@ -93,9 +93,9 @@ def recruit(args: list[str] = [], email_config={}, recruit_config={}, device: De
choose = {}
result = {}
if len(args) == 0:
choose, result = RecruitSolver(device).run(config.RECRUIT_PRIORITY, email_config, recruit_config)
choose, result = RecruitSolver(device).run(config.RECRUIT_PRIORITY, send_message_config, recruit_config)
else:
choose, result = RecruitSolver(device).run(args, email_config,recruit_config)
choose, result = RecruitSolver(device).run(args, send_message_config,recruit_config)

return choose, result

Expand Down
24 changes: 12 additions & 12 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def overtake_room(self):
self.tasks.append(SchedulerTask(datetime.now(), task_plan=_plan))
else:
msg = f'无法完成 {self.task.meta_data} 的排班,请检查替换组是否被占用'
self.send_email(msg)
self.send_message(msg)
else:
# 如果不满足,则找到并且执行最近一个type 包含 超过数量的high free 和low free 的 任务并且 干员没有 exaust_require 词条
task_index = -1
Expand Down Expand Up @@ -873,7 +873,7 @@ def get_resting_plan(self, agents, exist_replacement, plan, high_free, low_free)
if not low_agent.rest_in_full:
msg = f'同组干员{low_name}{high_name}心情差值大于4,请注意!'
logger.warning(msg)
self.send_email(msg)
self.send_message(msg)
return exist_replacement, plan, high_free - _high, low_free - _low

def initialize_operators(self):
Expand Down Expand Up @@ -1989,7 +1989,7 @@ def agent_arrange_room(self, new_plan, room, plan, skip_enter=False, get_time=Fa
else:
logger.info(f"检测到漏单")
self.recog.save_screencap("run_order_failure")
self.send_email("检测到漏单!")
self.send_message("检测到漏单!")
raise Exception("检测到漏单!")
while self.find('arrange_order_options') is None:
if error_count > 3:
Expand Down Expand Up @@ -2279,9 +2279,9 @@ def maa_plan_solver(self, tasks='All', one_time=False):

"""测试公招用"""
if self.recruit_config['recruit_enable']:
recruit([], self.email_config, self.recruit_config)
recruit([], self.send_message_config, self.recruit_config)

self.send_email('启动MAA')
self.send_message('启动MAA')
self.back_to_index()
# 任务及参数请参考 docs/集成文档.md
self.initialize_maa()
Expand Down Expand Up @@ -2330,7 +2330,7 @@ def maa_plan_solver(self, tasks='All', one_time=False):
if hard_stop:
hard_stop_msg = "Maa任务未完成,等待3分钟关闭游戏"
logger.info(hard_stop_msg)
self.send_email(hard_stop_msg)
self.send_message(hard_stop_msg)
time.sleep(180)
self.device.exit(self.package_name)
elif not one_time:
Expand All @@ -2343,23 +2343,23 @@ def maa_plan_solver(self, tasks='All', one_time=False):
logger.debug(stage_drop)
# 有掉落东西再发
if stage_drop["details"]:
self.send_email(maa_template.render(stage_drop=stage_drop), "Maa停止", "html")
self.send_message(maa_template.render(stage_drop=stage_drop), "Maa停止", "html")

'''仅发送由maa选择的结果以及稀有tag'''
if recruit_results:
result = []
# 稀有tag发送
if recruit_special_tags['tags']:
result = filter_result(recruit_special_tags['tags'], recruit_results["results"], 0)
self.send_email(recruit_template.render(recruit_results=result), "出现稀有tag辣", "html")
self.send_message(recruit_template.render(recruit_results=result), "出现稀有tag辣", "html")

# 发送选择的tag
if recruit_tags_selected['tags']:
result = filter_result(recruit_tags_selected['tags'], recruit_results["results"], 1)
self.send_email(recruit_template.render(recruit_results=result), "公招结果", "html")
self.send_message(recruit_template.render(recruit_results=result), "公招结果", "html")

else:
self.send_email("Maa单次任务停止")
self.send_message("Maa单次任务停止")
now_time = datetime.now().time()
try:
min_time = datetime.strptime(self.maa_config['sleep_min'], "%H:%M").time()
Expand All @@ -2379,7 +2379,7 @@ def maa_plan_solver(self, tasks='All', one_time=False):
if (self.maa_config['roguelike'] or self.maa_config['reclamation_algorithm'] or self.maa_config[
'stationary_security_service']) and not rg_sleep:
logger.info(f'准备开始:肉鸽/保全/演算')
self.send_email('启动 肉鸽/保全/演算')
self.send_message('启动 肉鸽/保全/演算')
while (self.tasks[0].time - datetime.now()).total_seconds() > 30:
self.MAA = None
self.initialize_maa()
Expand Down Expand Up @@ -2452,7 +2452,7 @@ def maa_plan_solver(self, tasks='All', one_time=False):
logger.exception(e)
self.MAA = None
self.device.exit(self.package_name)
self.send_email(str(e), "Maa调用出错!")
self.send_message(str(e), "Maa调用出错!")
remaining_time = (self.tasks[0].time - datetime.now()).total_seconds()
if remaining_time > 0:
logger.info(f"休息 {format_time(remaining_time)},到{self.tasks[0].time.strftime('%H:%M:%S')}开始工作")
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 @@ -48,15 +48,15 @@ def __init__(self, device: Device = None, recog: Recognizer = None) -> None:

self.recruit_pos = -1

def run(self, priority: list[str] = None, email_config={}, recruit_config={}):
def run(self, priority: list[str] = None, send_message_config={}, recruit_config={}):
"""
:param priority: list[str], 优先考虑的公招干员,默认为高稀有度优先
"""
self.priority = priority
self.recruiting = 0
self.has_ticket = True # 默认含有招募票
self.can_refresh = True # 默认可以刷新
self.email_config = email_config
self.send_message_config = send_message_config

# 调整公招参数
self.add_recruit_param(recruit_config)
Expand All @@ -83,7 +83,7 @@ def run(self, priority: list[str] = None, email_config={}, recruit_config={}):
if self.agent_choose:
logger.info(f'公招标签:{self.agent_choose}')
if self.agent_choose or self.result_agent:
self.send_email(recruit_template.render(recruit_results=self.agent_choose,
self.send_message(recruit_template.render(recruit_results=self.agent_choose,
recruit_get_agent=self.result_agent,
title_text="公招汇总"), "公招汇总通知", "html")

Expand Down Expand Up @@ -189,7 +189,7 @@ def recruit_tags(self) -> bool:
# 刷新标签
if need_choose is False:
'''稀有tag或支援,不需要选'''
self.send_email(recruit_rarity.render(recruit_results=best['possible'], title_text="稀有tag通知"), "出稀有标签辣",
self.send_message(recruit_rarity.render(recruit_results=best['possible'], title_text="稀有tag通知"), "出稀有标签辣",
"html")
logger.debug('稀有tag,发送邮件')
self.back()
Expand Down
4 changes: 3 additions & 1 deletion arknights_mower/templates/conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,6 @@ sss:
copilot: ''
run_order_grandet_mode:
enable: true
buffer_time: 30
buffer_time: 30
server_push_enable: false
sendKey: ''
71 changes: 29 additions & 42 deletions arknights_mower/templates/email/recruit_template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
Expand All @@ -14,47 +14,34 @@
</style>
</head>
<body>
<table style="text-align: center">
{% if recruit_results|length > 0 %}

<th>位置</th><th>标签</th><th>预计干员</th>
{% for pos,value in recruit_results.items() %}
<tr>
<table style="text-align: center">
{% if recruit_results|length > 0 %}
<tr>
<th>位置</th>
<th>标签</th>
<th>预计干员</th>
</tr>
{% for pos,value in recruit_results.items() %}
<tr>
<td>{{ pos }}</td>
{% for key,value in value.items() %}
<td>
{% for tag in key %}
{% if tag != "" %}
{{ tag }}
{% else %}
{{ "未选择" }}
{% endif %}
{% endfor %}
<td>
{% for agent in value.agent %}
{{ agent.name }}
{% endfor %}
</td>
{% endfor %}
</tr>
{% endfor %}
{% endif %}

{% if recruit_get_agent|length > 0 %}
<th colspan="3">上次公招干员</th>
{% for pos,value in recruit_get_agent.items() %}
<tr>
<td>{{ pos }}</td>
<td colspan="2">{{ value }}</td>
</tr>
{% endfor %}



{% endif %}

</table>
{% for key,value in value.items() %}
<td>
{% for tag in key %} {% if tag != "" %} {{ tag }} {% else %} {{
"未选择" }} {% endif %} {% endfor %}
</td>
<td>{% for agent in value.agent %} {{ agent.name }} {% endfor %}</td>
{% endfor %}
</tr>
{% endfor %} {% endif %} {% if recruit_get_agent|length > 0 %}
<tr>
<th colspan="3">上次公招干员</th>
</tr>
{% for pos,value in recruit_get_agent.items() %}
<tr>
<td>{{ pos }}</td>
<td colspan="2">{{ value }}</td>
</tr>
{% endfor %} {% endif %}
</table>
</body>
</html>


Loading

0 comments on commit d0cafed

Please sign in to comment.