feat: 添加群组和群成员信息获取功能
- 新增 action/group_member.go 文件,实现获取群组列表和群成员列表的方法 - 在 constants/uri.go 中定义群组相关的 API 路径常量 - 在 model/group.go 中添加群组和群成员的数据结构定义
This commit is contained in:
parent
711c4fd3d6
commit
db4d232464
58
action/group_member.go
Normal file
58
action/group_member.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
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
|
||||||
|
}
|
6
constants/uri.go
Normal file
6
constants/uri.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package constants
|
||||||
|
|
||||||
|
const (
|
||||||
|
GET_GROUP_LIST = "/get_group_list"
|
||||||
|
GET_GROUP_MEMBER_LIST = "/get_group_member_list"
|
||||||
|
)
|
47
model/group.go
Normal file
47
model/group.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
GroupID int64 `json:"group_id"`
|
||||||
|
GroupName string `json:"group_name"`
|
||||||
|
MemberCount int `json:"member_count"`
|
||||||
|
MaxMemberCount int `json:"max_member_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupListResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Retcode int `json:"retcode"`
|
||||||
|
Data []Group `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Wording string `json:"wording"`
|
||||||
|
Echo string `json:"echo"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupMember struct {
|
||||||
|
GroupID int64 `json:"group_id"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Card string `json:"card"`
|
||||||
|
Sex string `json:"sex"`
|
||||||
|
Age int `json:"age"`
|
||||||
|
Area string `json:"area"`
|
||||||
|
Level string `json:"level"`
|
||||||
|
QQLevel int `json:"qq_level"`
|
||||||
|
JoinTime int `json:"join_time"`
|
||||||
|
LastSentTime int `json:"last_sent_time"`
|
||||||
|
TitleExpireTime int `json:"title_expire_time"`
|
||||||
|
Unfriendly bool `json:"unfriendly"`
|
||||||
|
CardChangeable bool `json:"card_changeable"`
|
||||||
|
IsRobot bool `json:"is_robot"`
|
||||||
|
ShutUpTimestamp int `json:"shut_up_timestamp"`
|
||||||
|
Role string `json:"role"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupMemberListResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Retcode int `json:"retcode"`
|
||||||
|
Data []GroupMember `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Wording string `json:"wording"`
|
||||||
|
Echo string `json:"echo"`
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user