Skip to content

Commit

Permalink
Update reaper to use v3 of Riot's API
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Nov 5, 2017
1 parent 2efeb48 commit 0824862
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 113 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

[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
37 changes: 9 additions & 28 deletions common.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
console.error = function(msg)
{
console.log("[".white + "!".red + "] ".white + msg.white);
};
const colors = require('colors');

console.info = function(msg)
{
console.log("[".white + "-".green + "] ".white + msg.white);
};
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);

console.warn = function(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]];
}
};

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;
}
}
116 changes: 34 additions & 82 deletions reaper.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,46 @@
var common = require('./common');
"use strict";

var colors = require('colors');
var chunk = require('chunk');
var args = process.argv.slice(2);
const common = require('./common');
const chunk = require('chunk');
const fs = require('fs');
const https = require('https');
const RateLimiter = require('limiter').RateLimiter;

var fs = require('fs');
var http = require('http');
var https = require("https");
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)");
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 apiKey = "<api key here>";
const apiKey = "<api key here>";

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

var RateLimiter = require('limiter').RateLimiter;
var limiter = new RateLimiter(1, 'second');
const limiter = new RateLimiter(1, 'second');

var namesChecked = 0;
var namesFound = 0;

// 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);

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);
}
});
});
}

0 comments on commit 0824862

Please sign in to comment.