Skip to content

Commit

Permalink
🎨 Improve Pushplus configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MuelNova committed Jul 18, 2024
1 parent c3c0bb0 commit a906c72
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
5 changes: 1 addition & 4 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ def initialize(tasks, scheduler=None):
"server_push_enable": conf["server_push_enable"],
"sendKey": conf["sendKey"],
},
"pushplus_config": {
"pushplus_push_enable": conf["pushplus_enable"],
"pushplus_token": conf["pushplus_token"],
},
"pushplus_config": conf["pushplus"],
}
base_scheduler.check_mail_enable = conf["check_mail_enable"]
base_scheduler.report_enable = conf["report_enable"]
Expand Down
5 changes: 3 additions & 2 deletions arknights_mower/templates/conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ run_order_grandet_mode:
back_to_index: false
server_push_enable: false
sendKey: ''
pushplus_enable: false
pushplus_token: ''
pushplus:
enable: false
token: ''
recruit_gap: 9
recruit_auto_5: 1
recruit_auto_only5: false
Expand Down
27 changes: 24 additions & 3 deletions arknights_mower/utils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,19 +924,40 @@ 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("enable", False):
token = pushplus_config.get("token")
if not token:
logger.error("PushPlus的token未配置")
return


# img 嵌入 html
# if attach_image is not None:
# img = cv2.cvtColor(attach_image, cv2.COLOR_RGB2BGR)
# _, attachment = cv2.imencode(
# ".jpg", img, [int(cv2.IMWRITE_JPEG_QUALITY), 75]
# )
# img_base64 = base64.b64encode(attachment)
# img_url = f"data:image/jpeg;base64,{img_base64.decode('utf-8')}"
# img_tag = f'<img src="{img_url}" />'

# # 查找 </body> 标签的位置
# body_close_tag = '</body>'
# insert_position = body.find(body_close_tag)

# # 在 </body> 标签前插入 <img> 标签
# if insert_position != -1:
# body = body[:insert_position] + img_tag + body[insert_position:]


url = r"http://www.pushplus.plus/send"
data = {
"token": token,
"title": "Mower通知",
"content": mkBody,
"content": body,
"template": "markdown",
}


try:
response = requests.post(url, json=data)
Expand Down
3 changes: 1 addition & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,10 @@ def test_pushplus_push():
import requests

try:
print(config.conf)
response = requests.post(
r"http://www.pushplus.plus/send",
params={
"token": config.conf["pushplus_token"],
"token": config.conf["pushplus"]["token"],
"title": "arknights-mower推送测试",
"content": "arknights-mower推送测试",
},
Expand Down
10 changes: 5 additions & 5 deletions ui/src/components/PushPlus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mobile = inject('mobile')
const testPushResult = ref('')
const { pushplus_enable, pushplus_token } = storeToRefs(store)
const { pushplus } = storeToRefs(store)
async function test_push() {
testPushResult.value = '正在发送……'
Expand All @@ -21,7 +21,7 @@ async function test_push() {
<template>
<n-card>
<template #header>
<n-checkbox v-model:checked="pushplus_enable" class="serverpush-title">
<n-checkbox v-model:checked="pushplus.enable" class="serverpush-title">
<div class="card-title-wrapper">
<span class="card-title">PushPlus推送通知</span>
<help-text class="card-title-tip">
Expand All @@ -42,11 +42,11 @@ async function test_push() {
label-align="left"
>
<n-form-item label="Push Plus Token">
<n-input v-model:value="pushplus_token" show-password-on="click" type="password" />
<n-input v-model:value="pushplus.token" show-password-on="click" type="password" />
</n-form-item>
</n-form>
<n-divider v-if="pushplus_enable" />
<div v-if="pushplus_enable" class="push-test mt-16">
<n-divider v-if="pushplus.enable" />
<div v-if="pushplus.enable" class="push-test mt-16">
<n-button @click="test_push">发送测试通知</n-button>
<div>{{ testPushResult }}</div>
</div>
Expand Down
12 changes: 4 additions & 8 deletions ui/src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export const useConfigStore = defineStore('config', () => {
const run_order_grandet_mode = ref({})
const server_push_enable = ref(false) // Server酱通知开关
const sendKey = ref('') // Server酱Key值
const pushplus_enable = ref(false) // PushPlus通知开关
const pushplus_token = ref('') // PushPlus Token
const pushplus = ref({})
const check_mail_enable = ref(true)
const report_enable = ref(true)
const send_report = ref(true)
Expand Down Expand Up @@ -159,8 +158,7 @@ export const useConfigStore = defineStore('config', () => {
server_push_enable.value = response.data.server_push_enable != 0
sendKey.value = response.data.sendKey
// 新增:加载PushPlus的配置
pushplus_enable.value = response.data.pushplus_enable != 0
pushplus_token.value = response.data.pushplus_token
pushplus.value = response.data.pushplus
check_mail_enable.value = response.data.check_mail_enable
report_enable.value = response.data.report_enable
send_report.value = response.data.send_report
Expand Down Expand Up @@ -246,8 +244,7 @@ export const useConfigStore = defineStore('config', () => {
server_push_enable: server_push_enable.value ? 1 : 0,
sendKey: sendKey.value,
// 新增:PushPlus的配置
pushplus_enable: pushplus_enable.value ? 1 : 0,
pushplus_token: pushplus_token.value,
pushplus: pushplus.value,
check_mail_enable: check_mail_enable.value,
report_enable: report_enable.value,
send_report: send_report.value,
Expand Down Expand Up @@ -342,8 +339,7 @@ export const useConfigStore = defineStore('config', () => {
run_order_grandet_mode,
server_push_enable,
sendKey,
pushplus_enable,
pushplus_token,
pushplus,
check_mail_enable,
report_enable,
send_report,
Expand Down

0 comments on commit a906c72

Please sign in to comment.