Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bark推送加入title\group\icon\sound\url参数,当内容过长时自动切换为分批发送。 #320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dailycheckin/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def checkin_map():

notice_map = {
"BARK_URL": "",
"BARK_TITLE":"",
"BARK_GROUP":"",
"BARK_ICON":"",
"BARK_SOUND":"",
"BARK_URL_JUMP":"",
"COOLPUSHEMAIL": "",
"COOLPUSHQQ": "",
"COOLPUSHSKEY": "",
Expand Down
69 changes: 46 additions & 23 deletions dailycheckin/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def message2server_turbo(sendkey, content):


def message2coolpush(
coolpushskey,
content,
coolpushqq: bool = True,
coolpushwx: bool = False,
coolpushemail: bool = False,
coolpushskey,
content,
coolpushqq: bool = True,
coolpushwx: bool = False,
coolpushemail: bool = False,
):
print("Cool Push 推送开始")
params = {"c": content, "t": "每日签到"}
Expand Down Expand Up @@ -102,15 +102,25 @@ def message2dingtalk(dingtalk_secret, dingtalk_access_token, content):
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 推送开始")
parms = {"sound": sound, "group": group, "icon": icon, "url": url_jump}
if not bark_url.endswith("/"):
bark_url += "/"
content = quote_plus(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"}
requests.get(url=url, headers=headers)
return
resp = requests.get(url=url, headers=headers)
return resp


def message2qywxrobot(qywx_key, content):
Expand All @@ -123,13 +133,13 @@ def message2qywxrobot(qywx_key, content):


def message2qywxapp(
qywx_corpid,
qywx_agentid,
qywx_corpsecret,
qywx_touser,
qywx_media_id,
qywx_origin,
content,
qywx_corpid,
qywx_agentid,
qywx_corpsecret,
qywx_touser,
qywx_media_id,
qywx_origin,
content,
):
print("企业微信应用消息推送开始")
base_url = "https://qyapi.weixin.qq.com"
Expand Down Expand Up @@ -210,6 +220,11 @@ def push_message(content_list: list, notice_info: dict):
dingtalk_access_token = notice_info.get("dingtalk_access_token")
fskey = notice_info.get("fskey")
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")
sendkey = notice_info.get("sendkey")
qmsg_key = notice_info.get("qmsg_key")
Expand Down Expand Up @@ -243,13 +258,13 @@ def push_message(content_list: list, notice_info: dict):
print("获取重要通知失败:", e)
if merge_push is None:
if (
qmsg_key
or coolpushskey
or qywx_touser
or qywx_corpsecret
or qywx_agentid
or bark_url
or pushplus_token
qmsg_key
or coolpushskey
or qywx_touser
or qywx_corpsecret
or qywx_agentid
or bark_url
or pushplus_token
):
merge_push = False
else:
Expand Down Expand Up @@ -288,7 +303,15 @@ def push_message(content_list: list, notice_info: dict):
print("企业微信应用消息推送失败", e)
if bark_url:
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:
print("Bark 推送失败", e)
if dingtalk_access_token and dingtalk_secret:
Expand Down
5 changes: 5 additions & 0 deletions docker/config.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"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,
"COOLPUSHQQ":true,
"COOLPUSHSKEY":"",
Expand Down
15 changes: 13 additions & 2 deletions docs/pages/settings/notify/bark.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,30 @@ import { Callout } from 'nextra/components'
# BARK

<Callout type="warning">
通知消息在 Bark 有长度限制,如果没收到推送,请将 MERGE_PUSH 改为 false
通知消息在 Bark 有长度限制,如果内容过长导致推送失败,会自动切换为单条推送。
</Callout>

### 配置示例

```json filename="config.json" copy
{
"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_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**: 分开推送 |