Compare commits

...

9 Commits

Author SHA1 Message Date
09867b37ea Merge branch 'master' into disable-verification 2025-04-04 20:01:42 +00:00
eebddb88ff Merge pull request 'Update Noblox to 6.0.2' () from update-noblox into master
Reviewed-on: 
Reviewed-by: itzaname <itzaname@noreply@itzana.me>
2024-08-28 04:14:16 +00:00
37e691eebf Update Noblox to 6.0.2 2024-08-27 23:11:28 -05:00
af3d34f0c1 Merge pull request 'Use alternate API for current user and skip cookie validation' () from skip-cookie-validate into master
Reviewed-on: 
Reviewed-by: itzaname <itzaname@noreply@itzana.me>
2024-08-28 02:34:14 +00:00
d1066e2737 Use alternate API for current user and skip cookie validation 2024-08-27 21:28:33 -05:00
36c4a3d791 Merge pull request 'Improve error messages a bit for new API' () from improve-error-messages into master
Reviewed-on: 
Reviewed-by: itzaname <itzaname@noreply@itzana.me>
2024-08-28 02:02:47 +00:00
b3fdd8e2f1 Improve error messages a bit for new API 2024-08-26 21:38:17 -05:00
4e73ce1330 Merge pull request 'Use new product/asset API' () from update-product-api into master
Reviewed-on: 
Reviewed-by: itzaname <itzaname@noreply@itzana.me>
2024-08-22 04:00:15 +00:00
4f77012a9a Use new asset API 2024-08-21 22:48:30 -05:00
4 changed files with 87 additions and 72 deletions

