modify line command multiple reply or push message
This commit is contained in:
parent
afc0987d40
commit
cc67ba4738
@ -104,9 +104,9 @@ func checkMessageObject(m interface{}) interface{} {
|
||||
}
|
||||
|
||||
// PushMessage -
|
||||
func PushMessage(target string, message interface{}) {
|
||||
func PushMessage(target string, message ...interface{}) {
|
||||
log.Println("push target :::: ", target)
|
||||
if len(target) == 0 {
|
||||
if len(target) == 0 || len(message) == 0 {
|
||||
return
|
||||
}
|
||||
urlPath := "/v2/bot/message/push"
|
||||
@ -115,9 +115,19 @@ func PushMessage(target string, message interface{}) {
|
||||
To: target,
|
||||
}
|
||||
|
||||
message = checkMessageObject(message)
|
||||
checked := make([]interface{}, 0)
|
||||
for _, v := range message {
|
||||
tmp := checkMessageObject(v)
|
||||
if tmp == nil {
|
||||
continue
|
||||
}
|
||||
checked = append(checked, tmp)
|
||||
}
|
||||
|
||||
body.Messages = append(body.Messages, message)
|
||||
body.Messages = append(body.Messages, checked...)
|
||||
if len(body.Messages) > 5 {
|
||||
body.Messages = body.Messages[:5]
|
||||
}
|
||||
dataByte, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
log.Println("to json error ::::", err)
|
||||
@ -153,8 +163,8 @@ func PushMessage(target string, message interface{}) {
|
||||
}
|
||||
|
||||
// ReplyMessage -
|
||||
func ReplyMessage(replyToken string, message interface{}) {
|
||||
if len(replyToken) == 0 {
|
||||
func ReplyMessage(replyToken string, message ...interface{}) {
|
||||
if len(replyToken) == 0 || len(message) == 0 {
|
||||
return
|
||||
}
|
||||
urlPath := "/v2/bot/message/reply"
|
||||
@ -163,9 +173,19 @@ func ReplyMessage(replyToken string, message interface{}) {
|
||||
ReplyToken: replyToken,
|
||||
}
|
||||
|
||||
message = checkMessageObject(message)
|
||||
checked := make([]interface{}, 0)
|
||||
for _, v := range message {
|
||||
tmp := checkMessageObject(v)
|
||||
if tmp == nil {
|
||||
continue
|
||||
}
|
||||
checked = append(checked, tmp)
|
||||
}
|
||||
|
||||
body.Messages = append(body.Messages, message)
|
||||
body.Messages = append(body.Messages, checked...)
|
||||
if len(body.Messages) > 5 {
|
||||
body.Messages = body.Messages[:5]
|
||||
}
|
||||
dataByte, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -51,9 +51,13 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
|
||||
return
|
||||
}
|
||||
|
||||
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||
m := parseResult(str)
|
||||
line.ReplyMessage(replyToken, m)
|
||||
resStrs := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||
msgs := make([]interface{}, 0)
|
||||
for _, v := range resStrs {
|
||||
m := parseResult(v)
|
||||
msgs = append(msgs, m)
|
||||
}
|
||||
line.ReplyMessage(replyToken, msgs...)
|
||||
|
||||
} else {
|
||||
// key cmd
|
||||
@ -62,9 +66,13 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
|
||||
return
|
||||
}
|
||||
|
||||
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||
m := parseResult(str)
|
||||
line.ReplyMessage(replyToken, m)
|
||||
resStrs := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||
msgs := make([]interface{}, 0)
|
||||
for _, v := range resStrs {
|
||||
m := parseResult(v)
|
||||
msgs = append(msgs, m)
|
||||
}
|
||||
line.ReplyMessage(replyToken, msgs...)
|
||||
|
||||
}
|
||||
}
|
||||
@ -95,23 +103,31 @@ func parseResult(str string) interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func runCMD(txt, c string, s *lineobj.SourceObject) (res string) {
|
||||
cmdAct := parseCMD(c)
|
||||
if len(cmdAct) == 0 {
|
||||
return c
|
||||
func runCMD(txt, c string, s *lineobj.SourceObject) (res []string) {
|
||||
cmds := strings.Split(c, "$#$")
|
||||
if len(cmds) == 0 {
|
||||
return
|
||||
}
|
||||
res = c
|
||||
for _, v := range cmdAct {
|
||||
if len(v) > 1 {
|
||||
// run cmd
|
||||
m := strings.Split(v[1], "=")
|
||||
sub := ""
|
||||
if len(m) > 1 {
|
||||
sub = strings.Join(m[1:], " ")
|
||||
}
|
||||
cmdRes := selectAct(m[0], sub, txt, s)
|
||||
res = strings.Replace(res, v[0], cmdRes, 1)
|
||||
for _, c := range cmds {
|
||||
cmdAct := parseCMD(c)
|
||||
if len(cmdAct) == 0 {
|
||||
res = append(res, c)
|
||||
continue
|
||||
}
|
||||
tmpRes := c
|
||||
for _, v := range cmdAct {
|
||||
if len(v) > 1 {
|
||||
// run cmd
|
||||
m := strings.Split(v[1], "=")
|
||||
sub := ""
|
||||
if len(m) > 1 {
|
||||
sub = strings.Join(m[1:], " ")
|
||||
}
|
||||
cmdRes := selectAct(m[0], sub, txt, s)
|
||||
tmpRes = strings.Replace(tmpRes, v[0], cmdRes, 1)
|
||||
}
|
||||
}
|
||||
res = append(res, tmpRes)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user