How to make a rank command for Faceit Pro League NA Leaderboard for a player

I’m trying to make a command to show a players rank in fpl NA from this link if its possible https://www.faceit.com/en/hub/748cf78c-be73-4eb9-b131-21552f2f8b75/FPL%20CSGO%20North%20America/leaderboard/event/5aa0a46fc048880007748b8a

I want it to be for Hazed and show the number rank he is currently

Enter this into your chat:

!addcom !rank $(eval n=decodeURIComponent("$(querystring)")||"hazed";o="$(querystring $(urlfetch json https://api.faceit.com/leaderboard/v1/ranking/hub/748cf78c-be73-4eb9-b131-21552f2f8b75?leaderboardId=5aa0a46fc048880007748b8a&limit=50&offset=0))";t="$(querystring $(urlfetch json https://api.faceit.com/leaderboard/v1/ranking/hub/748cf78c-be73-4eb9-b131-21552f2f8b75?leaderboardId=5aa0a46fc048880007748b8a&limit=50&offset=50))";$(urlfetch json https://pastebin.com/raw/xJBXbMzu))

The command will be called !rank and will retrieve the rank of “hazed” unless the user specifies a name after the command.

In case my Pastebin link expires, here is that code (you can ignore this):

const playerName = n;
const page1Encoded = o;
const page2Encoded = t;

(function ()
{
    const page1Decoded = decodeURIComponent(page1Encoded);
    const page2Decoded = decodeURIComponent(page2Encoded);
    
    let page1, page2;
    try
    {
        page1 = JSON.parse(page1Decoded);
        page2 = JSON.parse(page2Decoded);
    }
    catch (e)
    {
        return `Failed to parse FACEIT API response: ${e.message}: ${page1Decoded}, ${page2Decoded}`;
    }
    
    if (!page1 || !page2)
        return `FACEIT API returned no response: ${page1Decoded}, ${page2Decoded}`;
    
    if (!page1.payload || !page2.payload)
        return `FACEIT API response contained no payload: ${page1Decoded}, ${page2Decoded}`;
    
    if (!page1.payload.rankings || !page2.payload.rankings)
        return `FACEIT API payload contained no rankings: ${page1Decoded}, ${page2Decoded}`;
    
    let rankings;
    try
    {
        rankings = page1.payload.rankings.concat(page2.payload.rankings);
    }
    catch (e)
    {
        return `FACEIT API rankings were not an array: ${page1Decoded}, ${page2Decoded}`;
    }
    
    const playerRankings = rankings.filter(ranking =>
    {
        if (!ranking.placement || !ranking.placement.entity_name || !ranking.position)
            return false;
        
        try
        {
            return ranking.placement.entity_name.toLowerCase() === playerName.toLowerCase();
        }
        catch (e)
        {
            return false;
        }
    });
    
    const leaderboardName = (page1.payload.leaderboard && page1.payload.leaderboard.leaderboard_name) || "unknown leaderboard name";
    
    if (playerRankings.length === 0)
        return `${playerName} was not found on the leaderboard (${leaderboardName})`;
    
    const playerNameCapitalized = playerRankings[0].placement.entity_name;
    return `Rank of ${playerNameCapitalized}: ${playerRankings.map(ranking => ranking.position).join(", ")} (${leaderboardName})`;
})().substr(0, 400);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.