🏡 index : ~doyle/reaper.git

author Jordan Doyle <jordan@9t9t9.com> 2017-11-05 11:03:39.0 +00:00:00
committer Jordan Doyle <jordan@9t9t9.com> 2017-11-05 11:03:39.0 +00:00:00
commit
082486211e02202dcd4a0bdfbaa05c6258d48023 [patch]
tree
d568206fd90e56340cdbc7bbb9e1d81cbacd5de7
parent
2efeb48d535525f6fe502a4b6ad81ef0eba849cf
download
082486211e02202dcd4a0bdfbaa05c6258d48023.tar.gz

Update reaper to use v3 of Riot's API



Diff

 README.md |   6 +++---
 common.js |  41 +++++++++++++----------------------------
 reaper.js | 120 ++++++++++++++++++++++++++++++++++++++++----------------------------------------
 3 files changed, 50 insertions(+), 117 deletions(-)

diff --git a/README.md b/README.md
index 5239cb3..e363a55 100644
--- a/README.md
+++ a/README.md
@@ -1,17 +1,17 @@
# reaper

[![License](https://poser.pugx.org/laravel/framework/license.svg)](http://github.com/jordandoyle/reaper)

[League of Legends](http://leagueoflegends.com) mass summoner name checker. Supply a region and a list and the script will check the list for available summoner names. Common uses are finding quick variations of your name or finding rare (or "OG") names for selling. An API Key is required to do use this script, they are available for free from [Riot Games](https://developer.riotgames.com/), the API key is set in **reaper.js**.

This script includes a built-in rate limiter and a very basic web server for checking the status of the script remotely available on port **8090**.
You can find a list of the servers you can query from on [Riot's website](https://developer.riotgames.com/regional-endpoints.html).

The syntax of reaper is very simple:

    node reaper.js [server (na/euw/lan/etc)] [username file] (output file)

    node reaper.js [server (na1/euw1/la1/etc)] [username file] (output file)


For example:

    node reaper.js euw username_list.txt output.txt

    node reaper.js euw1 username_list.txt output.txt


Will check the list username_list.txt for available summoner names on Europe West and output what it finds to output.txt
diff --git a/common.js b/common.js
index ce13c84..756bdad 100644
--- a/common.js
+++ a/common.js
@@ -1,31 +1,12 @@
console.error = function(msg)
{
	console.log("[".white + "!".red + "] ".white + msg.white);
const colors = require('colors');

console.error = (msg) => console.log("[".white + "!".red + "] ".white + msg.white);
console.info = (msg) => console.log("[".white + "-".green + "] ".white + msg.white);
console.warn = (msg) => console.log("[".white + "~".blue + "] ".white + msg.white);

exports.shuffle = (array) => {
    for (let i = array.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [array[i], array[j]] = [array[j], array[i]];
    }
};

console.info = function(msg)
{
	console.log("[".white + "-".green + "] ".white + msg.white);
};

console.warn = function(msg)
{
	console.log("[".white + "~".blue + "] ".white + msg.white);
};

exports.shuffle = function(array)
{
	var currentIndex = array.length;
	var temporaryValue;
	var randomIndex;

	while(currentIndex !== 0)
	{
		randomIndex = Math.floor(Math.random() * currentIndex);
		currentIndex -= 1;

		temporaryValue = array[currentIndex];
		array[currentIndex] = array[randomIndex];
		array[randomIndex] = temporaryValue;
	}
}
diff --git a/reaper.js b/reaper.js
index 495a5a0..ecb2e2b 100644
--- a/reaper.js
+++ a/reaper.js
@@ -1,94 +1,46 @@
var common = require('./common');

var colors = require('colors');
var chunk = require('chunk');
var args = process.argv.slice(2);

var fs = require('fs');
var http = require('http');
var https = require("https");

if(args.length < 2 || args.length > 3)
{
	console.error("Invalid syntax. Valid syntax: " + process.argv[0] + " " + process.argv[1] + " [server] [username input] (username output)");
}
"use strict";

var apiKey = "<api key here>";
const common = require('./common');
const chunk = require('chunk');
const fs = require('fs');
const https = require('https');
const RateLimiter = require('limiter').RateLimiter;

var server = args[0];
var input = args[1];
var output = args[2];
const args = process.argv.slice(2);

if(args.length < 2 || args.length > 3) {
    console.error("Invalid syntax. Valid syntax: " + process.argv[0] + " " + process.argv[1] + " [server] [username input] (username output)");
}

var RateLimiter = require('limiter').RateLimiter;
var limiter = new RateLimiter(1, 'second');
const apiKey = "<api key here>";

var namesChecked = 0;
var namesFound = 0;
const server = args[0];
const input = args[1];
const output = args[2];

// basic http server for logging
http.createServer(function(req, res)
{
	res.writeHead(200, { 'Content-Type': 'text/plain' });
	res.end('Names Checked: ' + namesChecked + '\nNames Found: ' + namesFound);
}).listen(8090);
const limiter = new RateLimiter(1, 'second');

var names = fs.readFileSync(input).toString().split('\n');
const names = fs.readFileSync(input).toString().split('\n');

// shuffle the list of names passed in
common.shuffle(names);

// check names in chunks of 40
chunk(names, 40).forEach(function(chunked)
{
	limiter.removeTokens(1, function(err, remainingRequests)
	{
		namesChecked += 40;

		var users = chunked.join(',').replace(/[-]/g, ' ').replace(/[\r\n'.]/g, '');

		// make a secure request to the specified server
		https.get('https://' + server + '.api.pvp.net/api/lol/' + server + '/v1.4/summoner/by-name/' + users + '?api_key=' + apiKey, function(res)
		{
			// riot returns a 404 if none of the names are registered
			if(res.statusCode === 404) {
				chunked.forEach(function(name)
				{
					namesFound++;
					console.info(name.replace(/[-]/g, ' ').replace(/[\r\n'.]/g, '') + " is available!");

					if(output != undefined)
						fs.appendFile(output, name + '\n');
				});
			} else if(res.statusCode === 200) {
				var body = '';
				res.setEncoding('utf8');

				res.on('data', function(d) {
					body += d;
				});

				res.on('end', function()
				{
					var obj = JSON.parse(body);
					
					chunked.forEach(function(name)
					{
						name = name.replace(/[-]/g, ' ').replace(/[\r\n'.]/g, '').trim();

						if(name.length < 3)
							return;

						if(obj[name] == undefined)
						{
							if(output != undefined)
								fs.appendFile(output, name + '\r\n');

							console.info(name + " is available!");
							namesFound++;
						}
					});
				});
			}
		});
	});
});
for (let name of names) {
    name = name.replace(/[-]/g, ' ').replace(/[\r\n'.]/g, '').trim();

    if(name.length < 3)
        continue;

    limiter.removeTokens(1, () => {
        // make a secure request to the specified server
        https.get(`https://${server}.api.riotgames.com/lol/summoner/v3/summoners/by-name/${name}?api_key=${apiKey}`, (res) => {
            // riot returns a 404 if none of the names are registered
            if(res.statusCode === 404) {
                console.info(name.replace(/[-]/g, ' ').replace(/[\r\n'.]/g, '') + " is available!");

                if(output !== undefined)
                    fs.appendFile(output, name + '\n', () => null);
            }
        });
    });
}