wolfyflutter

48. Roblox top playing now [kreasi] [info] [www.roblox.com] [official api]

Aug 8th, 2025 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 6.46 KB | Source Code | 0 0
  1. /*
  2.   base   : https://www.roblox.com/charts#/sortName/top-playing-now
  3.   note   : kamu perlu install library sharp (buat combine thumbnail)
  4.   url    : https://pastebin.com/HKZh7sc7 (save ajah link skrep nya, kalau skrep error biasanya aku update)
  5.   by     : wolep
  6.   update : 9 agustus 2025
  7. */
  8.  
  9. // pilih jalan ninjamu
  10. //import sharp from "sharp"
  11. //const sharp = require("sharp")
  12.  
  13. const r = {
  14.     _misc: {
  15.         async hit(hitDescription, url, options, returnType = "text") {
  16.             try {
  17.                 const response = await fetch(url, options)
  18.                 if (!response.ok) throw Error(`${response.status} ${response.statusText} ${(await response.text() || `(respond body kosong)`).substring(0, 100)}...`)
  19.                 try {
  20.  
  21.                     if (returnType === "text") {
  22.                         const data = await response.text()
  23.                         return { data, response }
  24.                     } else if (returnType === "json") {
  25.                         const data = await response.json()
  26.                         return { data, response }
  27.                     } else if (returnType == "buffer") {
  28.                         const ab = await response.arrayBuffer()
  29.                         const data = Buffer.from(ab)
  30.                         return { data, response }
  31.                     } else {
  32.                         throw Error(`invalid param retunt type. pilih text/json`)
  33.                     }
  34.                 } catch (error) {
  35.                     throw Error(`gagal mengubah response menjadi ${returnType}\n${error.message}`)
  36.                 }
  37.             } catch (error) {
  38.                 throw Error(`gagal hit. ${hitDescription}.\n${error.message}`)
  39.             }
  40.         },
  41.  
  42.  
  43.         log(logText) {
  44.             if (this.debug) console.log(logText)
  45.         },
  46.  
  47.         customMappingNumber (input) {
  48.             const char = ['𝟢', '𝟣', '𝟤', '𝟥', '𝟦', '𝟧', '𝟨', '𝟩', '𝟪', '𝟫']
  49.             return input.split("").map(v => isNaN(v) ? v : char[v]).join("")
  50.         }
  51.     },
  52.  
  53.     debug: false, // ganti false buat matikan log
  54.  
  55.     async getGameList(sortId = "top-playing-now") {
  56.         // parama validation
  57.         const validSortId = ["top-playing-now"]
  58.         if (!validSortId.includes(sortId)) throw Error(`invalid sortId. sortId tersedia: ${validSortId.join(", ")}. Atau km kalau tau sort id yang valid lainnya bisa tuh di add di filter`)
  59.  
  60.         // hit #1
  61.         const api1 = new URL(`https://apis.roblox.com`)
  62.         api1.pathname = `explore-api/v1/get-sort-content`
  63.         const usp = new URLSearchParams({
  64.             "sessionId": "17996246-1290-440d-b789-d49484115b9a",
  65.             "sortId": sortId,
  66.             "cpuCores": "8",
  67.             "maxResolution": "1920x1080",
  68.             "maxMemory": "8192",
  69.             "networkType": "4g"
  70.         })
  71.         api1.search = usp
  72.         const { data: json1 } = await this._misc.hit(`top playing now`, api1, { method: 'get' }, `json`)
  73.         const gameList = json1?.games?.slice(0, 10)
  74.         if (!gameList?.length) throw Error(`lah gamelist nya kosong`)
  75.         this._misc.log('hit api 1')
  76.  
  77.         // hit#2
  78.         const payload = gameList.map(v => {
  79.             const wolep = {
  80.                 "type": "GameIcon",
  81.                 "targetId": v.universeId,
  82.                 "format": "webp",
  83.                 "size": "256x256", // "256x256"
  84.             }
  85.             return wolep
  86.         })
  87.         const body = JSON.stringify(payload)
  88.         const api2 = 'https://thumbnails.roblox.com/v1/batch'
  89.         const { data: json2 } = await this._misc.hit(`batch download thumbnail`, api2, { body, 'method': 'post' }, `json`)
  90.         const thumbnaliList = json2.data
  91.         this._misc.log('hit api 2')
  92.  
  93.         // gabung value
  94.         const result = gameList.map((v, i) => {
  95.             const thumb = thumbnaliList[i]
  96.             const wolep = { ...v, ...thumb }
  97.             return wolep
  98.         })
  99.  
  100.         return result
  101.     },
  102.  
  103.     // bonus
  104.     async serialize(gameListObject) {
  105.         // download semua thumbnail sebagai buffer
  106.         const imageFetchs = gameListObject.map(v => {
  107.             const hit = this._misc.hit(`download gambar ${v.name}`, v.imageUrl, {}, 'buffer')
  108.             return hit
  109.         })
  110.         const imageResults = await Promise.all(imageFetchs)
  111.         const imageBuffers = imageResults.map(v => v.data)
  112.  
  113.         // gabungkan semua thumbnail menjadi 1 image besarrrrr
  114.         const imageBuffer = await sharp(
  115.             imageBuffers,
  116.             {
  117.                 join: {
  118.                     across: 5,        // kolom
  119.                     shim: 10,         // jarak antar gambar (padding internal)
  120.                     background: { r: 255, g: 255, b: 255, alpha: 1 } // warna padding
  121.                 }
  122.             })
  123.             .extend({ // padding global di luar grid
  124.                 top: 20,
  125.                 bottom: 20,
  126.                 left: 20,
  127.                 right: 20,
  128.                 background: { r: 255, g: 255, b: 255, alpha: 1 }
  129.             })
  130.             .png()
  131.             .toBuffer();
  132.  
  133.         // bikin caption
  134.         const hider = `top 10 playing now games on roblox\n\n`
  135.         const top10 = gameListObject.map((v, i) => {
  136.             const wolep = (i + 1) + " | " + v.name + "\n" +
  137.                 "👥 player count " + this._misc.customMappingNumber(v.playerCount.toLocaleString("id-ID")) + "\n" +
  138.                 "👍 likes " + this._misc.customMappingNumber((v.totalUpVotes / (v.totalUpVotes + v.totalDownVotes) * 100).toFixed()) + "%\n" +
  139.                 "🎮 play now https://www.roblox.com/games/" + v.rootPlaceId
  140.             return wolep
  141.         }).join("\n\n")
  142.  
  143.         const caption = hider + top10
  144.         const result = { imageBuffer, caption }
  145.         return result
  146.     },
  147.  
  148.     async cek() {
  149.         const gameListObject = await this.getGameList()
  150.         const result = await this.serialize(gameListObject)
  151.         return result
  152.     }
  153. }
  154.  
  155. // cara pakai
  156. r.cek()
  157.     .then(console.log)
  158.     .catch(console.log)
  159.  
  160. /* output
  161. {
  162.     imageBuffer: buffer isi thumbnail yang udh di gabung
  163.     caption: caption game yang udh di gabung
  164. }
  165.  
  166. kek gini
  167. 1 | [⏳] Grow a Garden 🌶️
  168. 👥 player count 𝟤.𝟣𝟥𝟢.𝟦𝟨𝟧
  169. 👍 likes 𝟫𝟥%
  170. 🎮 play now https://www.roblox.com/games/126884695634066
  171.  
  172. 2 | [🦉] 99 Nights in the Forest 🔦
  173. 👥 player count 𝟣.𝟧𝟣𝟪.𝟦𝟢𝟣
  174. 👍 likes 𝟫𝟣%
  175. 🎮 play now https://www.roblox.com/games/79546208627805
  176. */
Tags: Roblox info
Add Comment
Please, Sign In to add comment