-
Notifications
You must be signed in to change notification settings - Fork 42
/
get_login_info.go
74 lines (61 loc) · 1.81 KB
/
get_login_info.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
package handlers
import (
"encoding/json"
"fmt"
"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/openapi"
)
type LoginInfoResponse struct {
Data LoginInfoData `json:"data"`
Message string `json:"message"`
RetCode int `json:"retcode"`
Status string `json:"status"`
Echo interface{} `json:"echo"`
}
type LoginInfoData struct {
Nickname string `json:"nickname"`
UserID string `json:"user_id"` // Assuming UserID is a string type based on the pseudocode
}
func init() {
callapi.RegisterHandler("get_login_info", GetLoginInfo)
}
func GetLoginInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) (string, error) {
var response LoginInfoResponse
var botname string
var globalBotID uint64
// 获取机器人ID
if config.GetUseUin() {
globalBotID = uint64(config.GetUinint64())
} else {
globalBotID = config.GetAppID()
}
userIDStr := fmt.Sprintf("%d", globalBotID)
botname = config.GetCustomBotName()
response.Data = LoginInfoData{
Nickname: botname,
UserID: userIDStr,
}
response.Message = ""
response.RetCode = 0
response.Status = "ok"
response.Echo = message.Echo
// Convert the members slice to a map
outputMap := structToMap(response)
mylog.Printf("get_login_info: %+v\n", outputMap)
err := client.SendMessage(outputMap)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
} else {
mylog.Printf("响应get_login_info: %+v", outputMap)
}
//把结果从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
}