Skip to content

Commit

Permalink
Change username -> uuid provider
Browse files Browse the repository at this point in the history
- Experimental
  • Loading branch information
builder-247 committed Mar 23, 2021
1 parent c4b5d52 commit 39753d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions store/getUUID.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ async function getUUID(name) {
}

return cachedFunction(`uuid:${name.toLowerCase()}`, async () => {
const url = `https://api.ashcon.app/mojang/v1/user/${name}`;
const url = `https://playerdb.co/api/player/minecraft/${name}`;

const data = await getData(redis, url);
if (!data) {
const response = await getData(redis, url);
if (!response) {
throw new Error('Invalid username!');
}

const { uuid } = JSON.parse(data);
return removeDashes(uuid);
const { data } = response;
return data.player.raw_id;
}, { cacheDuration: config.UUID_CACHE_SECONDS, shouldCache: config.ENABLE_UUID_CACHE });
}

Expand Down
10 changes: 5 additions & 5 deletions util/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ const getData = fromPromise(async (redis, url) => {

const urlData = urllib.parse(url.url, true);
const isHypixelApi = urlData.host === 'api.hypixel.net';
const isMojangApi = urlData.host === 'api.mojang.com';
const isMojangApi = urlData.host === 'playerdb.co';

const target = urllib.format(urlData);

logger.info(`getData: ${target}`);

try {
const { body } = await got(target, {
responseType: isHypixelApi ? 'json' : 'text',
responseType: 'json',
timeout: url.timeout,
retry: url.retries,
hooks: {
Expand All @@ -346,6 +346,9 @@ const getData = fromPromise(async (redis, url) => {
logger.error(error);
}
}
if (isMojangApi) {
throw new Error('Failed to get player uuid');
}
},
],
},
Expand All @@ -356,9 +359,6 @@ const getData = fromPromise(async (redis, url) => {
if (url.noRetry) {
throw new Error('Invalid response');
}
if (isMojangApi) {
throw new Error('Failed to get player uuid');
}
if (error.response && error.response.statusCode) {
switch (error.response.statusCode) {
case 404:
Expand Down

0 comments on commit 39753d5

Please sign in to comment.