Skip to content

Instantly share code, notes, and snippets.

@TheGreatRambler
Created August 21, 2020 03:43
Show Gist options
  • Save TheGreatRambler/418e3037a903ce95c323f1066781f6f1 to your computer and use it in GitHub Desktop.
Save TheGreatRambler/418e3037a903ce95c323f1066781f6f1 to your computer and use it in GitHub Desktop.
Get valid MC names from a text file
const lineByLine = require("n-readlines");
const axios = require("axios");
const fs = require("fs");
function has(str, char) {
return str.indexOf(char) !== -1;
}
const liner = new lineByLine("./words.txt");
var outFile = fs.createWriteStream("validnames.txt");
var line;
var currentIndex = 0;
async function looper() {
line = liner.next();
console.log(currentIndex);
if (!line) {
console.log("done");
outFile.close();
return;
} else {
line = line.toString("ascii");
if (!has(line, "-") && !has(line, ".") && !has(line, "'") && !has(line, "&")) {
try {
// https://stackoverflow.com/a/49139664/9329945
await new Promise(resolve => setTimeout(resolve, 1080));
var res = await axios.get("https://api.mojang.com/users/profiles/minecraft/" + line);
if (res.status === 204) {
outFile.write(line + "\n");
console.log(line);
}
} catch (e) {
}
}
currentIndex++;
await looper();
}
}
looper();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment