Bump go-roblox
This commit is contained in:
parent
59f81fa7c6
commit
b60a4e0a37
2
vendor/git.itzana.me/itzaname/go-roblox/.gitignore
generated
vendored
2
vendor/git.itzana.me/itzaname/go-roblox/.gitignore
generated
vendored
@ -1,2 +0,0 @@
|
||||
.vscode/launch.json
|
||||
debug
|
1
vendor/git.itzana.me/itzaname/go-roblox/README.md
generated
vendored
1
vendor/git.itzana.me/itzaname/go-roblox/README.md
generated
vendored
@ -1 +0,0 @@
|
||||
Copyright © Stuart Livingston
|
110
vendor/git.itzana.me/itzaname/go-roblox/asset.go
generated
vendored
110
vendor/git.itzana.me/itzaname/go-roblox/asset.go
generated
vendored
@ -1,110 +0,0 @@
|
||||
package roblox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type AssetUploadOptions struct {
|
||||
Name string
|
||||
AssetID int
|
||||
Description string
|
||||
Public bool
|
||||
Comments bool
|
||||
Group int
|
||||
}
|
||||
|
||||
type AssetUploadResponse struct {
|
||||
AssetID int64 `json:"AssetId"`
|
||||
AssetVersionID int64 `json:"AssetVersionId"`
|
||||
}
|
||||
|
||||
func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUploadResponse, error) {
|
||||
var assetInfo AssetUploadResponse
|
||||
endpoint, err := url.Parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1")
|
||||
if err != nil {
|
||||
return assetInfo, err
|
||||
}
|
||||
|
||||
query := endpoint.Query()
|
||||
query.Set("name", options.Name)
|
||||
query.Set("description", options.Description)
|
||||
query.Set("assetid", strconv.Itoa(options.AssetID))
|
||||
|
||||
// Comments
|
||||
if options.Comments {
|
||||
query.Set("allowComments", "true")
|
||||
} else {
|
||||
query.Set("allowComments", "false")
|
||||
}
|
||||
|
||||
// Public
|
||||
if options.Public {
|
||||
query.Set("ispublic", "true")
|
||||
} else {
|
||||
query.Set("ispublic", "false")
|
||||
}
|
||||
|
||||
// Group
|
||||
if options.Group > 0 {
|
||||
query.Set("groupId", strconv.Itoa(options.Group))
|
||||
}
|
||||
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := http.NewRequest("POST", endpoint.String(), nil)
|
||||
req.Header.Set("user-agent", "Roblox")
|
||||
|
||||
// Perform request
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return assetInfo, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 403 && resp.Header.Get("X-Csrf-Token") != "" {
|
||||
req, err := http.NewRequest("POST", endpoint.String(), f)
|
||||
req.Header.Set("user-agent", "Roblox")
|
||||
req.Header.Set("x-csrf-token", strings.Trim(resp.Header["X-Csrf-Token"][0], " "))
|
||||
// Perform request
|
||||
resp, err = s.client.Do(req)
|
||||
if err != nil {
|
||||
return assetInfo, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return assetInfo, fmt.Errorf(resp.Status)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return assetInfo, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &assetInfo); err != nil {
|
||||
return assetInfo, err
|
||||
}
|
||||
|
||||
return assetInfo, nil
|
||||
}
|
||||
|
||||
func (s *Session) Download(id int) (io.Reader, error) {
|
||||
resp, err := s.client.Get("https://assetgame.roblox.com/Asset/?id=" + strconv.Itoa(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf(resp.Status)
|
||||
}
|
||||
|
||||
return resp.Body, nil
|
||||
}
|
3
vendor/git.itzana.me/itzaname/go-roblox/go.mod
generated
vendored
3
vendor/git.itzana.me/itzaname/go-roblox/go.mod
generated
vendored
@ -1,3 +0,0 @@
|
||||
module git.itzana.me/itzaname/go-roblox
|
||||
|
||||
go 1.15
|
156
vendor/git.itzana.me/itzaname/go-roblox/item.go
generated
vendored
156
vendor/git.itzana.me/itzaname/go-roblox/item.go
generated
vendored
@ -1,156 +0,0 @@
|
||||
package roblox
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Item struct containing data on retrieved items
|
||||
type Item struct {
|
||||
ProductID int
|
||||
ItemID int
|
||||
AssetID int
|
||||
UserID int
|
||||
UserName string
|
||||
Type string
|
||||
Name string
|
||||
CopyLocked bool
|
||||
Owned bool
|
||||
}
|
||||
|
||||
// HasItem will return if you own the item
|
||||
func (s *Session) HasItem(id int) (bool, error) {
|
||||
resp, err := s.client.Get(fmt.Sprintf("http://api.roblox.com/Ownership/HasAsset?userId=%d&assetId=%d", s.ID, id))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return string(data) == "true", nil
|
||||
}
|
||||
|
||||
// AddItem add item by id to inventory
|
||||
func (s *Session) AddItem(id int) error {
|
||||
product, err := s.GetProduct(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
payload := struct {
|
||||
ExpectedCurrency int `json:"expectedCurrency"`
|
||||
ExpectedPrice int `json:"expectedPrice"`
|
||||
ExpectedSellerID int `json:"expectedSellerId"`
|
||||
}{
|
||||
ExpectedCurrency: 1,
|
||||
ExpectedPrice: 0,
|
||||
ExpectedSellerID: product.Creator.ID,
|
||||
}
|
||||
// Gen json body
|
||||
data, err := json.Marshal(&payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("https://economy.roblox.com/v1/purchases/products/%d", product.ProductID), bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 403 {
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("https://economy.roblox.com/v1/purchases/products/%d", product.ProductID), bytes.NewBuffer(data))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
|
||||
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("Failed to add item. Status %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveItem will remove item from inventory
|
||||
func (s *Session) RemoveItem(id int) error {
|
||||
v := url.Values{}
|
||||
v.Set("assetId", strconv.Itoa(id))
|
||||
resp, err := s.client.Post("https://www.roblox.com/asset/delete-from-inventory", "application/x-www-form-urlencoded", bytes.NewBufferString(v.Encode()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 403 {
|
||||
req, err := http.NewRequest("POST", "https://www.roblox.com/asset/delete-from-inventory", bytes.NewBufferString(v.Encode()))
|
||||
req.Header.Set("x-csrf-token", strings.Trim(resp.Header["X-Csrf-Token"][0], " "))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("Failed to remove item. Status %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetModels will list models in inventory
|
||||
func (s *Session) GetModels(user int) ([]Item, error) {
|
||||
var Data []Item
|
||||
|
||||
resp, err := s.client.Get("https://www.roblox.com/users/inventory/list-json?assetTypeId=10&userId=" + strconv.Itoa(user))
|
||||
if err != nil {
|
||||
return Data, fmt.Errorf("Could not get list: %s", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode == 200 {
|
||||
var dat map[string]interface{}
|
||||
defer resp.Body.Close()
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err := json.Unmarshal(body, &dat); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
set := dat["Data"].(map[string]interface{})
|
||||
ilist := set["Items"].([]interface{})
|
||||
for _, obj := range ilist {
|
||||
itm := obj.(map[string]interface{})
|
||||
iInfo := itm["Item"].(map[string]interface{})
|
||||
iCreator := itm["Creator"].(map[string]interface{})
|
||||
Data = append(Data, Item{0, int(iInfo["AssetId"].(float64)), 0, int(iCreator["Id"].(float64)), iCreator["Name"].(string), "Model", iInfo["Name"].(string), false, true})
|
||||
}
|
||||
|
||||
return Data, nil
|
||||
}
|
||||
return Data, fmt.Errorf("Could not get models. Status: %d", resp.StatusCode)
|
||||
}
|
61
vendor/git.itzana.me/itzaname/go-roblox/product.go
generated
vendored
61
vendor/git.itzana.me/itzaname/go-roblox/product.go
generated
vendored
@ -1,61 +0,0 @@
|
||||
package roblox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Product contains info about a product
|
||||
type Product struct {
|
||||
TargetID int `json:"TargetId"`
|
||||
ProductType string `json:"ProductType"`
|
||||
AssetID int `json:"AssetId"`
|
||||
ProductID int `json:"ProductId"`
|
||||
Name string `json:"Name"`
|
||||
Description string `json:"Description"`
|
||||
AssetTypeID int `json:"AssetTypeId"`
|
||||
Creator struct {
|
||||
ID int `json:"Id"`
|
||||
Name string `json:"Name"`
|
||||
CreatorType string `json:"CreatorType"`
|
||||
CreatorTargetID int `json:"CreatorTargetId"`
|
||||
} `json:"Creator"`
|
||||
IconImageAssetID int `json:"IconImageAssetId"`
|
||||
Created time.Time `json:"Created"`
|
||||
Updated time.Time `json:"Updated"`
|
||||
PriceInRobux int `json:"PriceInRobux"`
|
||||
PriceInTickets int `json:"PriceInTickets"`
|
||||
Sales int `json:"Sales"`
|
||||
IsNew bool `json:"IsNew"`
|
||||
IsForSale bool `json:"IsForSale"`
|
||||
IsPublicDomain bool `json:"IsPublicDomain"`
|
||||
IsLimited bool `json:"IsLimited"`
|
||||
IsLimitedUnique bool `json:"IsLimitedUnique"`
|
||||
Remaining int `json:"Remaining"`
|
||||
MinimumMembershipLevel int `json:"MinimumMembershipLevel"`
|
||||
ContentRatingTypeID int `json:"ContentRatingTypeId"`
|
||||
}
|
||||
|
||||
// GetProduct will retrieve store information on a product
|
||||
func (s *Session) GetProduct(id int) (*Product, error) {
|
||||
resp, err := s.client.Get(fmt.Sprintf("http://api.roblox.com/marketplace/productinfo?assetId=%d", id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info Product
|
||||
err = json.Unmarshal(data, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
89
vendor/git.itzana.me/itzaname/go-roblox/session.go
generated
vendored
89
vendor/git.itzana.me/itzaname/go-roblox/session.go
generated
vendored
@ -1,89 +0,0 @@
|
||||
package roblox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Session struct for roblox login session data and members
|
||||
type Session struct {
|
||||
ID int
|
||||
Username string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// New create a new session and logs in with provided data
|
||||
func New(cookie string) (*Session, error) {
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
rbxCookie := []*http.Cookie{&http.Cookie{
|
||||
Name: ".ROBLOSECURITY",
|
||||
Value: cookie,
|
||||
}}
|
||||
// url.Parse("http://www.roblox.com") // http://api.roblox.com
|
||||
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "www.roblox.com"}, rbxCookie)
|
||||
cookieJar.SetCookies(&url.URL{Scheme: "http", Host: "api.roblox.com"}, rbxCookie)
|
||||
cookieJar.SetCookies(&url.URL{Scheme: "https", Host: "economy.roblox.com"}, rbxCookie)
|
||||
cookieJar.SetCookies(&url.URL{Scheme: "https", Host: "data.roblox.com"}, rbxCookie)
|
||||
client := &http.Client{
|
||||
Jar: cookieJar,
|
||||
}
|
||||
|
||||
session := Session{0, "", client}
|
||||
|
||||
/*err := session.Login(username, password)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to login: %s", err)
|
||||
}*/
|
||||
|
||||
info, err := session.GetUserInfo()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to retrieve user information: %s", err)
|
||||
}
|
||||
|
||||
session.ID = info.UserID
|
||||
session.Username = info.UserName
|
||||
|
||||
return &session, err
|
||||
}
|
||||
|
||||
/*func (s *Session) Login(username, password string) error {
|
||||
details := struct {
|
||||
Ctype string `json:"ctype"`
|
||||
Cvalue string `json:"cvalue"`
|
||||
Password string `json:"password"`
|
||||
}{
|
||||
"Username",
|
||||
username,
|
||||
password,
|
||||
}
|
||||
payload, err := json.Marshal(&details)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := s.client.Post("https://auth.roblox.com/v2/login", "application/json", bytes.NewBuffer(payload))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 403 {
|
||||
req, err := http.NewRequest("POST", "https://auth.roblox.com/v2/login", bytes.NewBuffer(payload))
|
||||
req.Header.Set("X-Csrf-Token", resp.Header["X-Csrf-Token"][0])
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("Status %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}*/
|
37
vendor/git.itzana.me/itzaname/go-roblox/user.go
generated
vendored
37
vendor/git.itzana.me/itzaname/go-roblox/user.go
generated
vendored
@ -1,37 +0,0 @@
|
||||
package roblox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
UserID int `json:"UserID"`
|
||||
UserName string `json:"UserName"`
|
||||
RobuxBalance int `json:"RobuxBalance"`
|
||||
TicketsBalance int `json:"TicketsBalance"`
|
||||
ThumbnailURL string `json:"ThumbnailUrl"`
|
||||
IsAnyBuildersClubMember bool `json:"IsAnyBuildersClubMember"`
|
||||
}
|
||||
|
||||
// GetUserInfo will retrieve local user information
|
||||
func (s *Session) GetUserInfo() (*UserInfo, error) {
|
||||
resp, err := s.client.Get("http://www.roblox.com/mobileapi/userinfo")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info UserInfo
|
||||
err = json.Unmarshal(data, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user