This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
374 lines (321 loc) · 12.9 KB
/
api.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
const R6API = require('r6api.js').default;
const resemble = require("resemblejs");
const valid_seasons = ['Solar Raid', 'Brutal Swarm', 'Vector Glare', 'Demon Veil', 'High Calibre', 'Crystal Guard', 'North Star', 'Crimson Heist', 'Neon Dawn', 'Shadow Legacy', 'Steel Wave', 'Void Edge', 'Shifting Tides', 'Ember Rise', 'Phantom Sight'].map(i => i.toLowerCase().replace(/\s/g, '-'));
function generateAPIHook(options) {
return new R6API({
email: options.email,
password: options.password
});
}
R6API.prototype.calculateRating = async function(profile) {
if (!profile) {
throw new Error("Please pass a valid player object. You can create one via .hookPlayer().");
}
if (profile.verified) {
return "This is a well known or verified player.";
}
if (profile.banned) {
return "This player has already been banned.";
}
if (profile.score > 150) {
return "Very likely a legitimate player.";
}
if (profile.score > 90) {
return "Possible cheater or new player/account.";
}
if (profile.score > 50) {
return "Definite cheater.";
}
if (profile.score <= 50) {
return "Rage cheater/Server Hitter.";
}
throw new Error('Invalid player data');
}
R6API.prototype.hookPlayerByID = async function(options) {
let invalid, value;
await this.findById('all', options.id, { isUserId: true }).then((result) => {
if (result.length == 0) {
invalid = true;
}
value = result[0];
});
if (invalid) {
throw new Error("Provide a valid username and/or platform.");
}
return value;
}
R6API.prototype.hookPlayerByName = async function(options) {
let invalid, value;
await this.findByUsername(options.platform, options.username).then((result) => {
if (result.length == 0) {
invalid = true;
}
value = result[0];
});
if (invalid) {
throw new Error("Provide a valid username and/or platform.");
}
return value;
}
R6API.prototype.findPlatforms = async function(player) {
if (!player || !player.userId) {
throw new Error("Please pass a valid hook object. You can create one via .hookPlayer().");
}
return await this.findById('all', player.userId, {
isUserId: true
});
}
R6API.prototype.getAllApplications = async function(player) {
if (!player || !player.userId) {
throw new Error("Please pass a valid hook object. You can create one via .hookPlayer().");
}
return (await this.getProfileApplications(player.userId, {
isUserId: true
}))[0];
}
R6API.prototype.getSmurfs = async function(player) {
if (!player || !player.userId) {
throw new Error("Please pass a valid hook object. You can create one via .hookPlayer().");
}
return await (await fetch('https://r6.apitab.net/website/profiles/' + player.userId + '/smurfs', {
"Content-Type": "application/json"
}).catch(console.err))
.json();
}
R6API.prototype.getStatistics = async function(player) {
if (!player || !player.userId) {
throw new Error("Please pass a valid hook object. You can create one via .hookPlayer().");
}
return (await fetch('https://r6.apitab.net/website/profiles/' + player.userId, {
"Content-Type": "application/json"
}).catch(console.err))
.json();
}
R6API.prototype.hasDefaultPFP = async function(player) {
if (!player || !player.avatar['256']) {
throw new Error("Please pass a valid hook object. You can create one via.hookPlayer().");
}
return (await new Promise((resolve) => {
resemble('src/comp.png')
.compareTo(player.avatar['256'])
.ignoreColors()
.onComplete(resolve)
})).rawMisMatchPercentage == 0;
}
//async function grabUbiProfile(generator,)
R6API.prototype.generateSimpleProfile = async function(hook, options) {
let profile = {};
/** Grab Ubisoft and Tabstats-provided data **/
if (options && options.debug) { console.log('(1/6) Verifying basic data...'); }
if (!hook) {
throw new Error("Please pass a valid hook object.")
}
profile = {
_ubi: hook,
username: hook.username,
pfp: null,
games: [],
linked: [],
score: 100,
};
if (options && options.debug) { console.log('(2/6) Analyzing avatar...'); }
profile._defaultPFP = await this.hasDefaultPFP(profile._ubi);
if (options && options.debug) { console.log('(3/6) Fetching linked platforms...'); }
profile.linked = await this.findPlatforms(profile._ubi);
if (options && options.debug) { console.log('(4/6) Fetching applications...'); }
profile._appdata = await this.getAllApplications(profile._ubi);
if (options && options.debug) { console.log('(5/6) Fetching statistics...'); }
profile._tabstats = await this.getStatistics(profile._ubi);
if (options && options.debug) { console.log('(6/6) Fetching linked accounts...'); }
profile._smurfs = await this.getSmurfs(profile._ubi);
/** Add PFP to return object **/
profile.pfp = profile._ubi.avatar['500'];
/** Calculate score non-standard pfp **/
profile.score += profile._defaultPFP ? -10 : 1;
/** Calculate based on additional linked platforms **/
profile.score += (profile.linked.length - 1) * 10;
/** Calculate based on name **/
profile.score += Math.max(4 - profile.username.length, -5);
/** Calculate based on owned titles **/
if (profile._appdata) {
profile.games = profile._appdata.applications;
profile.score += (profile.games.length - 2) * 10;
} else {
profile.autoclaimed = true;
profile.score -= 10;
}
/** Calculate based on first played **/
if (profile.games && profile.games.find(i => i.name == "Tom Clancy's Rainbow Six Siege")) {
profile._siege = profile.games.find(i => i.name == "Tom Clancy's Rainbow Six Siege");
profile.yearsplayed = (Date.now() - Date.parse(profile._siege.firstPlayedAt)) * 0.0000000000317098;
profile.score += (profile.yearsplayed - 1) * 7.5;
profile.yearsplayed = (profile.yearsplayed).toFixed(2);
}
/** Compute based on raw KD **/
profile.score += ((profile._tabstats.profile.kd - 0.9) ** 3) * -50;
/** Computer based on raw HS **/
// can't find this for some reason
/** Computer based on KD trendline **/
let flattened_seasons = profile._tabstats.ranked_records
.map(regions => regions[0])
.filter(season => valid_seasons.includes(season.season_slug));
profile.kd = {
avg: flattened_seasons.reduce((total, new_element) => total + new_element.kd, 0) / flattened_seasons.length,
}
if (flattened_seasons.length > 3 && flattened_seasons[0].kd > 1 && flattened_seasons[0].wins + flattened_seasons[0].losses > 20) {
// Calculate lifetime and recent slope lines for kd
profile.kd.recent_slope = (flattened_seasons[0].kd - flattened_seasons[1].kd) / 2;
profile.kd.lifetime_slope = (flattened_seasons[0].kd - flattened_seasons[flattened_seasons.length - 1].kd) / flattened_seasons.length;
// Calculate the difference between recent and lifetime KD slope
profile.kd.shift = profile.kd.lifetime_slope * 100 - profile.kd.recent_slope * 100;
// Exaggerate the difference between recent and lifetime slope and adjust score accordingly
profile.score += profile.kd.shift ** 3 / 50;
// Make KD more readable
profile.kd.avg = profile.kd.avg.toFixed(2);
profile.kd.recent_slope = profile.kd.recent_slope.toFixed(2);
profile.kd.lifetime_slope = profile.kd.lifetime_slope.toFixed(2);
profile.kd.shift = (profile.kd.shift > 0 ? '' : '+') + -profile.kd.shift.toFixed(2) + '%';
} else {
profile.newplayer = true;
profile.score -= 10;
}
/** Add smurfs to return object **/
if (profile._smurfs.length > 0) {
profile.accounts = profile._smurfs.map(smurf => smurf.profile.display_name);
}
/** Check for banned smurfs **/
if (profile._smurfs.filter(smurf => smurf.profile.is_cheater).length > 0) {
profile.bannedaccounts = profile._smurfs.filter(smurf => smurf.profile.is_cheater).map(smurf => smurf.profile.display_name);
profile.score -= (profile.bannedaccounts.length ** 2) * 20;
}
/** Adjust for each non-banned account **/
if (profile.accounts > 0 && profile._smurfs.filter(smurf => smurf.profile.is_cheater).length > 0) {
profile.score += (profile.accounts + 1) ** 3;
}
/** Check ff player has already been banned **/
if (profile._tabstats.profile.is_cheater) {
profile.score -= 200;
profile.banned = true;
}
/** Check if player has been verified **/
if (profile._tabstats.profile.is_verified) {
profile.score += 100;
profile.verified = true;
}
/** Clean up and present data **/
delete profile._ubi;
delete profile._siege;
delete profile._smurfs;
delete profile._appdata;
delete profile._tabstats;
delete profile._defaultPFP;
profile.score = (profile.score).toFixed(2);
profile.games = profile.games.map(i => i.name == null ? "Unknown Title" : i.name);
return profile;
};
R6API.prototype.generateDetailedProfile = async function(hook) {
let profile = {};
/** Grab Ubisoft and Tabstats-provided data **/
console.log('(1/6) Verifying basic data...');
if (!hook) {
throw new Error("Please pass a valid hook object.")
}
profile = {
_ubi: hook,
username: hook.username,
pfp: null,
games: [],
linked: [],
score: 100,
};
console.log('(2/6) Analyzing avatar...')
profile.defaultPFP = await this.hasDefaultPFP(profile._ubi);
console.log('(3/6) Fetching linked platforms...');
profile.linked = await this.findPlatforms(profile._ubi);
console.log('(4/6) Fetching applications...');
profile.appdata = await this.getAllApplications(profile._ubi);
console.log('(5/6) Fetching statistics...');
profile.tabstats = await this.getStatistics(profile._ubi);
console.log('(6/6) Fetching linked accounts...');
profile.smurfs = await this.getSmurfs(profile._ubi);
/** Add PFP to return object **/
profile.pfp = profile._ubi.avatar['500'];
/** Calculate score non-standard pfp **/
profile.score += profile._defaultPFP ? -10 : 1;
/** Calculate based on additional linked platforms **/
profile.score += (profile.linked.length - 1) * 10;
/** Calculate based on name **/
profile.score += Math.max(4 - profile.username.length, -5);
/** Calculate based on owned titles **/
if (profile._appdata) {
profile.games = profile._appdata.applications;
profile.score += (profile.games.length - 2) * 10;
} else {
profile.autoclaimed = true;
profile.score -= 10;
}
/** Calculate based on first played **/
if (profile.games && profile.games.find(i => i.name == "Tom Clancy's Rainbow Six Siege")) {
profile.siege = profile.games.find(i => i.name == "Tom Clancy's Rainbow Six Siege");
profile.yearsplayed = (Date.now() - Date.parse(profile._siege.firstPlayedAt)) * 0.0000000000317098;
profile.score += (profile.yearsplayed - 1) * 7.5;
profile.yearsplayed = (profile.yearsplayed).toFixed(2);
}
/** Compute based on raw KD **/
profile.score += ((profile.tabstats.profile.kd - 0.9) ** 3) * -50;
/** Computer based on raw HS **/
// can't find this for some reason
/** Computer based on KD trendline **/
let flattened_seasons = profile.tabstats.ranked_records
.map(regions => regions[0])
.filter(season => valid_seasons.includes(season.season_slug));
profile.kd = {
avg: flattened_seasons.reduce((total, new_element) => total + new_element.kd, 0) / flattened_seasons.length,
}
if (flattened_seasons.length > 3 && flattened_seasons[0].kd > 1 && flattened_seasons[0].wins + flattened_seasons[0].losses > 20) {
// Calculate lifetime and recent slope lines for kd
profile.kd.recent_slope = (flattened_seasons[0].kd - flattened_seasons[1].kd) / 2;
profile.kd.lifetime_slope = (flattened_seasons[0].kd - flattened_seasons[flattened_seasons.length - 1].kd) / flattened_seasons.length;
// Calculate the difference between recent and lifetime KD slope
profile.kd.shift = profile.kd.lifetime_slope * 100 - profile.kd.recent_slope * 100;
// Exaggerate the difference between recent and lifetime slope and adjust score accordingly
profile.score += profile.kd.shift ** 3 / 50;
// Make KD more readable
profile.kd.avg = profile.kd.avg.toFixed(2);
profile.kd.recent_slope = profile.kd.recent_slope.toFixed(2);
profile.kd.lifetime_slope = profile.kd.lifetime_slope.toFixed(2);
profile.kd.shift = (profile.kd.shift > 0 ? '' : '+') + -profile.kd.shift.toFixed(2) + '%';
} else {
profile.newplayer = true;
profile.score -= 10;
}
/** Add smurfs to return object **/
if (profile.smurfs.length > 0) {
profile.accounts = profile._smurfs.map(smurf => smurf.profile.display_name);
}
/** Check for banned smurfs **/
if (profile.smurfs.filter(smurf => smurf.profile.is_cheater).length > 0) {
profile.bannedaccounts = profile._smurfs.filter(smurf => smurf.profile.is_cheater).map(smurf => smurf.profile.display_name);
profile.score -= (profile.bannedaccounts.length ** 2) * 20;
}
/** Adjust for each non-banned account **/
if (profile.accounts > 0 && profile.smurfs.filter(smurf => smurf.profile.is_cheater).length > 0) {
profile.score += (profile.accounts + 1) ** 3;
}
/** Check ff player has already been banned **/
if (profile.tabstats.profile.is_cheater) {
profile.score -= 200;
profile.banned = true;
}
/** Check if player has been verified **/
if (profile.tabstats.profile.is_verified) {
profile.score += 100;
profile.verified = true;
}
/** Present data **/
return profile;
};
module.exports = {
R6API, generateAPIHook
};