diff --git a/action/action.go b/action/action.go index ebd5925..eb9c2d8 100644 --- a/action/action.go +++ b/action/action.go @@ -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 -} diff --git a/action/group_member.go b/action/group_member.go index cd57913..6621323 100644 --- a/action/group_member.go +++ b/action/group_member.go @@ -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 +} diff --git a/constants/uri.go b/constants/uri.go index 735ca15..256d73d 100644 --- a/constants/uri.go +++ b/constants/uri.go @@ -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" ) diff --git a/handler/help/help.go b/handler/help/help.go index b32c69f..fe806ba 100644 --- a/handler/help/help.go +++ b/handler/help/help.go @@ -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}, diff --git a/model/group.go b/model/group.go index 585c25f..dcadd7d 100644 --- a/model/group.go +++ b/model/group.go @@ -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"` +}