From 082486211e02202dcd4a0bdfbaa05c6258d48023 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sun, 5 Nov 2017 11:03:39 +0000 Subject: [PATCH] Update reaper to use v3 of Riot's API --- README.md | 6 +++--- common.js | 37 +++++++++---------------------------- reaper.js | 116 ++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------- 3 files changed, 46 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 5239cb3..e363a55 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/common.js b/common.js index ce13c84..756bdad 100644 --- a/common.js +++ b/common.js @@ -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; - } -} diff --git a/reaper.js b/reaper.js index 495a5a0..ecb2e2b 100644 --- a/reaper.js +++ b/reaper.js @@ -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 = ""; +const apiKey = ""; -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); + } + }); + }); +} \ No newline at end of file -- libgit2 1.7.2