/
get_status.go
86 lines (74 loc) · 2.43 KB
/
get_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package handlers
import (
"encoding/json"
"github.com/hoshinonyaruko/gensokyo-kook/callapi"
"github.com/hoshinonyaruko/gensokyo-kook/mylog"
)
type GetStatusResponse struct {
Data StatusData `json:"data"`
Message string `json:"message"`
RetCode int `json:"retcode"`
Status string `json:"status"`
Echo interface{} `json:"echo"`
}
type StatusData struct {
AppInitialized bool `json:"app_initialized"`
AppEnabled bool `json:"app_enabled"`
PluginsGood bool `json:"plugins_good"`
AppGood bool `json:"app_good"`
Online bool `json:"online"`
Good bool `json:"good"`
Stat Statistics `json:"stat"`
}
type Statistics struct {
PacketReceived uint64 `json:"packet_received"`
PacketSent uint64 `json:"packet_sent"`
PacketLost uint32 `json:"packet_lost"`
MessageReceived uint64 `json:"message_received"`
MessageSent uint64 `json:"message_sent"`
DisconnectTimes uint32 `json:"disconnect_times"`
LostTimes uint32 `json:"lost_times"`
LastMessageTime int64 `json:"last_message_time"`
}
func init() {
callapi.RegisterHandler("get_status", GetStatus)
}
func GetStatus(client callapi.Client, Token string, BaseUrl string, message callapi.ActionMessage) (string, error) {
var response GetStatusResponse
response.Data = StatusData{
AppInitialized: true,
AppEnabled: true,
PluginsGood: true,
AppGood: true,
Online: true, //测试数据
Good: true, //测试数据
Stat: Statistics{
PacketReceived: 1000, //测试数据
PacketSent: 950, //测试数据
PacketLost: 50, //测试数据
MessageReceived: 500, //测试数据
MessageSent: 490, //测试数据
DisconnectTimes: 5, //测试数据
LostTimes: 2, //测试数据
LastMessageTime: 1677721600, //测试数据
},
}
response.Message = ""
response.RetCode = 0
response.Status = "ok"
response.Echo = message.Echo
outputMap := structToMap(response)
mylog.Printf("get_status: %+v\n", outputMap)
err := client.SendMessage(outputMap)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
}
//把结果从struct转换为json
result, err := json.Marshal(response)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
//todo 符合onebotv11 ws返回的错误码
return "", nil
}
return string(result), nil
}