fix: 按网站接口收发账号和日志
This commit is contained in:
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -78,13 +79,15 @@ func (e *Engine) Accept(from, raw string) ([]Outbox, []protocol.Log, error) {
|
||||
return e.acceptCommand(from, msg.ID, "", true, msg.ShortcutID)
|
||||
case protocol.TypeText:
|
||||
return nil, nil, e.acceptText(from, msg)
|
||||
case protocol.TypeShortcuts:
|
||||
case protocol.TypeShortcuts, protocol.TypeShortcutsGet:
|
||||
if msg.Type == protocol.TypeShortcutsGet || !jsonHasItems(raw) {
|
||||
return e.replyShortcuts(from, msg.ID)
|
||||
}
|
||||
return nil, nil, e.acceptShortcuts(from, msg)
|
||||
case protocol.TypeShortcutsGet:
|
||||
return e.replyShortcuts(from, msg.ID)
|
||||
case protocol.TypeLogsGet:
|
||||
return e.replyLogs(from, msg.ID)
|
||||
case protocol.TypeLogs:
|
||||
case protocol.TypeLogs, protocol.TypeLogsGet:
|
||||
if msg.Type == protocol.TypeLogsGet || !jsonHasItems(raw) {
|
||||
return e.replyLogs(from, msg.ID)
|
||||
}
|
||||
return nil, nil, e.acceptLogs(from, msg)
|
||||
case protocol.TypeResult:
|
||||
return nil, nil, e.acceptResult(from, msg)
|
||||
@@ -93,6 +96,16 @@ func (e *Engine) Accept(from, raw string) ([]Outbox, []protocol.Log, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func jsonHasItems(raw string) bool {
|
||||
var probe struct {
|
||||
Items json.RawMessage `json:"items"`
|
||||
}
|
||||
if json.Unmarshal([]byte(raw), &probe) != nil || len(probe.Items) == 0 {
|
||||
return false
|
||||
}
|
||||
return string(probe.Items) != "null"
|
||||
}
|
||||
|
||||
func (e *Engine) acceptCommand(from, id, script string, shortcut bool, shortcutID string) ([]Outbox, []protocol.Log, error) {
|
||||
if !idutil.ValidMessage(id) {
|
||||
return nil, nil, nil
|
||||
|
||||
Reference in New Issue
Block a user