@ -4,7 +4,7 @@ const fs = require('node:fs');
const noblox = require("noblox.js");
const axios = require("axios").default;
const { submissions, commands, cookies } = require("../config/config.js");
const { AssetType, getAssetInfo, SubmissionColumnsString, createSubmissionLine, getSubmissionLine, validateMapAsset, getValidationMessage } = require("../common.js");
const { getAssetInfo, SubmissionColumnsString, createSubmissionLine, getSubmissionLine, validateMapAsset, getValidationMessage } = require("../common.js");
async function robloxUserFromDiscord(id) {
if (isNaN(id)) return undefined;
@ -48,14 +48,13 @@ async function execute(interaction) {
}
const id = interaction.options.getInteger("asset_id", true);
await noblox.setCookie(cookies[game]);
noblox.setCookie(cookies[game], false);
try {
// Check that the bot owns this model
if (!(await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset"))) {
const msg = `🚫 The ${game} maptest bot's inventory does not contain this asset (id: ${id}). You must use the /take command first.`;
const robloxUser = await noblox.getAuthenticatedUser();
if (!(await noblox.getOwnership(robloxUser.id, id, "Asset"))) {
const msg = `🚫 The ${game} maptest bot's inventory does not contain this asset (id: \`${id}\`). You must use the /take command first.`;
await interaction.editReply(msg);
return;
}
@ -63,13 +62,13 @@ async function execute(interaction) {
if (error.message !== "400 The specified Asset does not exist!") {
throw error;
}
await interaction.editReply(`🚫 This asset does not exist (id: ${id}).`);
await interaction.editReply(`🚫 This asset does not exist (id: \`${id}\`).`);
return;
}
const assetInfo = await getAssetInfo(id);
if (assetInfo.typeId !== AssetType.Model) {
await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
if (!assetInfo.isModel) {
await interaction.editReply(`🚫 This asset (id: \`${id}\`) is not a model. Your map must be a model.`);
return;
}
@ -82,7 +81,6 @@ async function execute(interaction) {
await interaction.editReply(msg);
return;
}
const csvFile = fs.readFileSync(fname);
const lines = parse(csvFile, {delimiter: ',', fromLine: 2});
@ -90,7 +88,7 @@ async function execute(interaction) {
for (let lineStr of lines) {
const line = getSubmissionLine(lineStr);
if (id === line.modelId) {
await interaction.editReply(`🚫 This map (id: ${id}) was already submitted on <t:${line.timestamp}:d>.`);
await interaction.editReply(`🚫 This map (id: \`${id}\`) was already submitted on <t:${line.timestamp}:d>.`);
return;
}
}
@ -115,7 +113,7 @@ async function execute(interaction) {
csvString += createSubmissionLine(id, unixTimestamp, userId, await robloxUsernameFromId(userId), validation.displayName, validation.creator);
fs.writeFileSync(fname, csvString);
await interaction.followUp(`Map (id: ${id}) successfully submitted.`);
await interaction.followUp(`Map (id: \`${id}\`) successfully submitted.`);
}
module.exports = {

@ -1,7 +1,7 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const noblox = require("noblox.js");
const { cookies, commands, gamePlaces } = require("../config/config.js");
const { AssetType, getAssetInfo, validateMapAsset, getValidationMessage } = require("../common.js");
const { getAssetInfo, buyModel, validateMapAsset, getValidationMessage } = require("../common.js");
/**
* @param {import('discord.js').ChatInputCommandInteraction} interaction
@ -15,62 +15,48 @@ async function execute(interaction) {
}
const id = interaction.options.getInteger("asset_id", true);
await noblox.setCookie(cookie);
noblox.setCookie(cookie, false);
let alreadyOwned;
try {
// Check if the bot already owns this asset
alreadyOwned = await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset");
const robloxUser = await noblox.getAuthenticatedUser();
alreadyOwned = await noblox.getOwnership(robloxUser.id, id, "Asset");
} catch (error) {
if (error.message !== "400 The specified Asset does not exist!") {
throw error;
}
await interaction.editReply(`🚫 This asset does not exist (id: ${id}).`);
await interaction.editReply(`🚫 This asset does not exist (id: \`${id}\`).`);
return;
}
// Validate that this is a model
const assetInfo = await getAssetInfo(id);
if (assetInfo.status !== 403 && (assetInfo.status < 200 || assetInfo.status > 300)) {
await interaction.editReply(`🚫 This asset may not exist or is not a model (id: ${id}). Your map must be a model.`);
if (assetInfo.status === 404) {
await interaction.editReply(`🚫 This [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store). Alternatively, the provided ID may not actually be a model.`);
return;
}
// 403 (Forbidden) means the asset isn't distributed
if (assetInfo.status === 403 || !assetInfo.forSale) {
await interaction.editReply(`🚫 This model (id: ${id}) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store). It is also possible that this is not a valid model.`);
if (assetInfo.status < 200 || assetInfo.status >= 300) {
await interaction.editReply(`🚫 Something unexpected went wrong trying to retrive info about the model (id: \`${id}\`).`);
return;
}
if (assetInfo.typeId !== AssetType.Model) {
await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
if (assetInfo.forSale === false) {
await interaction.editReply(`🚫 This [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store).`);
return;
}
if (!assetInfo.isModel) {
await interaction.editReply(`🚫 This asset (id: \`${id}\`) is not a model. Your map must be a model.`);
return;
}
if (!assetInfo.isFree) {
await interaction.editReply(`🚫 This model (id: ${id}) is not free. Please change the price to be free.`);
await interaction.editReply(`🚫 This [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`) is not free. Please change the price to be free.`);
return;
}
// Kick off the buy request
let buyPromise;
if (!alreadyOwned) {
const jar = noblox.options.jar;
const xcsrf = await noblox.getGeneralToken(jar);
buyPromise = noblox.http("https://apis.roblox.com/marketplace-fiat-service/v1/product/purchase", {
method: "POST",
resolveWithFullResponse: true,
jar,
headers: {
"X-CSRF-TOKEN": xcsrf,
"Content-Type": "application/json"
},
body: JSON.stringify({
expectedPrice: {currencyCode: "USD", quantity: {significand: 0, exponent: 0}},
productKey: {
productNamespace: "PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET",
productTargetId: `${id}`,
productType: "PRODUCT_TYPE_MODEL"
}
})
});
buyPromise = buyModel(id);
}
// Validate and send the validation result
@ -85,8 +71,12 @@ async function execute(interaction) {
}
// Make sure the buy request is done
const res = await buyPromise;
console.log(JSON.parse(res.body));
const success = await buyPromise;
if (!success) {
await interaction.followUp(`🚫 Something went wrong when trying to buy the [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`).`);
return;
}
await interaction.followUp(
`
Now that your [map (id: ${id})](<https://create.roblox.com/store/asset/${id}/>) has been taken by the bot you can load it into the [${game} maptest place](<${gamePlaces[game]}>).

@ -1,5 +1,6 @@
const axios = require("axios").default;
const { RobloxFile } = require("rbxm-parser");
const noblox = require("noblox.js");
// https://create.roblox.com/docs/reference/engine/enums/AssetType
const AssetType = {
@ -25,44 +26,70 @@ const AssetType = {
};
async function getAssetInfo(assetId) {
const res = await axios.get("https://apis.roblox.com/toolbox-service/v1/items/details", {
params: {
assetIds: assetId
},
validateStatus: (_status) => true
const jar = noblox.options.jar;
const xcsrf = await noblox.getGeneralToken(jar);
const res = await noblox.http(`https://apis.roblox.com/user/cloud/v2/creator-store-products/PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET-PRODUCT_TYPE_MODEL-${assetId}`, {
method: "GET",
resolveWithFullResponse: true,
jar: jar,
headers: {
"X-CSRF-TOKEN": xcsrf,
"Content-Type": "application/json"
}
});
if (res.status < 200 || res.status > 300) {
if (res.statusCode < 200 || res.statusCode >= 300) {
return {
status: res.status
status: res.statusCode,
isModel: false
};
}
const data = res.data.data;
const assetInfo = data[0];
let isFree, forSale;
if (assetInfo.fiatProduct) {
const quantity = assetInfo.fiatProduct.purchasePrice.quantity;
isFree = quantity.significand === 0 && quantity.exponent === 0;
forSale = assetInfo.fiatProduct.published && assetInfo.fiatProduct.purchasable;
}
else {
isFree = assetInfo.product.price === 0;
forSale = assetInfo.product.isForSaleOrIsPublicDomain;
}
console.log(assetInfo);
const assetInfo = JSON.parse(res.body);
const quantity = assetInfo.purchasePrice.quantity;
const isFree = quantity.significand === 0 && quantity.exponent === 0;
const forSale = assetInfo.published && assetInfo.purchasable;
return {
status: res.status,
id: assetId,
name: assetInfo.asset.name,
typeId: assetInfo.asset.typeId,
creatorId: assetInfo.creator.id,
status: res.statusCode,
isModel: true,
id: assetInfo.modelAssetId,
creatorId: +assetInfo.userSeller,
isFree: isFree,
forSale: forSale
};
}
async function buyModel(modelId) {
const reqJson = {
expectedPrice: {currencyCode: "USD", quantity: {significand: 0, exponent: 0}},
productKey: {
productNamespace: "PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET",
productTargetId: `${modelId}`,
productType: "PRODUCT_TYPE_MODEL"
}
};
const jar = noblox.options.jar;
const xcsrf = await noblox.getGeneralToken(jar);
const res = await noblox.http("https://apis.roblox.com/marketplace-fiat-service/v1/product/purchase", {
method: "POST",
resolveWithFullResponse: true,
jar: jar,
headers: {
"X-CSRF-TOKEN": xcsrf,
"Content-Type": "application/json"
},
body: JSON.stringify(reqJson)
});
const resJson = JSON.parse(res.body);
// Return true if purchased, false otherwise
return res.statusCode >= 200 && res.statusCode < 300 && resJson.purchaseTransactionStatus === "PURCHASE_TRANSACTION_STATUS_SUCCESS";
}
const SubmissionColumnsString = "map_id,unix_timestamp,user_id,username,display_name,creator\n";
const SubmissionColumn = {
@ -332,4 +359,4 @@ function getValidationMessage(validation, game, errorOnFail) {
return msg;
}
module.exports = { AssetType, getAssetInfo, SubmissionColumn, SubmissionColumnsString, getSubmissionLine, createSubmissionLine, validateMapAsset, getValidationMessage, safeCsvFormat };
module.exports = { AssetType, getAssetInfo, buyModel, SubmissionColumn, SubmissionColumnsString, getSubmissionLine, createSubmissionLine, validateMapAsset, getValidationMessage, safeCsvFormat };

@ -6,7 +6,7 @@
"csv-parse": "^5.0.4",
"discord-api-types": "^0.37.81",
"discord.js": "^14.14.1",
"noblox.js": "^4.15.1",
"noblox.js": "^6.0.2",
"node-csv": "^0.1.2",
"rbxm-parser": "^1.1.0",
"sugar-date": "^2.0.6"