-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetuserinfo.js
141 lines (121 loc) · 4.54 KB
/
getuserinfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const axios = require("axios");
class RobloxUser {
constructor(roblosecurityCookie, userId, username, displayName) {
this.roblosecurityCookie = roblosecurityCookie;
this.userId = userId;
this.username = username;
this.displayName = displayName;
}
async doAuthorizedRequest(url) {
return (await axios.get(url, {
headers: {
Cookie: `.ROBLOSECURITY=${this.roblosecurityCookie}`,
},
})).data;
}
static async register(roblosecurityCookie) {
const { data } = await axios.get("https://users.roblox.com/v1/users/authenticated", {
headers: {
Cookie: `.ROBLOSECURITY=${roblosecurityCookie}`,
},
});
return new RobloxUser(roblosecurityCookie, data.id, data.name, data.displayName);
}
async getAccountCreationDate() {
const { created } = await this.doAuthorizedRequest(`https://users.roblox.com/v1/users/${this.userId}`);
return new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeStyle: "long" }).format(
new Date(created),
);
}
async getAccountPremiumStatus() {
try {
await this.doAuthorizedRequest(
`https://premiumfeatures.roblox.com/v1/users/${this.userId}/subscriptions`
);
return true;
} catch (error) {
return false;
}
}
async getAccount2FAStatus() {
const { twoStepVerificationEnabled } = await this.doAuthorizedRequest(
`https://twostepverification.roblox.com/v1/metadata`
);
return twoStepVerificationEnabled;
}
async getAccountPinStatus() {
const { isEnabled } = await this.doAuthorizedRequest(
`https://auth.roblox.com/v1/account/pin`
);
return isEnabled;
}
async getAccountBalance() {
const { robux } = await this.doAuthorizedRequest(
`https://economy.roblox.com/v1/users/${this.userId}/currency`
);
return robux;
}
async getUserData() {
const creationDate = await this.getAccountCreationDate();
const premiumStatus = await this.getAccountPremiumStatus();
const twoFAStatus = await this.getAccount2FAStatus();
const pinStatus = await this.getAccountPinStatus();
const accountBalance = await this.getAccountBalance();
return {
username: this.username,
uid: this.userId,
displayName: this.displayName,
avatarUrl: await this.getAccountBodyShot(),
createdAt: creationDate,
country: await this.getAccountCountry(),
balance: accountBalance,
isTwoStepVerificationEnabled: twoFAStatus,
isPinEnabled: pinStatus,
isPremium: premiumStatus,
creditbalance: await this.getAccountCreditBalance(),
rap: await this.getAccountRAP(this.userId),
};
}
async getAccountBodyShot() {
const { data } = await this.doAuthorizedRequest(
`https://thumbnails.roblox.com/v1/users/avatar?userIds=${
this.userId
}&size=720x720&format=Png&isCircular=false`
);
return data[0].imageUrl;
}
async getAccountCountry() {
const { countryName } = await this.doAuthorizedRequest(
"https://www.roblox.com/account/settings/account-country"
);
return countryName;
}
async getAccountCreditBalance() {
const { balance } = await this.doAuthorizedRequest(
"https://billing.roblox.com/v1/credit"
);
const formatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
});
return formatter.format(balance);
}
async getAccountRAP(userId) {
let calculatedRap = 0;
let nextPageCursor = "";
while (nextPageCursor !== null) {
const inventoryPage = await this.doAuthorizedRequest(
`https://inventory.roblox.com/v1/users/${userId}/assets/collectibles?sortOrder=Asc&limit=100&cursor=${nextPageCursor}`
);
calculatedRap += inventoryPage.data.reduce(
(rap, item) => rap + item.recentAveragePrice,
0
);
nextPageCursor = inventoryPage.nextPageCursor;
}
return calculatedRap;
}
}
module.exports = {
RobloxUser,
};