-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmojangAPIConnector.js
27 lines (22 loc) · 947 Bytes
/
mojangAPIConnector.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
class MojangApiConnector {
async getUUIDFromPlayername(playername) {
return fetch(`https://api.mojang.com/users/profiles/minecraft/${playername}`)
.then(data => data.json())
.then(player => player.id.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5'));//adds the dashes back to the uuid that the mojang api ommits
}
async getPlayernameFromUUID(uuid) {
return fetch(`https://api.mojang.com/user/profile/${uuid}`)
.then(data => data.json())
.then(player => player.name);
}
}
const mojangApiConnector = new MojangApiConnector();
module.exports = mojangApiConnector;
/*mojangApiConnector.getUUIDFromPlayername("Jbeast291").then(id => {
console.log(`ID is ${id}`)
})
mojangApiConnector.getPlayernameFromUUID("0cb77a34b17f48d5b521bdc4a00cd699").then(name => {
console.log(`name is ${name}`)
})
const id = await getId(args[2])
console.log(`ID is ${id}`)*/