- 新增 action/group_member.go 文件,实现获取群组列表和群成员列表的方法 - 在 constants/uri.go 中定义群组相关的 API 路径常量 - 在 model/group.go 中添加群组和群成员的数据结构定义
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package action
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"git.lxtend.com/qqbot/config"
|
|
"git.lxtend.com/qqbot/constants"
|
|
"git.lxtend.com/qqbot/model"
|
|
)
|
|
|
|
func GetGroupMemberList(groupID int64) ([]model.GroupMember, error) {
|
|
fullURL := fmt.Sprintf("http://%s%s?group_id=%d", config.ConfigManager.GetConfig().NapcatHttpSrv, constants.GET_GROUP_MEMBER_LIST, groupID)
|
|
|
|
response, err := http.Get(fullURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
body, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var groupMemberListResponse model.GroupMemberListResponse
|
|
err = json.Unmarshal(body, &groupMemberListResponse)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return groupMemberListResponse.Data, nil
|
|
}
|
|
|
|
func GetGroupList() ([]model.Group, error) {
|
|
fullURL := fmt.Sprintf("http://%s%s", config.ConfigManager.GetConfig().NapcatHttpSrv, constants.GET_GROUP_LIST)
|
|
|
|
response, err := http.Get(fullURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
body, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var groupListResponse model.GroupListResponse
|
|
err = json.Unmarshal(body, &groupListResponse)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return groupListResponse.Data, nil
|
|
}
|