aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/hypixelCached.js4
-rw-r--r--build/mojang.js68
2 files changed, 26 insertions, 46 deletions
diff --git a/build/hypixelCached.js b/build/hypixelCached.js
index 82e8c93..a667ec4 100644
--- a/build/hypixelCached.js
+++ b/build/hypixelCached.js
@@ -114,7 +114,7 @@ async function uuidFromUser(user) {
// set it as waitForCacheSet (a promise) in case uuidFromUser gets called while its fetching mojang
usernameCache.set(util_1.undashUuid(user), waitForCacheSet(usernameCache, user, user));
// not cached, actually fetch mojang api now
- let { uuid, username } = await mojang.mojangDataFromUser(user);
+ let { uuid, username } = await mojang.profileFromUser(user);
if (!uuid) {
usernameCache.set(user, null);
return;
@@ -139,7 +139,7 @@ async function usernameFromUser(user) {
}
if (_1.debug)
console.log('Cache miss: usernameFromUser', user);
- let { uuid, username } = await mojang.mojangDataFromUser(user);
+ let { uuid, username } = await mojang.profileFromUser(user);
uuid = util_1.undashUuid(uuid);
usernameCache.set(uuid, username);
return username;
diff --git a/build/mojang.js b/build/mojang.js
index ae0e1e6..f18875d 100644
--- a/build/mojang.js
+++ b/build/mojang.js
@@ -6,7 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.usernameFromUser = exports.mojangDataFromUser = exports.uuidFromUser = exports.usernameFromUuid = exports.uuidFromUsername = exports.mojangDataFromUuid = void 0;
+exports.profileFromUser = exports.profileFromUsername = exports.profileFromUuid = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
const https_1 = require("https");
const util_1 = require("./util");
@@ -17,7 +17,7 @@ const httpsAgent = new https_1.Agent({
/**
* Get mojang api data from the session server
*/
-async function mojangDataFromUuid(uuid) {
+async function profileFromUuid(uuid) {
const fetchResponse = await node_fetch_1.default(
// using mojang directly is faster than ashcon lol, also mojang removed the ratelimits from here
`https://sessionserver.mojang.com/session/minecraft/profile/${util_1.undashUuid(uuid)}`, { agent: () => httpsAgent });
@@ -27,55 +27,35 @@ async function mojangDataFromUuid(uuid) {
}
catch {
// if it errors, just return null
- return {
- uuid: null,
- username: null
- };
+ return { uuid: null, username: null };
}
return {
uuid: data.id,
username: data.name
};
}
-exports.mojangDataFromUuid = mojangDataFromUuid;
-async function uuidFromUsername(username) {
+exports.profileFromUuid = profileFromUuid;
+async function profileFromUsername(username) {
// since we don't care about anything other than the uuid, we can use /uuid/ instead of /user/
- const fetchResponse = await node_fetch_1.default(`https://api.ashcon.app/mojang/v2/uuid/${username}`, { agent: () => httpsAgent });
- const userUuid = await fetchResponse.text();
- return userUuid.replace(/-/g, '');
-}
-exports.uuidFromUsername = uuidFromUsername;
-async function usernameFromUuid(uuid) {
- const userJson = await mojangDataFromUuid(uuid);
- return userJson.username;
-}
-exports.usernameFromUuid = usernameFromUuid;
-/**
- * Fetch the uuid from a user
- * @param user A user can be either a uuid or a username
- */
-async function uuidFromUser(user) {
- if (util_1.isUuid(user))
- // already a uuid, just return it undashed
- return util_1.undashUuid(user);
- else
- return await uuidFromUsername(user);
+ const fetchResponse = await node_fetch_1.default(`https://api.mojang.com/users/profiles/minecraft/${username}`, { agent: () => httpsAgent });
+ let data;
+ try {
+ data = await fetchResponse.json();
+ }
+ catch {
+ return { uuid: null, username: null };
+ }
+ return {
+ uuid: data.id,
+ username: data.name
+ };
}
-exports.uuidFromUser = uuidFromUser;
-async function mojangDataFromUser(user) {
- if (!util_1.isUuid(user))
- return await mojangDataFromUuid(await uuidFromUsername(user));
+exports.profileFromUsername = profileFromUsername;
+async function profileFromUser(user) {
+ if (util_1.isUuid(user)) {
+ return await profileFromUuid(user);
+ }
else
- return await mojangDataFromUuid(user);
-}
-exports.mojangDataFromUser = mojangDataFromUser;
-/**
- * Fetch the username from a user
- * @param user A user can be either a uuid or a username
- */
-async function usernameFromUser(user) {
- // we do this to fix the capitalization
- const data = await mojangDataFromUser(user);
- return data.username;
+ return await profileFromUsername(user);
}
-exports.usernameFromUser = usernameFromUser;
+exports.profileFromUser = profileFromUser;