Skip to content

Commit

Permalink
[Feat] Add Bark Subscription (#39)
Browse files Browse the repository at this point in the history
* 新增bark推送
  • Loading branch information
rxxcy authored Mar 9, 2023
1 parent 01b9c49 commit bcc8f9c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
output/
login_info.txt
users.yaml
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- 可选需要的打卡类型
- 本日亲密度已满徽章不重复打卡
- 多账号支持
- 多种推送通知 (PushDeer PushPlus Telegram)
- 多种推送通知 (PushDeer PushPlus Telegram Bark
- 同步异步配置

<small>ps: 新版 B 站粉丝牌的亲密度每一个牌子都将单独计算</small>
Expand Down
24 changes: 24 additions & 0 deletions service/push/bark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package push

import (
"github.com/ThreeCatsLoveFish/medalhelper/manager"
"github.com/ThreeCatsLoveFish/medalhelper/util"
"net/url"
)

const BarkName = "bark"

type BarkPush struct {
util.Endpoint
}

func (push BarkPush) Submit(pd Data) error {
data := url.Values{
"device_key": []string{push.Token},
"title": []string{pd.Title},
"body": []string{pd.Content},
}

_, err := manager.Post(push.URL, data)
return err
}
2 changes: 2 additions & 0 deletions service/push/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func SetEndpoint(endpoint util.Endpoint) {
addPush(endpoint.Name, PushPlusPush{endpoint})
case TelegramName:
addPush(endpoint.Name, TelegramPush{endpoint})
case BarkName:
addPush(endpoint.Name, BarkPush{endpoint})
}
}

Expand Down
17 changes: 17 additions & 0 deletions service/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,20 @@ func TestTelegramPush(t *testing.T) {
t.Fatalf("Push error: %v", err)
}
}

func TestBarkPush(t *testing.T) {
push := BarkPush{
util.Endpoint{
Name: "push",
Type: "bark",
URL: "https://<bark-url-or-ip>/push",
Token: "<YOUR-TOKEN>",
},
}
if err := push.Submit(Data{
Title: "test",
Content: "Good Morning!",
}); err != nil {
t.Fatalf("Push error: %v", err)
}
}
6 changes: 5 additions & 1 deletion users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ PUSH:
token: "<YOUR-TELEGRAM-CHATID>"
type: "telegram"
url: "https://api.telegram.org/bot<YOUR-BOT-TOKEN-HERE>/sendMessage"
- name: "BARK"
token: "<YOUR-TOKEN-HERE>"
type: "bark"
url: "http://<bark-url-or-ip>/push"
# 推送服务,每日打卡成功或报错日志推送
# 目前支持PushDeer, PushPlus, Telegram
# 目前支持PushDeer, PushPlus, Telegram, Bark

0 comments on commit bcc8f9c

Please sign in to comment.