Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions utils/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getActiveClient(client, key) {
client.set(
key,
Buffer.from(JSON.stringify(val)),
{expires: 30*24*60*60}); // If this changes, update the Tip.js file in 25Karma
{expires: 86400}); // If this changes, update the Tip.js file in 25Karma
},
close: () => {
client.close();
Expand All @@ -56,4 +56,4 @@ function getInactiveClient() {

function sanitizeString(id) {
return id.split('-').join('').toLowerCase();
}
}
19 changes: 8 additions & 11 deletions utils/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import fetch from 'node-fetch';
const key = process.env.HYPIXEL_SECRET_KEY

export async function getMojang(slug) {
const response = await fetch(`https://playerdb.co/api/player/minecraft/${slug}`);
const response = await fetch(`https://mowojang.seraph.si/${slug}`);
const json = await response.json();
return {
response: response.status,
username: traverse(json, 'data.player.username'),
uuid: traverse(json, 'data.player.id'),
username: json?.name,
uuid: normalizeUUID(json?.id),
};
}

Expand Down Expand Up @@ -48,12 +48,9 @@ export async function getHypixelResource(endpoint) {
}
}

function traverse(json, path, defaultValue = undefined) {
const paths = path.split('.');
for (const p of paths) {
if (json === undefined) return defaultValue;
json = json[p];
}
if (json === undefined) return defaultValue;
return json;
function normalizeUUID(uuid) {
if (uuid && !uuid.includes("-")) {
return [uuid.slice(0, 8), uuid.slice(8, 12), uuid.slice(12, 16), uuid.slice(16, 20), uuid.slice(20)].join('-')
}
return uuid;
}