Skip to content
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

Updated getCurrentUser to use 4 different endpoints. #823

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bun.lockb
Binary file not shown.
60 changes: 40 additions & 20 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,28 +18,47 @@ exports.optional = ['option', 'jar']
**/

// Define
exports.func = async function (args) {
const jar = args.jar
const option = args.option
const httpOpt = {
url: '//www.roblox.com/mobileapi/userinfo',
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) }
}

function constructRequest (url, jar) {
return http({
url: encodeURI(url),
options: {
resolveWithFullResponse: true,
method: 'GET',
followRedirect: true,
followRedirect: false,
json: true,
jar
}
}
const res = await http(httpOpt)
if (res.statusCode !== 200) {
throw new Error('You are not logged in.')
}
const json = JSON.parse(res.body)
if (!option) {
return json
}
const searchKey = Object.keys(json).filter((key) => {
return option.toLowerCase() === key.toLowerCase()
})[0]
return json[searchKey]
})
}
Loading