Skip to content

Instantly share code, notes, and snippets.

@tadhgboyle
Last active December 12, 2022 23:30
Show Gist options
  • Select an option

  • Save tadhgboyle/c33c22b473d69d866a899cecff318d3d to your computer and use it in GitHub Desktop.

Select an option

Save tadhgboyle/c33c22b473d69d866a899cecff318d3d to your computer and use it in GitHub Desktop.

Revisions

  1. tadhgboyle revised this gist Dec 12, 2022. 1 changed file with 13 additions and 18 deletions.
    31 changes: 13 additions & 18 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -1,51 +1,46 @@
    // usage: `node main.js <full luckperms editor url>`

    const process = require('process');
    const axios = require('axios');

    const luckPermsEditorUrl = process.argv[2];
    const shouldAnnoy = process.argv[3] !== 'false';
    const luckPermsEditorUrl = process.argv[2].match(/https:\/\/luckperms.net\/editor\/(.*)/i);

    if (!luckPermsEditorUrl) {
    console.log('❌ Gimme an LP Editor URL!');
    process.exit(1);
    }

    const code = luckPermsEditorUrl.split('/').pop();
    const code = luckPermsEditorUrl[1];
    if (!luckPermsEditorUrl) {
    console.log('❌ Unable to find code in URL!');
    process.exit(1);
    }

    if (shouldAnnoy) {
    console.log(`πŸ”Ž Found valid code (${code})`);
    console.log('⏲️ Loading data from API...');
    }
    console.log(`πŸ”Ž Found valid code (${code})`);
    console.log('⏲️ Loading data from API...');

    axios.get(`https://usercontent.luckperms.net/${code}`)
    fetch(`https://usercontent.luckperms.net/${code}`)
    .then(resp => {
    if (resp.status !== 200) {
    throw new Error(`${resp.status} ${resp.statusText}`);
    }

    if (shouldAnnoy) {
    console.log('βœ… Loaded data from API');
    }
    console.log('βœ… Loaded data from API');

    const users = resp.data.permissionHolders.filter(p => p.type === 'user');

    let numberOfPirates = 0;
    let totalNumberOfUser = users.length;
    let totalNumberOfUsers = users.length;

    users.forEach(p => {
    const numberOfPirates = users.reduce((num, p) => {
    const uuid = p.id.split('-')[2];
    if (!uuid.startsWith('4')) {
    numberOfPirates++;
    num++;
    }
    });

    return num;
    }, 0);

    if (numberOfPirates > 0) {
    console.log(`🚨 ${numberOfPirates} out of ${totalNumberOfUser} users are pirates (${ (totalNumberOfUser/numberOfPirates) * 100 }%)!`);
    console.log(`🚨 ${numberOfPirates} out of ${totalNumberOfUsers} users are pirates (${ (totalNumberOfUsers/numberOfPirates) * 100 }%)!`);
    process.exit(1);
    }

  2. tadhgboyle revised this gist Jan 19, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.js
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@ axios.get(`https://usercontent.luckperms.net/${code}`)

    users.forEach(p => {
    const uuid = p.id.split('-')[2];
    if (uuid.startsWith('3')) {
    if (!uuid.startsWith('4')) {
    numberOfPirates++;
    }
    });
  3. tadhgboyle revised this gist Jan 19, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // usage: `node main.js <full luckperms editor url>`

    const process = require('process');
    const axios = require('axios');

  4. tadhgboyle created this gist Jan 19, 2022.
    55 changes: 55 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    const process = require('process');
    const axios = require('axios');

    const luckPermsEditorUrl = process.argv[2];
    const shouldAnnoy = process.argv[3] !== 'false';

    if (!luckPermsEditorUrl) {
    console.log('❌ Gimme an LP Editor URL!');
    process.exit(1);
    }

    const code = luckPermsEditorUrl.split('/').pop();
    if (!luckPermsEditorUrl) {
    console.log('❌ Unable to find code in URL!');
    process.exit(1);
    }

    if (shouldAnnoy) {
    console.log(`πŸ”Ž Found valid code (${code})`);
    console.log('⏲️ Loading data from API...');
    }

    axios.get(`https://usercontent.luckperms.net/${code}`)
    .then(resp => {
    if (resp.status !== 200) {
    throw new Error(`${resp.status} ${resp.statusText}`);
    }

    if (shouldAnnoy) {
    console.log('βœ… Loaded data from API');
    }

    const users = resp.data.permissionHolders.filter(p => p.type === 'user');

    let numberOfPirates = 0;
    let totalNumberOfUser = users.length;

    users.forEach(p => {
    const uuid = p.id.split('-')[2];
    if (uuid.startsWith('3')) {
    numberOfPirates++;
    }
    });

    if (numberOfPirates > 0) {
    console.log(`🚨 ${numberOfPirates} out of ${totalNumberOfUser} users are pirates (${ (totalNumberOfUser/numberOfPirates) * 100 }%)!`);
    process.exit(1);
    }

    console.log('βœ… No piracy detected');
    })
    .catch(err => {
    console.log(`❌ Error loading data from API: ${err.message}`);
    process.exit(1);
    });