Skip to content

Commit

Permalink
✨ Add new notify method: pushplus
Browse files Browse the repository at this point in the history
This commit adds error handling, fixed the wrong url written by Copilot.
  • Loading branch information
MuelNova committed Jul 17, 2024
1 parent f64992b commit c3c0bb0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
6 changes: 3 additions & 3 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ def initialize(tasks, scheduler=None):
"server_push_enable": conf["server_push_enable"],
"sendKey": conf["sendKey"],
},
"pushplus_push_config": {
"pushplus_push_enable": conf["pushplus_push_enable"],
"pushplus_config": {
"pushplus_push_enable": conf["pushplus_enable"],
"pushplus_token": conf["pushplus_token"],
}
},
}
base_scheduler.check_mail_enable = conf["check_mail_enable"]
base_scheduler.report_enable = conf["report_enable"]
Expand Down
36 changes: 32 additions & 4 deletions arknights_mower/utils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,25 @@ def handle_serverJang_error(self, url, data):
logger.exception(e)
self.csleep(delay)

# PushPlus异常处理
def handle_pushplus_error(self, data):
for delay in self.exponential_backoff():
try:
response = requests.post(r"http://www.pushplus.plus/send", json=data)
json_data = response.json()
if json_data.get("code") == 200:
logger.info("PushPlus通知发送成功")
break
else:
logger.error(
f"PushPlus通知发送失败,错误信息:{json_data.get('msg')}"
)
self.csleep(delay)
except Exception as e:
logger.error("PushPlus通知发送失败")
logger.exception(e)
self.csleep(delay)

def send_message(
self,
body="",
Expand Down Expand Up @@ -858,7 +877,7 @@ def send_message_old(
# 获取Server酱配置
serverJang_push_config = send_message_config.get("serverJang_push_config")
# 获取PushPlus配置
pushPlus_config = send_message_config.get("pushPlus_config")
pushplus_config = send_message_config.get("pushplus_config")

# 邮件通知部分
if email_config and email_config.get("mail_enable", 0):
Expand Down Expand Up @@ -905,13 +924,13 @@ def send_message_old(
failed_methods.append(("serverJang", url, data))

# PushPlus通知部分
if pushPlus_config and pushPlus_config.get("pushplus_enable", False):
token = pushPlus_config.get("pushplus_token")
if pushplus_config and pushplus_config.get("pushplus_enable", False):
token = pushplus_config.get("pushplus_token")
if not token:
logger.error("PushPlus的token未配置")
return

url = r"http://pushplus.hxtrip.com/send"
url = r"http://www.pushplus.plus/send"
data = {
"token": token,
"title": "Mower通知",
Expand All @@ -931,6 +950,7 @@ def send_message_old(
except Exception as e:
logger.error("PushPlus通知发送失败")
logger.exception(e)
failed_methods.append(("pushplus", data))

# 处理失败的方法
for method, *args in failed_methods:
Expand All @@ -948,3 +968,11 @@ def send_message_old(
break
except Exception:
self.csleep(1)

elif method == "pushplus":
for _ in range(retry_times):
try:
self.handle_pushplus_error(*args)
break
except Exception:
self.csleep(1)

0 comments on commit c3c0bb0

Please sign in to comment.