Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Add UUID support for players and profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaPhant committed Feb 6, 2020
1 parent 9872e2c commit 8bef57a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
53 changes: 45 additions & 8 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,39 @@ app.use(express.static('public', { maxAge: CACHE_DURATION }));
app.get('/stats/:player/:profile?', async (req, res, next) => {
let response;

let active_profile = db
.get('profiles')
.find({ username: req.params.player.toLowerCase() })
.value();
let paramPlayer = req.params.player.toLowerCase().replace(/\-/g, '');
let paramProfile = req.params.profile ? req.params.profile.toLowerCase() : null;

let isPlayerUuid = paramPlayer.length == 32;
let isProfileUuid = false;

if(paramProfile)
isProfileUuid = paramProfile.length == 32;

let active_profile;

if(isPlayerUuid)
active_profile = db
.get('profiles')
.find({ uuid: paramPlayer })
.value();
else
active_profile = db
.get('profiles')
.find({ username: paramPlayer })
.value();

let params = {
key: getApiKey()
};

if(isPlayerUuid)
params.uuid = paramPlayer;
else
params.name = paramPlayer;

try{
response = await Hypixel.get('player', { params: { key: getApiKey(), name: req.params.player }, timeout: 5000 });
response = await Hypixel.get('player', { params, timeout: 5000 });
let { data } = response;

if(!data.success){
Expand Down Expand Up @@ -181,9 +207,20 @@ app.get('/stats/:player/:profile?', async (req, res, next) => {
}
}

if(req.params.profile)
skyblock_profiles = _.pickBy(all_skyblock_profiles, a => a.cute_name.toLowerCase() == req.params.profile.toLowerCase());
else if(active_profile)
if(paramProfile){
if(isProfileUuid){
if(Object.keys(all_skyblock_profiles).includes(paramProfile)){
skyblock_profiles = _.pickBy(all_skyblock_profiles, a => a.profile_id.toLowerCase() == paramProfile);
}else{
skyblock_profiles[paramProfile] = {
profile_id: paramProfile,
cute_name: 'Avocado'
};
}
}else{
skyblock_profiles = _.pickBy(all_skyblock_profiles, a => a.cute_name.toLowerCase() == paramProfile);
}
}else if(active_profile)
skyblock_profiles = _.pickBy(all_skyblock_profiles, a => a.profile_id.toLowerCase() == active_profile.profile_id);

if(Object.keys(skyblock_profiles).length == 0)
Expand Down
4 changes: 2 additions & 2 deletions views/stats.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ if(calculated.bank)
<%= calculated.display_name %>
<div id="other_players">
<% calculated.members.forEach(member => { %>
<a class="goto" href="/stats/<%= member.display_name %>/<%= calculated.profile.cute_name %>"><%= member.display_name %></a>
<a class="goto" href="/stats/<%= member.uuid %>/<%= calculated.profile.profile_id %>"><%= member.display_name %></a>
<% }); %>
<input type="text" id="enter_player" placeholder="Enter username"><a id="goto_player"></a>
</div>
Expand All @@ -165,7 +165,7 @@ if(calculated.bank)
<div id="other_profiles">
<% for(let profile_id in calculated.profiles){ %>
<% let _profile = calculated.profiles[profile_id]; %>
<a class="goto" href="/stats/<%= calculated.display_name %>/<%= _profile.cute_name %>"><%= _profile.cute_name %></a>
<a class="goto" href="/stats/<%= calculated.uuid %>/<%= _profile.profile_id %>"><%= _profile.cute_name %></a>
<% } %>
</div>
</div>
Expand Down

0 comments on commit 8bef57a

Please sign in to comment.