-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update reaper to use v3 of Riot's API
- Loading branch information
Showing
3 changed files
with
46 additions
and
113 deletions.
There are no files selected for viewing
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
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
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; | ||
} | ||
} |
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
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); | ||
} | ||
}); | ||
}); | ||
} |