Skip to content

Commit

Permalink
Merge pull request #451 from qiaoyun680/main
Browse files Browse the repository at this point in the history
增加ntfy和gotify推送方式
  • Loading branch information
Sitoi authored Jan 7, 2025
2 parents e36284c + 0563bbc commit df71bcf
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 4 deletions.
6 changes: 6 additions & 0 deletions dailycheckin/configs.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def checkin_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
}


Expand Down
75 changes: 73 additions & 2 deletions dailycheckin/utils/message.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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(
Expand Down Expand Up @@ -239,7 +284,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:
Expand All @@ -258,6 +308,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:
Expand Down Expand Up @@ -348,7 +400,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())
4 changes: 3 additions & 1 deletion docs/pages/settings/notify/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"qywxrobot": "企业微信群机器人",
"telegram": "Telegram",
"server": "Server 酱",
"turbo": "Server 酱 Turbo"
"turbo": "Server 酱 Turbo",
"ntfy": "Ntfy",
"gotify": "Gotify"
}
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/bark.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/coolpush.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/dingtalk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

# 钉钉
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/settings/notify/feishu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

# 飞书

### 配置示例
Expand Down
77 changes: 77 additions & 0 deletions docs/pages/settings/notify/gotify.mdx
Original file line number Diff line number Diff line change
@@ -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**: 分开推送 |
77 changes: 77 additions & 0 deletions docs/pages/settings/notify/ntfy.mdx
Original file line number Diff line number Diff line change
@@ -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**: 分开推送 |
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/pushplus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/qmsg.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 酱
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/settings/notify/qywx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

# 企业微信应用消息
Expand Down
Loading

0 comments on commit df71bcf

Please sign in to comment.