This repository was archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
47 lines (46 loc) · 1.45 KB
/
code.js
File metadata and controls
47 lines (46 loc) · 1.45 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
/**
* Retrieve the most recent username associated with the UUID.
*
* @param {"f5d5c301-9ad3-4cb4-9cfd-a6b78e67734a"} uuid The UUID of the player.
* @return {string} The most recent username.
* @customfunction
*/
function GETIGN(uuid) {
let cache = CacheService.getDocumentCache();
let username = cache.get(uuid);
try {
if (username === null) {
const url = 'https://api.ashcon.app/mojang/v2/user/' + uuid;
let playerJSON = UrlFetchApp.fetch(url);
let playerObject = JSON.parse(playerJSON);
username = playerObject.username;
cache.put(uuid, username, 3600);
}
return username;
} catch (e) {
throw new Error('Enter a valid UUID');
}
}
/**
* Retrieve the UUID associated with the username.
*
* @param {"Flashee"} username The username of the player.
* @param {"7/21/2020"} date [OPTIONAL] - The time in history to search for said username.
* @return {string} UUID.
* @customfunction
*/
function GETUUID(username, date) {
try {
if (date != null) {
date = new Date(date).getTime() / 1000;
return JSON.parse(UrlFetchApp.fetch("https://api.mojang.com/users/profiles/minecraft/" + username.toString() + "?at=" + date)).id;
} else {
var url = 'https://api.ashcon.app/mojang/v2/user/' + username;
var playerJSON = UrlFetchApp.fetch(url.toString());
var playerObject = JSON.parse(playerJSON);
return playerObject.uuid;
}
} catch (e) {
throw new Error('Username not found');
}
}