This commit is contained in:
qiaoyun680 2024-10-23 09:16:53 +00:00 committed by GitHub
commit d984dad9e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 324 additions and 4 deletions

6
dailycheckin/configs.py Executable file → Normal file
View File

@ -41,6 +41,12 @@ notice_map = {
"TG_PROXY": "",
"TG_USER_ID": "",
"MERGE_PUSH": "",
'GOTIFY_URL': "", # gotify地址,如https://push.example.de:8080
'GOTIFY_TOKEN': "", # gotify的消息应用token
'GOTIFY_PRIORITY': "", # 推送消息优先级,默认为0
'NTFY_URL': "", # ntfy地址,如https://ntfy.sh
'NTFY_TOPIC': "", # ntfy的消息应用topic
'NTFY_PRIORITY': "", # 推送消息优先级,默认为3
}

75
dailycheckin/utils/message.py Executable file → Normal file
View File

@ -189,6 +189,51 @@ def message2pushplus(pushplus_token, content, pushplus_topic=None):
requests.post(url="http://www.pushplus.plus/send", data=json.dumps(data))
return
def message2gotify(gotify_url: str, gotify_token: str, gotify_priority: str, content: str) -> None:
print("Gotify 服务启动")
if not gotify_priority:
gotify_priority = "3"
url = "{}/message?token={}".format(gotify_url, gotify_token)
data = {
"title": "Dailycheckin签到通知",
"message": content,
"priority": gotify_priority,
}
response = requests.post(url, data=data).json()
if response.get("id"):
print("Gotify 推送成功!")
else:
print("Gotify 推送失败!")
return
def message2ntfy(ntfy_url: str, ntfy_topic: str, ntfy_priority: str, content: str) -> None:
def encode_rfc2047(text: str) -> str:
"""将文本编码为符合 RFC 2047 标准的格式"""
encoded_bytes = base64.b64encode(text.encode('utf-8'))
encoded_str = encoded_bytes.decode('utf-8')
return f'=?utf-8?B?{encoded_str}?='
print("Ntfy 服务启动")
if not ntfy_url:
ntfy_url = "https://ntfy.sh"
if not ntfy_priority:
ntfy_priority = "3"
# 使用 RFC 2047 编码 title
encoded_title = encode_rfc2047("Dailycheckin签到通知")
data = content.encode(encoding='utf-8')
headers = {
"Title": encoded_title, # 使用编码后的 title
"Priority": ntfy_priority
}
url = "{}/{}".format(ntfy_url, ntfy_topic)
response = requests.post(url, data=data, headers=headers)
if response.status_code == 200: # 使用 response.status_code 进行检查
print("Ntfy 推送成功!")
else:
print("Ntfy 推送失败!错误信息:", response.text)
def important_notice():
datas = requests.get(
@ -231,7 +276,12 @@ def push_message(content_list: list, notice_info: dict):
qywx_origin = notice_info.get("qywx_origin")
pushplus_token = notice_info.get("pushplus_token")
pushplus_topic = notice_info.get("pushplus_topic")
merge_push = notice_info.get("merge_push")
gotify_url = notice_info.get("gotify_url")
gotify_token = notice_info.get("gotify_token")
gotify_priority = notice_info.get("gotify_priority")
ntfy_url = notice_info.get("ntfy_url")
ntfy_topic = notice_info.get("ntfy_topic")
ntfy_priority = notice_info.get("ntfy_priority")
content_str = "\n————————————\n\n".join(content_list)
message_list = [content_str]
try:
@ -250,6 +300,8 @@ def push_message(content_list: list, notice_info: dict):
or qywx_agentid
or bark_url
or pushplus_token
or ntfy_topic
or (gotify_url and gotify_token)
):
merge_push = False
else:
@ -340,7 +392,26 @@ def push_message(content_list: list, notice_info: dict):
)
except Exception as e:
print("Telegram 推送失败", e)
if gotify_url and gotify_token:
try:
message2gotify(
gotify_url=gotify_url,
gotify_token=gotify_token,
gotify_priority=gotify_priority,
content=message,
)
except Exception as e:
print("Gotify 推送失败", e)
if ntfy_topic:
try:
message2ntfy(
ntfy_url=ntfy_url,
ntfy_topic=ntfy_topic,
ntfy_priority=ntfy_priority,
content=message,
)
except Exception as e:
print("Ntfy 推送失败", e)
if __name__ == "__main__":
print(important_notice())

View File

