Last active
December 12, 2022 23:30
-
-
Save tadhgboyle/c33c22b473d69d866a899cecff318d3d to your computer and use it in GitHub Desktop.
LuckyPerms piracy detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// usage: `node main.js <full luckperms editor url>` | |
const process = require('process'); | |
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[1]; | |
if (!luckPermsEditorUrl) { | |
console.log('❌ Unable to find code in URL!'); | |
process.exit(1); | |
} | |
console.log(`🔎 Found valid code (${code})`); | |
console.log('⏲️ Loading data from API...'); | |
fetch(`https://usercontent.luckperms.net/${code}`) | |
.then(resp => { | |
if (resp.status !== 200) { | |
throw new Error(`${resp.status} ${resp.statusText}`); | |
} | |
console.log('✅ Loaded data from API'); | |
const users = resp.data.permissionHolders.filter(p => p.type === 'user'); | |
let totalNumberOfUsers = users.length; | |
const numberOfPirates = users.reduce((num, p) => { | |
const uuid = p.id.split('-')[2]; | |
if (!uuid.startsWith('4')) { | |
num++; | |
} | |
return num; | |
}, 0); | |
if (numberOfPirates > 0) { | |
console.log(`🚨 ${numberOfPirates} out of ${totalNumberOfUsers} users are pirates (${ (totalNumberOfUsers/numberOfPirates) * 100 }%)!`); | |
process.exit(1); | |
} | |
console.log('✅ No piracy detected'); | |
}) | |
.catch(err => { | |
console.log(`❌ Error loading data from API: ${err.message}`); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment