mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 17:28:53 +02:00
[BREAKING] changed notification config format, support multiple notification providers, support webhook and markdown style notification
This commit is contained in:
36
internal/notif/format.go
Normal file
36
internal/notif/format.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package notif
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func formatMarkdown(extras map[string]interface{}) string {
|
||||
msg := bytes.NewBufferString("")
|
||||
for k, v := range extras {
|
||||
msg.WriteString("#### ")
|
||||
msg.WriteString(k)
|
||||
msg.WriteRune('\n')
|
||||
msg.WriteString(fmt.Sprintf("%v", v))
|
||||
msg.WriteRune('\n')
|
||||
}
|
||||
return msg.String()
|
||||
}
|
||||
|
||||
func formatDiscord(extras map[string]interface{}) (string, error) {
|
||||
fieldsMap := make([]map[string]any, len(extras))
|
||||
i := 0
|
||||
for k, extra := range extras {
|
||||
fieldsMap[i] = map[string]any{
|
||||
"name": k,
|
||||
"value": extra,
|
||||
}
|
||||
i++
|
||||
}
|
||||
fields, err := json.Marshal(fieldsMap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(fields), nil
|
||||
}
|
||||
Reference in New Issue
Block a user