Skip to content

Commit

Permalink
remove async lib from dev scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 3, 2023
1 parent 2939d21 commit e807997
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 296 deletions.
59 changes: 26 additions & 33 deletions dev/checkAccounts.mjs
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
import fs from 'fs';
import Steam from 'steam';
import async from 'async';
const accountData = fs.readFileSync('./STEAM_ACCOUNT_DATA_BAD.txt', 'utf8');
const accountArray = accountData.split(require('os').EOL);

let index = Number(process.argv[2]) || -1;
async.whilst(
() => true,
(cb) => {
index += 1;
const random = index;
// const random = Math.floor(Math.random() * accountArray.length);
const user = accountArray[random].split('\t')[0];
const pass = accountArray[random].split('\t')[1];
const logOnDetails = {
account_name: user,
password: pass,
};
const client = new Steam.SteamClient();
client.steamUser = new Steam.SteamUser(client);
client.connect();
client.on('connected', () => {
client.steamUser.logOn(logOnDetails);
});
client.on('logOnResponse', (logOnResp) => {
if (logOnResp.eresult === Steam.EResult.AccountDisabled) {
console.error(index, user, 'failed', logOnResp.eresult);
} else if (logOnResp.eresult === Steam.EResult.InvalidPassword) {
console.error(index, user, 'failed', logOnResp.eresult);
} else {
console.error(index, user, 'passed', logOnResp.eresult);
}
client.disconnect();
setTimeout(cb, 500);
});
},
() => {}
);
index += 1;
const random = index;
// const random = Math.floor(Math.random() * accountArray.length);
const user = accountArray[random].split('\t')[0];
const pass = accountArray[random].split('\t')[1];
const logOnDetails = {
account_name: user,
password: pass,
};
const client = new Steam.SteamClient();
client.steamUser = new Steam.SteamUser(client);
client.connect();
client.on('connected', () => {
client.steamUser.logOn(logOnDetails);
});
client.on('logOnResponse', (logOnResp) => {
if (logOnResp.eresult === Steam.EResult.AccountDisabled) {
console.error(index, user, 'failed', logOnResp.eresult);
} else if (logOnResp.eresult === Steam.EResult.InvalidPassword) {
console.error(index, user, 'failed', logOnResp.eresult);
} else {
console.error(index, user, 'passed', logOnResp.eresult);
}
client.disconnect();
setTimeout(cb, 500);
});
38 changes: 15 additions & 23 deletions dev/createAccounts.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import Steam from 'steam';
import SteamUser from 'steam-user';
import async from 'async';

