/
get_friend_list.go
65 lines (52 loc) · 1.54 KB
/
get_friend_list.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
package handlers
import (
"encoding/json"
"github.com/bwmarrin/discordgo"
"github.com/hoshinonyaruko/gensokyo-discord/callapi"
"github.com/hoshinonyaruko/gensokyo-discord/mylog"
)
func init() {
callapi.RegisterHandler("get_friend_list", HandleGetFriendList)
}
type APIOutput struct {
Data []FriendData `json:"data"`
Message string `json:"message"`
RetCode int `json:"retcode"`
Status string `json:"status"`
Echo interface{} `json:"echo"`
}
type FriendData struct {
Nickname string `json:"nickname"`
Remark string `json:"remark"`
UserID string `json:"user_id"`
}
func HandleGetFriendList(client callapi.Client, s *discordgo.Session, message callapi.ActionMessage) (string, error) {
var output APIOutput
for i := 0; i < 10; i++ { // Assume we want to loop 10 times to create friend data
data := FriendData{
Nickname: "小狐狸",
Remark: "",
UserID: "2022717137",
}
output.Data = append(output.Data, data)
}
output.Message = ""
output.RetCode = 0
output.Status = "ok"
output.Echo = message.Echo
// Convert the APIOutput structure to a map[string]interface{}
outputMap := structToMap(output)
// Send the map
err := client.SendMessage(outputMap) //发回去
if err != nil {
mylog.Printf("error sending friend list via wsclient: %v", err)
}
result, err := json.Marshal(output)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
//todo 符合onebotv11 ws返回的错误码
return "", nil
}
mylog.Printf("get_friend_list: %s", result)
return string(result), nil
}