UNPKG

goblox.js

Version:

Unoffical ROBLOX API wrapper made by Fastering18.

56 lines (52 loc) 2.1 kB
const requests = require("../util/baseRequest") const endpoints = require("../util/endpoints") function getInfo(id, options) { return new Promise((resolve, reject) => { new requests(`${endpoints.userinfo}/${id}`, options || {}).json().get() .then((result) => { result = JSON.parse(result) new requests(`${endpoints.userinfo}/${id}/status`, options).json().get() .then(res => { res = JSON.parse(res) return resolve({ UserId: result.id, Username: result.name, Description: result.description, Status: res.status, JoinDate: new Date(result.created).getTime(), displayName: result.displayName }) }) .catch(reject) }).catch(err => { const body = { "usernames": [ id ], "excludeBannedUsers": true } const option = { body: JSON.stringify(body), } new requests(endpoints.accountinfo, option).json().post() .then(async (resultName) => { resultName = JSON.parse(resultName) if (!resultName || !resultName.data || resultName.data.length <= 0) return reject(`User not found`); const id = resultName.data[0].id return resolve(await getInfo(id)) }).catch(errr => { reject("User not found."); }) }) }) } function getAccountInfo(UsernameOrUserId) { return new Promise((resolve, reject) => { if (!UsernameOrUserId) reject(`Cannot get your user data, please provide name or user id.`); getInfo(UsernameOrUserId).then(resolve).catch(reject); }) } module.exports = { getAccountInfo: getAccountInfo, getInfo: getInfo }