@ -9,5 +9,7 @@
"qywxrobot": "企业微信群机器人",
"telegram": "Telegram",
"server": "Server 酱",
"turbo": "Server 酱 Turbo"
"turbo": "Server 酱 Turbo",
"ntfy": "Ntfy",
"gotify": "Gotify"
}

View File

@ -46,6 +46,14 @@ import { Callout } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# BARK

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# CoolPush

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# 钉钉

View File

@ -45,8 +45,15 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# 飞书
### 配置示例

View File

@ -0,0 +1,77 @@
import { Cards, Card } from 'nextra/components'
import { Callout } from 'nextra/components'
<Cards>
<Card
title="BARK"
href="/settings/notify/bark"
/>
<Card
title="CoolPush"
href="/settings/notify/coolpush"
/>
<Card
title="钉钉"
href="/settings/notify/dingtalk"
/>
<Card
title="飞书"
href="/settings/notify/feishu"
/>
<Card
title="PushPlus"
href="/settings/notify/pushplus"
/>
<Card
title="Qmsg 酱"
href="/settings/notify/qmsg"
/>
<Card
title="企业微信应用消息"
href="/settings/notify/qywx"
/>
<Card
title="企业微信群机器人"
href="/settings/notify/qywxrobot"
/>
<Card
title="Server 酱"
href="/settings/notify/server"
/>
<Card
title="Telegram"
href="/settings/notify/telegram"
/>
<Card
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# GOTIFY
### 配置示例
```json filename="config.json" copy
{
"GOTIFY_URL": "",
"GOTIFY_TOKEN": "",
"GOTIFY_PRIORITY": "",
}
```
| 参数 | 说明 |
| :--------------: | :--------------------------------------------------------------------------------------------: |
| _**GOTIFY_URL**_ | [GOTIFY] ,填写 `GOTIFY_URL` |
| _**GOTIFY_TOKEN**_| 填写 `GOTIFY_TOKEN` |
| _**GOTIFY_PRIORITY**_| 填写 `GOTIFY_PRIORITY` |
| _**MERGE_PUSH**_ | **true**: 将推送消息合并;**false**: 分开推送 |

View File

@ -0,0 +1,77 @@
import { Cards, Card } from 'nextra/components'
import { Callout } from 'nextra/components'
<Cards>
<Card
title="BARK"
href="/settings/notify/bark"
/>
<Card
title="CoolPush"
href="/settings/notify/coolpush"
/>
<Card
title="钉钉"
href="/settings/notify/dingtalk"
/>
<Card
title="飞书"
href="/settings/notify/feishu"
/>
<Card
title="PushPlus"
href="/settings/notify/pushplus"
/>
<Card
title="Qmsg 酱"
href="/settings/notify/qmsg"
/>
<Card
title="企业微信应用消息"
href="/settings/notify/qywx"
/>
<Card
title="企业微信群机器人"
href="/settings/notify/qywxrobot"
/>
<Card
title="Server 酱"
href="/settings/notify/server"
/>
<Card
title="Telegram"
href="/settings/notify/telegram"
/>
<Card
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# NTFY
### 配置示例
```json filename="config.json" copy
{
"NTFY_URL": "",
"NTFY_TOPIC": "",
"NTFY_PRIORITY": "",
}
```
| 参数 | 说明 |
| :--------------: | :--------------------------------------------------------------------------------------------: |
| _**NTFY_URL**_ | [NTFY](https://ntfy.sh) ,填写 `NTFY_URL` 例: `https://ntfy.sh` 也可以自建服务端 |
| _**NTFY_TOPIC**_| 填写 `NTFY_TOPIC` 例: `dailycheckin` |
| _**NTFY_PRIORITY**_| 填写 `NTFY_PRIORITY` 例: `3`, 默认为3 |
| _**MERGE_PUSH**_ | **true**: 将推送消息合并;**false**: 分开推送 |

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# PushPlus

View File

@ -46,6 +46,14 @@ import { Callout } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# Qmsg 酱

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# 企业微信应用消息

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# 企业微信群机器人

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# Server 酱

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# Telegram

View File

@ -45,6 +45,14 @@ import { Cards, Card } from 'nextra/components'
title="Server 酱 TURBO"
href="/settings/notify/turbo"
/>
<Card
title="Ntfy"
href="/settings/notify/ntfy"
/>
<Card
title="Gotify"
href="/settings/notify/gotify"
/>
</Cards>
# Server 酱 TURBO