This repository was archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
84 lines (69 loc) · 1.81 KB
/
util.js
File metadata and controls
84 lines (69 loc) · 1.81 KB
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
const fetch = require('node-fetch');
/***
* @param {int} id The Players ID
*/
async function getPlayerNameFromID(id) {
try{
const response = await fetch(`https://apim.rec.net/accounts/account/${id}`);
const json = await response.json();
if (json.errors) throw json.errors;
return json.username;
} catch(e) {
console.error(e)
return "*(unknown)*";
}
}
/***
* @param {string} name The Players name
*/
async function getPlayerIDFromName(name) {
try{
const response = await fetch(`https://apim.rec.net/accounts/account?username=${name}`);
const json = await response.json();
if (json.errors) throw json.errors;
return json.accountId;
} catch(e) {
console.error(e)
return "*(unknown)*";
}
}
/***
* @param {int} id The room ID
*/
async function getRoomNameFromID(id) {
try{
const response = await fetch(`https://rooms.rec.net/rooms/bulk?Id=${id}`);
const json = await response.json();
if (json.title) throw json.title;
if (json.length == 0) return null;
return `^${json[0].Name}`;
} catch(e) {
console.error(e)
return null;
}
}
/***
* @param {int} flags Identity flags
*/
async function decodeFlags(flags) {
//TODO: Figure out how to decode this!
return flags;
}
/***
* @param {int} flags Pronoun flags
*/
async function decodePronouns(flags) {
//TODO: Figure out how to decode this!
return flags;
}
function randomColor(){
return Math.floor(Math.random()*16777215).toString(16);
}
/***
* @param {int} number Max number
*/
function random(number) {
return Math.floor(Math.random() * number)
}
//Export functions for use
module.exports = { getPlayerIDFromName, getPlayerNameFromID, getRoomNameFromID, randomColor, random }