const steam = new SteamUser();
const time = Math.floor(new Date() / 1000);
async.eachSeries(
Array.from(new Array(1000), (v, i) => i),
(i, cb) => {
steam.logOn(() => {});
steam.once('loggedOn', () => {
const name = `${time}_${i}`;
const password = (Math.random() + 1).toString(36).substring(7);
const email = `${name}@email.com`;
steam.createAccount(name, password, email, (result, steamid) => {
console.error(name, password, result, steamid);
if (result === Steam.EResult.OK) {
console.log('%s\t%s', name, password);
}
steam.logOff(() => {});
setTimeout(cb, 61000);
});
Array.from(new Array(1000), (v, i) => i).forEach((i) => {
steam.logOn(() => {});
steam.once('loggedOn', () => {
const name = `${time}_${i}`;
const password = (Math.random() + 1).toString(36).substring(7);
const email = `${name}@email.com`;
steam.createAccount(name, password, email, (result, steamid) => {
console.error(name, password, result, steamid);
if (result === Steam.EResult.OK) {
console.log('%s\t%s', name, password);
}
steam.logOff(() => {});
setTimeout(cb, 61000);
});
},
(err) => {
console.error(err);
process.exit(Number(err));
}
);
});
});
93 changes: 38 additions & 55 deletions dev/findProMatches.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import async from 'async';
import queries from '../store/queries.mjs';
import db from '../store/db.mjs';
import { generateJob, getData } from '../util/utility.mjs';
Expand All @@ -15,49 +14,38 @@ function getPage(url, leagueid, cb) {
data.result.total_results,
data.result.results_remaining
);
async.eachSeries(
data.result.matches,
(match, cb) => {
console.log(match.match_id);
const job = generateJob('api_details', {
match_id: match.match_id,
});
const { url } = job;
getData(
{
url,
delay: 200,
},
async (err, body) => {
if (err) {
throw err;
}
if (body.result) {
const match = body.result;
await queries.insertMatchPromise(match, { skipParse: true });
cb();
} else {
cb();
}
data.result.matches.forEach((match) => {
console.log(match.match_id);
const job = generateJob('api_details', {
match_id: match.match_id,
});
const { url } = job;
getData(
{
url,
delay: 200,
},
async (err, body) => {
if (err) {
throw err;
}
if (body.result) {
const match = body.result;
await queries.insertMatchPromise(match, { skipParse: true });
} else {
}
);
},
(err) => {
if (err) {
throw err;
}
if (data.result.results_remaining) {
const url2 = generateJob('api_history', {
leagueid,
start_at_match_id:
data.result.matches[data.result.matches.length - 1].match_id - 1,
}).url;
getPage(url2, leagueid, cb);
} else {
cb(err);
}
}
);
);
});
if (data.result.results_remaining) {
const url2 = generateJob('api_history', {
leagueid,
start_at_match_id:
data.result.matches[data.result.matches.length - 1].match_id - 1,
}).url;
getPage(url2, leagueid, cb);
} else {
}
});
}

Expand All @@ -71,18 +59,13 @@ db.select('leagueid')
throw err;
}
const leagueIds = data.map((l) => l.leagueid);
async.eachSeries(
leagueIds,
(leagueid, cb) => {
const { url } = generateJob('api_history', {
leagueid,
});
return getPage(url, leagueid, cb);
},
(err) => {
process.exit(Number(err));
}
);
leagueIds.forEach((leagueid) => {
const { url } = generateJob('api_history', {
leagueid,
});
return getPage(url, leagueid, cb);
});
process.exit(Number(err));
});
// From API
/*
Expand All @@ -93,7 +76,7 @@ getData(leagueUrl, (err, data) => {
// console.log(data);
const leagueIds = data.result.leagues.map(l => l.leagueid);
// iterate through leagueids and use getmatchhistory to retrieve matches for each
async.eachSeries(leagueIds, (leagueid, cb) => {
leagueIds.forEach(leagueid) => {
const url = generateJob('api_history',
{
leagueid,
Expand Down
29 changes: 11 additions & 18 deletions dev/generateFakeRatings.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import async from 'async';
import db from '../store/db.mjs';

function randByCentralLimitTheorem() {
Expand All @@ -19,21 +18,15 @@ function gaussianRandom(mean, std) {
}

db.from('players').asCallback((err, players) => {
async.each(
players,
(p, cb) => {
const fake = {
match_id: p.account_id,
account_id: p.account_id,
solo_competitive_rank: Math.floor(gaussianRandom(4000, 1000)),
competitive_rank: p.account_id % 8000,
time: new Date(),
};
console.log(fake.account_id, fake.solo_competitive_rank);
db.insert(fake).into('player_ratings').asCallback(cb);
},
(err) => {
process.exit(Number(err));
}
);
players.forEach((p) => {
const fake = {
match_id: p.account_id,
account_id: p.account_id,
solo_competitive_rank: Math.floor(gaussianRandom(4000, 1000)),
competitive_rank: p.account_id % 8000,
time: new Date(),
};
console.log(fake.account_id, fake.solo_competitive_rank);
db.insert(fake).into('player_ratings').asCallback(cb);
});
});
37 changes: 14 additions & 23 deletions dev/keyTest.mjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import request from 'request';
import async from 'async';
import axios from 'axios';
import config from '../config.js';

const output = [];

async.eachSeries(
config.STEAM_API_KEY.split(','),
(key, cb) => {
setTimeout(() => {
request(
`http://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=${key}`,
(err, resp, body) => {
console.log(key, resp.statusCode);
if (resp.statusCode !== 200) {
console.log(body);
} else {
output.push(key);
}
cb();
}
);
}, 1000);
},
() => {
console.log(output.join(','));
const arr = config.STEAM_API_KEY.split(',');
for (let i = 0; i < arr; i++) {
const key = arr[i];
const resp = await axios.get(
`http://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=${key}`
);
console.log(key, resp.statusCode);
if (resp.statusCode !== 200) {
console.log(body);
} else {
output.push(key);
}
);
}
console.log(output.join(','));
2 changes: 1 addition & 1 deletion dev/lobby.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const port = config.PORT || config.RETRIEVER_PORT;
// create array of numbers from 0 to n
const count = 0;
while (a.length < users.length) a.push(a.length + 0);
async.each(a, (i, cb) => {
a.forEach((i) => {
let dotaReady = false;
const relationshipReady = false;
const client = new Steam.SteamClient();
Expand Down
12 changes: 0 additions & 12 deletions dev/metaParse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,3 @@ console.time('map');s
entries.map(e => Object.assign({}, e));
console.timeEnd('map');
*/
/*
const request = require('request');
const async = require('async');
async.eachSeries(Array.from(new Array(100), (e, i) => i), (i, cb) => {
request(`http://localhost:5100?match_id=2716007205`, (err, resp, body) => {
console.log(i, err, resp && resp.statusCode);
setTimeout(() => {
cb(err);
}, 1000);
});
}, (err) => (process.exit(Number(err))));
*/
40 changes: 16 additions & 24 deletions dev/rePatch.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Recalculate patch ID for matches in match table
* */
import async from 'async';
import constants from 'dotaconstants';
import db from '../store/db.mjs';
import queries from '../store/queries.mjs';
Expand All @@ -14,27 +13,20 @@ db.select(['match_id', 'start_time'])
if (err) {
throw err;
}
async.eachSeries(
matchIds,
(match, cb) => {
const patch =
constants.patch[utility.getPatchIndex(match.start_time)].name;
console.log(match.match_id, patch);
queries.upsert(
db,
'match_patch',
{
match_id: match.match_id,
patch,
},
{
match_id: match.match_id,
},
cb
);
},
(err) => {
process.exit(Number(err));
}
);
matchIds.forEach((match) => {
const patch =
constants.patch[utility.getPatchIndex(match.start_time)].name;
console.log(match.match_id, patch);
queries.upsert(
db,
'match_patch',
{
match_id: match.match_id,
patch,
},
{
match_id: match.match_id,
}
);
});
});
Loading

0 comments on commit e807997

Please sign in to comment.