Advertisement
Pvhak

Roblox item hunter

Oct 23rd, 2023 (edited)
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.26 KB | Gaming | 0 0
  1. let url = "https://catalog.roblox.com/v1/search/items?category=&CreatorName=ROBLOX&limit=120&maxPrice=0&minPrice=0&salesTypeFilter=1",
  2. purchaseUrl = "https://economy.roblox.com/v1/purchases/products/",
  3. detailsUrl = "https://catalog.roblox.com/v1/catalog/items/details",
  4. inventoryUrl = "https://inventory.roblox.com/v1/users/",
  5. csrfUrl = "https://economy.roblox.com/v1/purchases/products/666",
  6. userUrl = "https://users.roblox.com/v1/users/authenticated",
  7. welcomeMessageDisplayed = !1;
  8.  
  9. async function getAuthenticatedUserInfo() {
  10.   try {
  11.     const e = await fetch(userUrl, {
  12.       method: "GET",
  13.       credentials: "include"
  14.     });
  15.     return await e.json()
  16.   } catch (e) {
  17.     throw new Error("Failed to fetch authenticated user information")
  18.   }
  19. }
  20. async function getCSRFTokenFromUrl() {
  21.   return new Promise((async (e, t) => {
  22.     console.log("Generating CSRF Token...");
  23.     try {
  24.       const o = (await fetch(csrfUrl, {
  25.         method: "POST",
  26.         credentials: "include"
  27.       })).headers.get("X-Csrf-Token");
  28.       o ? e(o) : t(new Error("CSRF token not found in request response..."))
  29.     } catch (e) {
  30.       t(e)
  31.     }
  32.   }))
  33. }
  34.  
  35. function delay(e) {
  36.   return new Promise((t => setTimeout(t, e)))
  37. }
  38. async function fetchData(e) {
  39.   const t = await fetch(e, {
  40.       credentials: "include"
  41.     }),
  42.     o = await t.json(),
  43.     a = o.nextPageCursor,
  44.     s = o.data;
  45.   let n = await getCSRFTokenFromUrl(),
  46.     r = await getAuthenticatedUserInfo();
  47.   const l = r.id,
  48.     i = r.name,
  49.     c = r.displayName,
  50.     d = "";
  51.   welcomeMessageDisplayed || (i.toLowerCase() !== c.toLowerCase() ? console.log(`Welcome to ${d}, ${i} A.K.A. ${c}!`) : console.log(`Welcome to ${d}, ${i}!`), welcomeMessageDisplayed = !0);
  52.   const u = s.map((e => ({
  53.       id: e.id,
  54.       itemType: "Asset" === e.itemType ? 1 : 2
  55.     }))),
  56.     m = await fetch(detailsUrl, {
  57.       method: "POST",
  58.       body: JSON.stringify({
  59.         items: u
  60.       }),
  61.       headers: {
  62.         "Content-Type": "application/json",
  63.         "X-Csrf-Token": n
  64.       },
  65.       credentials: "include"
  66.     }),
  67.     h = (await m.json()).data;
  68.   for (let e = 0; e < h.length; e++) {
  69.     const t = h[e],
  70.       o = t.id.toString(),
  71.       a = t.name,
  72.       s = "Bundle" === t.itemType ? 3 : 0;
  73.     let r, i;
  74.     do {
  75.       if (r = await fetch(`${inventoryUrl}${l}/items/${s}/${o}`), i = await r.json(), 429 === r.status) {
  76.         const e = Math.floor(3e4 * Math.random()) + 3e4;
  77.         console.log(`Too many requests. Waiting for ${e/1e3} seconds...`), await delay(e)
  78.       }
  79.     } while (429 === r.status);
  80.     if (null === i.nextPageCursor && null === i.previousPageCursor && 0 === i.data.length) {
  81.       const s = JSON.stringify({
  82.         expectedCurrency: 1,
  83.         expectedPrice: 0,
  84.         expectedSellerId: 1
  85.       });
  86.       let r, l;
  87.       0 === e || await delay(Math.floor(0 * Math.random()) + 500), console.log(`Attempting to buy item "${a}" (#${e+1} out of ${h.length})`);
  88.       do {
  89.         if (r && 429 === r.status || l && l.errors && 27 === l.errors[0].code) {
  90.           const e = Math.floor(3e4 * Math.random()) + 3e4;
  91.           console.log(`Too many requests. Waiting for ${e/1e3} seconds...`), await delay(e)
  92.         }
  93.         r && "Token Validation Failed" == l.message && (console.log("Token validation failed. Generating a new CSRF Token..."), n = await getCSRFTokenFromUrl()), r = await fetch(purchaseUrl + t.productId, {
  94.           method: "POST",
  95.           body: s,
  96.           headers: {
  97.             "Content-Type": "application/json",
  98.             "X-Csrf-Token": n
  99.           },
  100.           credentials: "include"
  101.         }), l = await r.json()
  102.       } while (429 === r.status || 403 === r.status);
  103.       l.purchased ? (console.log(`Purchase successful for item "${a}" (ID: ${o})`), console.log(l)) : "AlreadyOwned" === l.reason ? console.log(`Item "${a}" (ID: ${o}) is already owned`) : (console.log(`Purchase failed for item "${a}" (ID: ${o})`), console.log(l))
  104.     } else console.log(`Skipping owned item "${a}" (ID: ${o}) (#${e+1} out of ${h.length})`)
  105.   }
  106.   if (null !== a) {
  107.     const t = e.replace(/&cursor=.*/, "") + `&cursor=${a}`;
  108.     await fetchData(t)
  109.   }
  110. }
  111. fetchData(url);
  112. console.log("\n < Completely Loaded. > \n < Free item hunter [Only roblox items version] > \n < V1.0 > \n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement