Skip to content

Commit 45dbd8e

Browse files
committed
new: push format `{{name}}
1 parent af74bbb commit 45dbd8e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

model/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ var (
122122
"action": "send_group_msg",
123123
"params": map[string]interface{}{
124124
"group_id": 123456789,
125-
"message": "Server1\n" + res.PushFormatLocator,
125+
"message": res.PushFormatNameLocator +
126+
"\n" +
127+
res.PushFormatMsgLocator,
126128
},
127129
}
128130
defaultWekhookBodyBytes, _ = json.Marshal(defaultWebhookBody)

model/push.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,19 @@ func (pf PushFormat) Format(args []*PushPair) string {
7878
kv := fmt.Sprintf(`%s\n%s: %s`, arg.time, arg.key, arg.value)
7979
ss = append(ss, kv)
8080
}
81-
return strings.Replace(
82-
string(pf),
83-
res.PushFormatLocator,
84-
strings.Join(ss, `\n`), 1)
81+
msgReplaced := strings.Replace(
82+
string(pf),
83+
res.PushFormatMsgLocator,
84+
strings.Join(ss, `\n`),
85+
1,
86+
)
87+
nameReplaced := strings.Replace(
88+
msgReplaced,
89+
res.PushFormatNameLocator,
90+
Config.Name,
91+
1,
92+
)
93+
return nameReplaced
8594
}
8695

8796
type PushType string

res/res.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const (
3636
DefaultInterval = time.Second * 7
3737
MaxInterval = time.Second * 10
3838

39-
PushFormatLocator = "{{msg}}"
39+
PushFormatMsgLocator = "{{msg}}"
40+
PushFormatNameLocator = "{{name}}"
4041
)
4142

4243
func init() {

0 commit comments

Comments
 (0)