-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix addDeveloperProduct & checkDeveloperProductName. addGamepass feature #785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const http = require('../util/http.js').func | ||
const getGeneralToken = require('../util/getGeneralToken.js').func | ||
|
||
exports.required = ['universeId', 'name', 'priceInRobux'] | ||
exports.optional = ['description', 'jar'] | ||
|
||
// Docs | ||
/** | ||
* 🔐 Create a gamepass. | ||
* @category Game | ||
* @alias addGamepass | ||
* @param {number} universeId - The id of the universe. | ||
* @param {string} name - The name of the gamepass. | ||
* @param {number} priceInRobux - The price of the product. | ||
* @param {string=} description - The description of the gamepass. | ||
* @returns {Promise<GamepassAddResult>} | ||
* @example const noblox = require("noblox.js") | ||
* // Login using your cookie | ||
* noblox.addGamepass(1, "A Gamepass", 100, "A cool item.") | ||
**/ | ||
|
||
const nextFunction = (jar, token, universeId, name, priceInRobux, description) => { | ||
const FormData = require('form-data'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't require modules in functions like this. |
||
const goofy = new FormData() | ||
goofy.append("Name", name) | ||
goofy.append("Description", description) | ||
goofy.append("UniverseId", universeId) | ||
goofy.append("IsForSale", 'true') | ||
goofy.append("Price", priceInRobux) | ||
return http({ | ||
url: `//apis.roblox.com/game-passes/v1/game-passes`, | ||
options: { | ||
method: 'POST', | ||
jar: jar, | ||
body: goofy, | ||
headers: { | ||
...goofy.getHeaders(), | ||
'X-CSRF-TOKEN': token | ||
}, | ||
resolveWithFullResponse: true | ||
} | ||
}).then((res) => { | ||
console.log(res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. console.log shouldn't be there |
||
if (res.statusCode === 200) { | ||
return { | ||
universeId, | ||
name, | ||
priceInRobux, | ||
description, | ||
gamepassId: typeof res.body === 'object' ? res.body.id : JSON.parse(res.body).id | ||
} | ||
} else { | ||
throw new Error(`Create gamepass failed, ${res.statusCode} ${res.statusMessage}`) | ||
} | ||
}).catch(e => {}) | ||
} | ||
|
||
exports.func = (args) => { | ||
const jar = args.jar | ||
|
||
return getGeneralToken({ jar: jar }).then((xcsrf) => { | ||
return nextFunction(jar, xcsrf, args.universeId, args.name, args.priceInRobux, args.description) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,10 @@ exports.optional = ['jar', 'productId'] | |
* @param {number} universeId - The id of the universe. | ||
* @param {string} productName - The name of the developer product. | ||
* @param {number=} productId - The id of the developer product. | ||
* @returns {Promise<CheckDeveloperProductNameResult>} | ||
* @returns {Promise<Boolean>} | ||
* @example const noblox = require("noblox.js") | ||
* // Login using your cookie | ||
* const productInfo = await noblox.checkDeveloperProductName(1, "A Developer Product") | ||
* const exists = await noblox.checkDeveloperProductName(1, "A Developer Product") | ||
**/ | ||
|
||
exports.func = (args) => { | ||
|
@@ -23,17 +23,25 @@ exports.func = (args) => { | |
const productId = parseInt(args.productId) ? parseInt(args.productId) : 0 | ||
|
||
return http({ | ||
url: '//www.roblox.com/places/check-developerproduct-name?universeId=' + universeId + '&developerProductId=' + productId + '&developerProductName=' + args.productName + '&_=1515792139751', | ||
url: `//apis.roblox.com/developer-products/v1/universes/${universeId}/developerproducts?pageNumber=1&pageSize=2147483647`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the meaning of the page size here? Why is it a large arbitrary number? how does this work when the number of pages is greater than 1? Could this use a pagination wrapper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my testing, Roblox does not use cursors for this endpoint. The number specified for the page size is (2^31)-1 (the largest possible signed 32bit int), which happens to be the largest page size Roblox supports. Now, whether the api will actually return that many results, I don't know. I agree that a pagination wrapper would be preferable to this though, given this is already undocumented to start with and I don't really expect this to work in practice (but maybe somehow it does). |
||
options: { | ||
method: 'GET', | ||
jar, | ||
jar: jar, | ||
resolveWithFullResponse: true | ||
} | ||
}).then((res) => { | ||
if (res.statusCode !== 200) { | ||
throw new Error('You are not logged in') | ||
} else { | ||
return JSON.parse(res.body) | ||
const data = JSON.parse(res.body) | ||
let exists = false | ||
data.forEach(product => { | ||
if(product.name == args.productName || product.id == productId){ | ||
exists = true | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns undefined and the typing says it returns a boolean. for (const product of data) {
if (...) {
return true
}
}
return false
```? |
||
} | ||
}) | ||
return exists | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the point of this change is