feat: 添加获取登录账户信息的功能,并更新相关数据结构和常量

This commit is contained in:
lixiangwuxian 2025-04-10 01:13:28 +08:00
parent 546f1abcd1
commit eba07290a9
5 changed files with 49 additions and 14 deletions

View File

@ -104,15 +104,3 @@ func (am *actionManager) DrawbackMsg(msgId int32) error {
}
return nil
}
func (am *actionManager) GetGroupMemberList(groupId int64) ([]int64, error) {
askGroupMemberListPkg := model.GenGetGroupMemberListPkg(groupId)
askGroupMemberListPkgJson, err := json.Marshal(askGroupMemberListPkg)
if err != nil {
return nil, err
}
if err = am.botConn.WriteMessage(websocket.TextMessage, askGroupMemberListPkgJson); err != nil {
return nil, err
}
return nil, nil //todo
}

View File

@ -56,3 +56,26 @@ func GetGroupList() ([]model.Group, error) {
return groupListResponse.Data, nil
}
func (am *actionManager) GetLoginAccountInfo() (*model.LoginAccountInfoResponse, error) {
fullURL := fmt.Sprintf("http://%s%s", config.ConfigManager.GetConfig().Management.NapcatHttpSrv, constants.GET_LOGIN_INFO)
response, err := http.Post(fullURL, "application/json", nil)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
var loginAccountInfoResponse model.LoginAccountInfoResponse
err = json.Unmarshal(body, &loginAccountInfoResponse)
if err != nil {
return nil, err
}
return &loginAccountInfoResponse, nil
}

View File

@ -3,4 +3,5 @@ package constants
const (
GET_GROUP_LIST = "/get_group_list"
GET_GROUP_MEMBER_LIST = "/get_group_member_list"
GET_LOGIN_INFO = "/get_login_info"
)

View File

@ -1,6 +1,9 @@
package help
import (
"log"
"strconv"
"git.lxtend.com/qqbot/action"
"git.lxtend.com/qqbot/constants"
"git.lxtend.com/qqbot/handler"
@ -32,8 +35,16 @@ func help(msg model.Message) *model.Reply {
textMsg := message.NewTextMessage()
textMsg.Data.Text = helpInfo
nodeMsg := message.NewNodeMessage()
nodeMsg.Data.UserID = "123456789"
nodeMsg.Data.Nickname = "test"
loginAccountInfo, err := action.ActionManager.GetLoginAccountInfo()
if err != nil {
log.Println("GetLoginAccountInfo error:", err)
return nil
}
if loginAccountInfo == nil {
return nil
}
nodeMsg.Data.UserID = strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10)
nodeMsg.Data.Nickname = loginAccountInfo.Data.Nickname
nodeMsg.Data.Content = []any{&textMsg}
action.ActionManager.SendForward(&model.Reply{
ReplyMsg: []any{&nodeMsg},

View File

@ -45,3 +45,15 @@ type GroupMemberListResponse struct {
Wording string `json:"wording"`
Echo string `json:"echo"`
}
type LoginAccountInfoResponse struct {
Status string `json:"status"`
Retcode int `json:"retcode"`
Data struct {
UserID int `json:"user_id"`
Nickname string `json:"nickname"`
} `json:"data"`
Message string `json:"message"`
Wording string `json:"wording"`
Echo string `json:"echo"`
}