// GetLatestModel returns the asset id of the latest model for a given user. // While this is useful for retrieving the asset id of a newly created model // that was just uploaded, it is not necessarily reliable for this purpose. func GetLatestModel(client *rbxweb.Client, userId int32) (assetId int64, err error) { if userId == 0 { return 0, errors.New("invalid user id") } query := url.Values{ "Category": {"Models"}, "SortType": {"RecentlyUpdated"}, "IncludeNotForSale": {"true"}, "ResultsPerPage": {"1"}, "CreatorID": {client.I32toa(userId)}, } resp, err := client.Get(client.GetURL(`api`, `/catalog/json`, query)) if err = client.AssertResp(resp, err); err != nil { return 0, err } defer resp.Body.Close() dec := json.NewDecoder(resp.Body) var asset []struct { AssetId int64 } if err = dec.Decode(&asset); err != nil { return 0, errors.New("JSON decode failed: " + err.Error()) } return asset[0].AssetId, nil }
// Wall posts a message to a group wall. The account the client is logged into // must have a group role that has permission to post to the group's wall. // // This function requires the client to be logged in. func Wall(client *rbxweb.Client, groupID int32, message string) (success bool) { page := client.GetURL(`www`, `/My/Groups.aspx`, url.Values{"gid": {client.I32toa(groupID)}}) err := client.DoRawPost(page, url.Values{ "ctl00$ctl00$cphRoblox$cphMyRobloxContent$GroupWallPane$NewPost": {message}, "ctl00$ctl00$cphRoblox$cphMyRobloxContent$GroupWallPane$NewPostButton": {}, "ctl00$ctl00$cphRoblox$cphMyRobloxContent$rbxGroupRoleSetMembersPane$currentRoleSetID": {}, }) if err != nil { return false } return true }
// Add adds an asset to a set. The set must belong to the current user, and // the asset must be addable to sets. // // This function requires the client to be logged in. func Add(client *rbxweb.Client, assetId int64, setId int32) (err error) { query := url.Values{ "rqtype": {"addtoset"}, "assetId": {client.I64toa(assetId)}, "setId": {client.I32toa(setId)}, } resp, err := client.Post(client.GetURL(`www`, `/Sets/SetHandler.ashx`, query), "", nil) if err = client.AssertResp(resp, err); err != nil { return err } resp.Body.Close() return nil }