This commit is contained in:
hysteria 2024-10-08 15:06:24 +08:00 committed by GitHub
commit 48743a834a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 25 deletions

View File

@ -17,6 +17,11 @@ checkin_map = checkin_map()
notice_map = { notice_map = {
"BARK_URL": "", "BARK_URL": "",
"BARK_TITLE":"",
"BARK_GROUP":"",
"BARK_ICON":"",
"BARK_SOUND":"",
"BARK_URL_JUMP":"",
"COOLPUSHEMAIL": "", "COOLPUSHEMAIL": "",
"COOLPUSHQQ": "", "COOLPUSHQQ": "",
"COOLPUSHSKEY": "", "COOLPUSHSKEY": "",

View File

@ -23,11 +23,11 @@ def message2server_turbo(sendkey, content):
def message2coolpush( def message2coolpush(
coolpushskey, coolpushskey,
content, content,
coolpushqq: bool = True, coolpushqq: bool = True,
coolpushwx: bool = False, coolpushwx: bool = False,
coolpushemail: bool = False, coolpushemail: bool = False,
): ):
print("Cool Push 推送开始") print("Cool Push 推送开始")
params = {"c": content, "t": "每日签到"} params = {"c": content, "t": "每日签到"}
@ -102,15 +102,25 @@ def message2dingtalk(dingtalk_secret, dingtalk_access_token, content):
return return
def message2bark(bark_url: str, content): def message2bark(bark_url: str, content, title: str = None, sound: str = None, group: str = None,
icon: str = None,
url_jump: str = None):
print("Bark 推送开始") print("Bark 推送开始")
parms = {"sound": sound, "group": group, "icon": icon, "url": url_jump}
if not bark_url.endswith("/"): if not bark_url.endswith("/"):
bark_url += "/" bark_url += "/"
content = quote_plus(content) content = quote_plus(content)
url = f"{bark_url}{content}" url = f"{bark_url}{content}"
if title:
url = f"{bark_url}{title}/{content}?"
for k, v in parms.items():
if v:
url += f"{k}={v}&"
if url.endswith("&"):
url = url[:-1]
headers = {"Content-type": "application/x-www-form-urlencoded"} headers = {"Content-type": "application/x-www-form-urlencoded"}
requests.get(url=url, headers=headers) resp = requests.get(url=url, headers=headers)
return return resp
def message2qywxrobot(qywx_key, content): def message2qywxrobot(qywx_key, content):
@ -123,13 +133,13 @@ def message2qywxrobot(qywx_key, content):
def message2qywxapp( def message2qywxapp(
qywx_corpid, qywx_corpid,
qywx_agentid, qywx_agentid,
qywx_corpsecret, qywx_corpsecret,
qywx_touser, qywx_touser,
qywx_media_id, qywx_media_id,
qywx_origin, qywx_origin,
content, content,
): ):
print("企业微信应用消息推送开始") print("企业微信应用消息推送开始")
base_url = "https://qyapi.weixin.qq.com" base_url = "https://qyapi.weixin.qq.com"
@ -210,6 +220,11 @@ def push_message(content_list: list, notice_info: dict):
dingtalk_access_token = notice_info.get("dingtalk_access_token") dingtalk_access_token = notice_info.get("dingtalk_access_token")
fskey = notice_info.get("fskey") fskey = notice_info.get("fskey")
bark_url = notice_info.get("bark_url") bark_url = notice_info.get("bark_url")
bark_title = notice_info.get("bark_title")
bark_icon = notice_info.get("bark_icon")
bark_group = notice_info.get("bark_group")
bark_sound = notice_info.get("bark_sound")
bark_url_jump = notice_info.get("bark_url_jump") # 收到通知后点击打开的链接
sckey = notice_info.get("sckey") sckey = notice_info.get("sckey")
sendkey = notice_info.get("sendkey") sendkey = notice_info.get("sendkey")
qmsg_key = notice_info.get("qmsg_key") qmsg_key = notice_info.get("qmsg_key")
@ -243,13 +258,13 @@ def push_message(content_list: list, notice_info: dict):
print("获取重要通知失败:", e) print("获取重要通知失败:", e)
if merge_push is None: if merge_push is None:
if ( if (
qmsg_key qmsg_key
or coolpushskey or coolpushskey
or qywx_touser or qywx_touser
or qywx_corpsecret or qywx_corpsecret
or qywx_agentid or qywx_agentid
or bark_url or bark_url
or pushplus_token or pushplus_token
): ):
merge_push = False merge_push = False
else: else:
@ -288,7 +303,15 @@ def push_message(content_list: list, notice_info: dict):
print("企业微信应用消息推送失败", e) print("企业微信应用消息推送失败", e)
if bark_url: if bark_url:
try: try:
message2bark(bark_url=bark_url, content=message) resp = message2bark(bark_url=bark_url, content=message, icon=bark_icon, group=bark_group,title=bark_title,
sound=bark_sound,
url_jump=bark_url_jump)
error_msg=["414","431","large","long"]
# 如果列表中的字符串存在于resp.text中则分批发送
if any(x in resp.text.lower() for x in error_msg):
notice_info["merge_push"] = False
print("Bark 推送内容过长,已自动切换为单条推送")
push_message(content_list=content_list, notice_info=notice_info)
except Exception as e: except Exception as e:
print("Bark 推送失败", e) print("Bark 推送失败", e)
if dingtalk_access_token and dingtalk_secret: if dingtalk_access_token and dingtalk_secret:

View File

@ -1,5 +1,10 @@
{ {
"BARK_URL":"", "BARK_URL":"",
"BARK_TITLE":"dailycheckin",
"BARK_GROUP":"dailycheckin",
"BARK_ICON":"https://cdn.jsdelivr.net/gh/Sitoi/Sitoi.github.io/medias/avatars/avatar.jpg",
"BARK_SOUND":"",
"BARK_URL_JUMP":"",
"COOLPUSHEMAIL":true, "COOLPUSHEMAIL":true,
"COOLPUSHQQ":true, "COOLPUSHQQ":true,
"COOLPUSHSKEY":"", "COOLPUSHSKEY":"",

View File

@ -51,7 +51,7 @@ import { Callout } from 'nextra/components'
# BARK # BARK
<Callout type="warning"> <Callout type="warning">
通知消息在 Bark 有长度限制,如果没收到推送,请将 MERGE_PUSH 改为 false 通知消息在 Bark 有长度限制,如果内容过长导致推送失败,会自动切换为单条推送。
</Callout> </Callout>
### 配置示例 ### 配置示例
@ -59,11 +59,22 @@ import { Callout } from 'nextra/components'
```json filename="config.json" copy ```json filename="config.json" copy
{ {
"BARK_URL": "", "BARK_URL": "",
"MERGE_PUSH": "" "BARK_TITLE": "",
"BARK_GROUP": "",
"BARK_ICON": "",
"BARK_SOUND": "",
"BARK_URL_JUMP": "",
"MERGE_PUSH": true
} }
``` ```
| 参数 | 说明 | | 参数 | 说明 |
| :--------------: | :--------------------------------------------------------------------------------------------: | | :--------------: | :--------------------------------------------------------------------------------------------: |
| _**BARK_URL**_ | [BARK](https://bark.day.app/#/) ,填写 `BARK_URL` 例: `https://api.day.app/DxHcxxxxxRxxxxxxcm/` | | _**BARK_URL**_ | [BARK](https://bark.day.app/#/) ,填写 `BARK_URL` 例: `https://api.day.app/DxHcxxxxxRxxxxxxcm/` |
| _**BARK_TITLE(可选)**_ | 推送标题,例:`dailycheckin` |
| _**BARK_GROUP(可选)**_ | Bark中消息分组例:`dailycheckin` |
| _**BARK_ICON(可选)**_ | 推送图标,例:`https://example.com/icon.png` |
| _**BARK_SOUND(可选)**_ | 推送铃声请在app中查看铃声列表例:`bell` |
| _**BARK_URL_JUMP(可选)**_ | 推送消息点击跳转链接,例:`https://example.com` |
| _**MERGE_PUSH**_ | **true**: 将推送消息合并;**false**: 分开推送 | | _**MERGE_PUSH**_ | **true**: 将推送消息合并;**false**: 分开推送 |