Skip to content

Commit

Permalink
add MeoW Support
Browse files Browse the repository at this point in the history
It looks like the Bark server
  • Loading branch information
Janet-Baker committed Jan 14, 2025
1 parent 92716f9 commit e6d85e5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ address: '127.0.0.1:14000'
contact_bilibili: true
```
### 需要Bark推送的
### iOS用户,需要Bark推送的
```yaml
Bark:
Expand All @@ -53,6 +53,13 @@ Bark:
- url: "https://api.day.app/"
device_key: "xCVBNMASDFGHJKLERTYUIO"
```
### HarmonyOS用户,需要Bark推送的
```yaml
Meow:
- username: "a10000000"
- username: ""
```
### 需要企业微信应用消息的
Expand Down
4 changes: 4 additions & 0 deletions defaultConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Bark:
- url: "https://api.day.app/"
device_key: ""

Meow:
- username: ""
- username: ""

WXWorkApp:
# - corpId: "ww123456789a01b2c3"
# appSecret: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFG"
Expand Down
10 changes: 10 additions & 0 deletions loadConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ConfigLoader struct {
ContactBilibili bool `yaml:"contact_bilibili"`
Barks []messageSender.BarkServer `yaml:"Bark"`
WXWorkApps []messageSender.WXWorkAppTarget `yaml:"WXWorkApp"`
Meow []messageSender.MeowServer `yaml:"Meow"`
Receivers []Receiver `yaml:"Receivers"`
}

Expand Down Expand Up @@ -87,6 +88,15 @@ func loadConfig() initStruct {
senderCount++
}
}
if len(configuration.Meow) > 0 {
for i := 0; i < len(configuration.Meow); i++ {
if configuration.Meow[i].Username == "" {
continue
}
configuration.Meow[i].RegisterServer()
senderCount++
}
}
if len(configuration.WXWorkApps) > 0 {
for i := 0; i < len(configuration.WXWorkApps); i++ {
if configuration.WXWorkApps[i].CorpId == "" || configuration.WXWorkApps[i].AppSecret == "" || configuration.WXWorkApps[i].AgentID == "" {
Expand Down
56 changes: 56 additions & 0 deletions messageSender/sendMeowMessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package messageSender

import (
"bytes"
"errors"
log "github.com/sirupsen/logrus"
"io"
"net/http"
"net/url"
)

const meowServerUrl = "http://api.chuckfang.com/"

type MeowServer struct {
Username string `yaml:"username"`
}

func (m MeowServer) RegisterServer() {
RegisterMessageServer(m)
}

func (m MeowServer) SendMessage(message Message) {
err := m.sendMessage(message)
if err != nil {
log.Error("发送MeoW消息失败:", err)
}
}

func (m MeowServer) sendMessage(message Message) error {
if message == nil {
return errors.New("发送MeoW消息失败:消息为空")
}
target, err := url.JoinPath(meowServerUrl, m.Username, message.GetTitle(), message.GetContent())
if err != nil {
log.Error("发送MeoW消息失败:", err)
return err
}
resp, err := http.Get(target)
if err != nil {
log.Error("发送MeoW消息失败:", err)
return err
}
defer func(Body io.Closer) {
_ = Body.Close()
}(resp.Body)

if log.IsLevelEnabled(log.DebugLevel) {
buf := bytesBufferPool.Get().(*bytes.Buffer)
buf.Reset() // Reset the buffer for reuse
defer bytesBufferPool.Put(buf) // Return the buffer to the pool
_, _ = buf.ReadFrom(resp.Body)
log.Debug("发送MeoW消息响应:", buf.String())
}

return nil
}
19 changes: 19 additions & 0 deletions messageSender/sendMeowMessage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package messageSender

import (
"testing"
"time"
)

func TestMeowServer_sendMessage(t *testing.T) {
var target = MeowServer{Username: "xiaopangzi"}
var msg = GeneralPushMessage{
Title: "测试标题" + time.Now().String(),
Content: "测试内容" + time.Now().GoString(),
IconURL: "",
}
err := target.sendMessage(&msg)
if err != nil {
t.Fail()
}
}

0 comments on commit e6d85e5

Please sign in to comment.