Skip to content

Commit

Permalink
changed to use 3 different endpoints to accomodate for the removal of…
Browse files Browse the repository at this point in the history
… the endpoint.
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed Aug 14, 2024
1 parent 1aa2d50 commit 235bc43
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Binary file added bun.lockb
Binary file not shown.
52 changes: 49 additions & 3 deletions lib/util/getCurrentUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Includes
const http = require('./http.js').func
const { func:getPlayerThumbnail } = require("../thumbnails/getPlayerThumbnail.js")

// Args
exports.optional = ['option', 'jar']
Expand All @@ -17,8 +18,40 @@ exports.optional = ['option', 'jar']
**/

// Define
exports.func = async function (args) {
const jar = args.jar
exports.func = async function ({ jar, option }) {
try {
const { body:userInfo } = await constructRequest(`//users.roblox.com/v1/users/authenticated`, jar)
const userId = userInfo.id

const [ thumbnailReq, robuxReq, premiumReq ] = await Promise.allSettled([
getPlayerThumbnail({ userIds: [ userId ], cropType: "Body" }),
constructRequest("//economy.roblox.com/v1/user/currency", jar),
constructRequest(`//premiumfeatures.roblox.com/v1/users/${userId}/validate-membership`, jar)
])

const thumbnail = thumbnailReq.status == "fulfilled" && thumbnailReq.value?.[0].imageUrl
const robux = robuxReq.status == "fulfilled" && robuxReq.value.body?.robux
const premium = premiumReq.status == "fulfilled" && premiumReq.value.body

const json = {
UserID: userId,
UserName: userInfo.name,
RobuxBalance: robux,
ThumbnailUrl: thumbnail,
IsAnyBuildersClubMember: false,
IsPremium: premium
}

if (!option) return json

const searchKey = Object.keys(json).filter((key) => {
return option.toLowerCase() === key.toLowerCase()
})[0]
return json[searchKey]

} catch (e) { throw Error("Could not get current user!", e) }

/*const jar = args.jar
const option = args.option
const httpOpt = {
url: '//www.roblox.com/mobileapi/userinfo',
Expand All @@ -40,5 +73,18 @@ exports.func = async function (args) {
const searchKey = Object.keys(json).filter((key) => {
return option.toLowerCase() === key.toLowerCase()
})[0]
return json[searchKey]
return json[searchKey]*/
}


function constructRequest (url, jar) {
return http({
url: encodeURI(url),
options: {
resolveWithFullResponse: true,
followRedirect: false,
json: true,
jar
}
})
}

0 comments on commit 235bc43

Please sign in to comment.