From a3fe651ce2deaa2c04791ee3a9af01707ed255ab Mon Sep 17 00:00:00 2001 From: LastNever Date: Thu, 14 Mar 2024 10:53:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bark=E6=8E=A8=E9=80=81=E5=8A=A0=E5=85=A5tit?= =?UTF-8?q?le\group\icon\sound\url=E5=8F=82=E6=95=B0=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=BF=87=E9=95=BF=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BA=E5=88=86=E6=89=B9=E5=8F=91=E9=80=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dailycheckin/configs.py | 5 +++ dailycheckin/utils/message.py | 69 +++++++++++++++++++++++------------ docker/config.template.json | 5 +++ 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/dailycheckin/configs.py b/dailycheckin/configs.py index b8c0da1c5..529a09f9f 100755 --- a/dailycheckin/configs.py +++ b/dailycheckin/configs.py @@ -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": "", diff --git a/dailycheckin/utils/message.py b/dailycheckin/utils/message.py index f92795a29..4dc78e761 100755 --- a/dailycheckin/utils/message.py +++ b/dailycheckin/utils/message.py @@ -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": "每日签到"} @@ -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): @@ -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" @@ -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") @@ -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: @@ -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: diff --git a/docker/config.template.json b/docker/config.template.json index 38ff48ff9..8a388f0ac 100644 --- a/docker/config.template.json +++ b/docker/config.template.json @@ -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":"", From 947a5daa9847c23f538a0ab5005eeac18fc20106 Mon Sep 17 00:00:00 2001 From: LastNever Date: Thu, 14 Mar 2024 15:14:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bark=E6=8E=A8=E9=80=81=E5=8A=A0=E5=85=A5tit?= =?UTF-8?q?le\group\icon\sound\url=E5=8F=82=E6=95=B0=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=BF=87=E9=95=BF=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BA=E5=88=86=E6=89=B9=E5=8F=91=E9=80=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/pages/settings/notify/bark.mdx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/pages/settings/notify/bark.mdx b/docs/pages/settings/notify/bark.mdx index fff5b12d4..d33197d95 100644 --- a/docs/pages/settings/notify/bark.mdx +++ b/docs/pages/settings/notify/bark.mdx @@ -51,7 +51,7 @@ import { Callout } from 'nextra/components' # BARK - 通知消息在 Bark 有长度限制,如果没收到推送,请将 MERGE_PUSH 改为 false + 通知消息在 Bark 有长度限制,如果内容过长导致推送失败,会自动切换为单条推送。 ### 配置示例 @@ -59,11 +59,22 @@ import { Callout } from 'nextra/components' ```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**: 分开推送 |